-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (60 loc) · 1.88 KB
/
Copy pathmain.js
File metadata and controls
64 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const PUBLIC_KEY = import.meta.env.VITE_PUBLIC_KEY;
const paystack = new PaystackPop();
const makePaymentButton = document.getElementById('payment-btn')
// Method 1
const preloadPayment = async () => {
await paystack.paymentRequest({
key: PUBLIC_KEY,
email: `${Math.random().toString(36).substring(2)}@email.com`,
amount: 10000,
currency: 'NGN',
container: 'paystack-apple-pay',
loadPaystackCheckoutButton: 'paystack-other-channels',
style: {
theme: 'dark',
applePay: {
margin: '10px',
padding: '10px',
width: '100%',
borderRadius: '5px',
type: 'pay', // Default value is 'pay'. See other apple pay button types here https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_css
locale: 'en'
}
}, // custom styles for button elements
onSuccess(response) {
// do stuff
console.log("response: ", response)
},
onError(error) {
console.log(`Error: ${error.message}`)
},
onCancel() {
console.log("Pop up closed!")
},
onElementsMount(elements) { // { applePay: true } or null
if (elements) {
console.log(`Successfully mounted elements: ${JSON.stringify(elements)}`);
} else {
console.log('Could not load elements');
}
}
});
}
// Method 2
// const makePayment = async () => {
// await paystack.checkout({
// accessCode: "rl7pny5ixu0yyhd",
// onSuccess: (transaction) => {
// console.log("Transaction: ", transaction)
// alert(`Ref: ${transaction.reference}`)
// },
// onElementsMount(elements) { // { applePay: true } or null
// console.log(`Elements: ${JSON.stringify(elements)}`);
// },
// onCancel: () => {
// console.log("Pop up closed!")
// }
// });
// }
// makePaymentButton.addEventListener('click', makePayment)
preloadPayment()