Skip to content

Commit fb044cb

Browse files
committed
fix: destructure the props
1 parent 8dfc3f7 commit fb044cb

File tree

3 files changed

+48
-26
lines changed

3 files changed

+48
-26
lines changed

dist/paystack.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
return text;
4444
})
4545
let callback = (response) => {
46-
console.log({ response })
46+
console.log('this is a callback',{ response })
4747
};
4848
let close = () => {
4949
console.log('payment closed')

lib/paystack.vue

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</template>
1414

1515
<script>
16-
import { defineComponent, ref, onBeforeMount, onMounted } from "vue";
16+
import { defineComponent, ref, toRefs,onBeforeMount, onMounted } from "vue";
1717
1818
export default defineComponent({
1919
name: "PayStack",
@@ -114,6 +114,28 @@ export default defineComponent({
114114
},
115115
116116
setup(props) {
117+
const {
118+
paystackkey,
119+
email,
120+
firstname,
121+
lastname,
122+
channels,
123+
amount,
124+
accessCode,
125+
reference,
126+
callback,
127+
close,
128+
metadata,
129+
currency,
130+
plan,
131+
quantity,
132+
splitCode,
133+
split,
134+
subaccount,
135+
transactionCharge,
136+
bearer,
137+
embed,
138+
} = toRefs(props);
117139
const scriptLoaded = ref(null);
118140
const loadScript = (callback) => {
119141
const script = document.createElement("script");
@@ -134,7 +156,7 @@ export default defineComponent({
134156
} else {
135157
// Others
136158
script.onload = () => {
137-
callback();
159+
callback()
138160
};
139161
}
140162
};
@@ -149,37 +171,37 @@ export default defineComponent({
149171
scriptLoaded.value &&
150172
scriptLoaded.value.then(() => {
151173
const paystackOptions = {
152-
key: props.paystackkey,
153-
email: props.email,
154-
firstname: props.firstname,
155-
lastname: props.lastname,
156-
channels: props.channels,
157-
amount: props.amount,
158-
access_code: props.accessCode,
159-
ref: props.reference,
174+
key: paystackkey.value,
175+
email: email.value,
176+
firstname: firstname.value,
177+
lastname: lastname.value,
178+
channels: channels.value,
179+
amount:amount.value,
180+
access_code: accessCode.value,
181+
ref: reference.value,
160182
callback: (response) => {
161-
props.callback(response);
183+
callback.value(response);
162184
},
163185
onClose: () => {
164-
props.close();
186+
close.value();
165187
},
166-
metadata: props.metadata,
167-
currency: props.currency,
168-
plan: props.plan,
169-
quantity: props.quantity,
170-
subaccount: isDynamicSplit() ? "" : props.subaccount,
171-
split: isDynamicSplit() ? props.split.value : null,
172-
split_code: isDynamicSplit() ? "" : props.splitCode,
173-
transaction_charge: isDynamicSplit() ? 0 : props.transactionCharge,
174-
bearer: isDynamicSplit() ? "" : props.bearer,
188+
metadata: metadata.value,
189+
currency: currency.value,
190+
plan:plan.value,
191+
quantity: quantity.value,
192+
subaccount: isDynamicSplit() ? "" : subaccount.value,
193+
split: isDynamicSplit() ? split.value : null,
194+
split_code: isDynamicSplit() ? "" : splitCode.value,
195+
transaction_charge: isDynamicSplit() ? 0 : transactionCharge.value,
196+
bearer: isDynamicSplit() ? "" : bearer.value,
175197
};
176198
177-
if (props.embed) {
199+
if (embed.value) {
178200
paystackOptions.container = "paystackEmbedContainer";
179201
}
180202
181203
const handler = window.PaystackPop.setup(paystackOptions);
182-
if (!props.embed) {
204+
if (!embed.value) {
183205
handler.openIframe();
184206
}
185207
});
@@ -192,7 +214,7 @@ export default defineComponent({
192214
});
193215
});
194216
onMounted(() => {
195-
if (props.embed) {
217+
if (embed.value) {
196218
payWithPaystack();
197219
}
198220
});

0 commit comments

Comments
 (0)