-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
39 lines (35 loc) · 1.41 KB
/
main.js
File metadata and controls
39 lines (35 loc) · 1.41 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
'use strict';
// Update the following variables with your own values
const apiKey = ''; //Add Api Key here
const userId = ''; // Add your user ID here
document.addEventListener('DOMContentLoaded', function () {
const payButton = document.getElementById('pay-button');
if (payButton) {
payButton.disabled = true;
window.grailpay.init({
containerId: 'widget-container',
userId: userId,
token: apiKey,
sandbox: false, // Set to true to enable sandbox (test) mode; false for production
onError: function (error) {
console.log('GrailPay.onError', error);
},
onLinkedDefaultAccount: function (data) {
let responseContainer = document.getElementById('response-container');
if (responseContainer) {
responseContainer.innerHTML = data?.account_id ? `AccountId: ${data.account_id}` : '';
}
}
}).then(function (res) {
if (res.status) {
payButton.disabled = false;
console.log('GrailPay Banklink Widget initialized successfully');
}
}).catch(function (err) {
console.log(err, 'Error initializing GrailPay Banklink Widget');
});
payButton.addEventListener('click', function () {
window.grailpay.open();
});
}
});