/
GiftCards.js
105 lines (93 loc) · 3.61 KB
/
GiftCards.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import AdyenCheckout from '@adyen/adyen-web';
import '@adyen/adyen-web/dist/es/adyen.css';
import { handleChange, handleSubmit } from '../../handlers';
import { amount, shopperLocale, countryCode, returnUrl, shopperReference } from '../../config/commonConfig';
import { checkBalance, createOrder, createSession } from '../../services';
import '../../../config/polyfills';
import '../../utils';
import '../../style.scss';
(async () => {
window.checkout = await AdyenCheckout({
clientKey: process.env.__CLIENT_KEY__,
locale: shopperLocale,
countryCode,
environment: process.env.__CLIENT_ENV__,
onChange: handleChange,
onSubmit: handleSubmit,
showPayButton: true,
amount
});
window.giftcard = checkout
.create('giftcard', {
type: 'giftcard',
brand: 'valuelink',
onBalanceCheck: async (resolve, reject, data) => {
resolve(await checkBalance(data));
},
onOrderRequest: async (resolve, reject) => {
resolve(await createOrder({ amount }));
}
})
.mount('#genericgiftcard-container');
window.giftcard = checkout
.create('mealVoucher_FR_natixis', {
type: 'mealVoucher_FR_natixis',
brand: 'mealVoucher_FR_natixis',
onBalanceCheck: async (resolve, reject, data) => {
resolve(await checkBalance(data));
},
onOrderRequest: async (resolve, reject) => {
resolve(await createOrder({ amount }));
}
})
.mount('#mealvoucher-fr-container');
const session = await createSession({
amount,
reference: 'antonio_giftcard_test',
returnUrl,
shopperLocale,
shopperReference,
countryCode
});
const sessionCheckout = await AdyenCheckout({
environment: process.env.__CLIENT_ENV__,
clientKey: process.env.__CLIENT_KEY__,
session,
showPayButton: true,
// Events
beforeSubmit: (data, component, actions) => {
actions.resolve(data);
},
onPaymentCompleted: (result, component) => {
console.info(result, component);
},
onError: (error, component) => {
console.error(error.message, component);
}
});
const checkoutAddButton = document.querySelector('#custom-checkout-add-button');
const checkoutConfirmButton = document.querySelector('#custom-checkout-confirm-button');
const checkoutCardButton = document.querySelector('#custom-checkout-card-button');
checkoutConfirmButton.style.display = 'none';
const giftcardCheckBalance = () => window.giftcard.balanceCheck();
const giftcardSubmit = () => window.giftcard.submit();
const cardSubmit = () => window.card.submit();
checkoutAddButton.addEventListener('click', giftcardCheckBalance);
checkoutConfirmButton.addEventListener('click', giftcardSubmit);
checkoutCardButton.addEventListener('click', cardSubmit);
window.giftcard = sessionCheckout
.create('giftcard', {
type: 'giftcard',
brand: 'svs',
onOrderCreated: () => {
console.log('onOrderCreated');
},
onRequiringConfirmation: () => {
console.log('onRequiringConfirmation');
checkoutConfirmButton.style.display = '';
checkoutAddButton.style.display = 'none';
}
})
.mount('#giftcard-session-container');
window.card = sessionCheckout.create('card').mount('#payment-method-container');
})();