13
13
</template >
14
14
15
15
<script >
16
- import { defineComponent , ref , onBeforeMount , onMounted } from " vue" ;
16
+ import { defineComponent , ref , toRefs , onBeforeMount , onMounted } from " vue" ;
17
17
18
18
export default defineComponent ({
19
19
name: " PayStack" ,
@@ -114,6 +114,28 @@ export default defineComponent({
114
114
},
115
115
116
116
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);
117
139
const scriptLoaded = ref (null );
118
140
const loadScript = (callback ) => {
119
141
const script = document .createElement (" script" );
@@ -134,7 +156,7 @@ export default defineComponent({
134
156
} else {
135
157
// Others
136
158
script .onload = () => {
137
- callback ();
159
+ callback ()
138
160
};
139
161
}
140
162
};
@@ -149,37 +171,37 @@ export default defineComponent({
149
171
scriptLoaded .value &&
150
172
scriptLoaded .value .then (() => {
151
173
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 ,
160
182
callback : (response ) => {
161
- props . callback (response);
183
+ callback . value (response);
162
184
},
163
185
onClose : () => {
164
- props . close ();
186
+ close . value ();
165
187
},
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 ,
175
197
};
176
198
177
- if (props . embed ) {
199
+ if (embed . value ) {
178
200
paystackOptions .container = " paystackEmbedContainer" ;
179
201
}
180
202
181
203
const handler = window .PaystackPop .setup (paystackOptions);
182
- if (! props . embed ) {
204
+ if (! embed . value ) {
183
205
handler .openIframe ();
184
206
}
185
207
});
@@ -192,7 +214,7 @@ export default defineComponent({
192
214
});
193
215
});
194
216
onMounted (() => {
195
- if (props . embed ) {
217
+ if (embed . value ) {
196
218
payWithPaystack ();
197
219
}
198
220
});
0 commit comments