-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample-1.js
More file actions
140 lines (122 loc) · 4.09 KB
/
example-1.js
File metadata and controls
140 lines (122 loc) · 4.09 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const fieldsExample1 = dlocalInstance.fields({
fonts: [{
cssSrc: 'https://rsms.me/inter/inter-ui.css'
}],
locale: 'en',
country: 'BR'
});
var example1 = document.querySelector(".example-1");
var form1 = example1.querySelector('form');
var error1 = form1.querySelector('.error');
var errorMessage1 = error1.querySelector('.message');
const panExample1 = fieldsExample1.create('pan', {
style: {
base: {
fontSize: "16px",
fontFamily: "Quicksand, Open Sans, Segoe UI, sans-serif",
lineHeight: '18px',
fontSmoothing: 'antialiased',
fontWeight: '500',
color: "#666",
'::placeholder': {
color: "#c1c1c1"
},
iconColor: "#c1c1c1"
},
autofilled: {
color: "#000000"
}
},
placeholder: "4111 1111 1111 1111"
});
let actualBrandExample1 = null;
panExample1.on('brand', function (event) {
if (event.brand && actualBrandExample1 !== event.brand) {
actualBrandExample1 = event.brand;
dlocalInstance.createInstallmentsPlan(panExample1, 20, "BRL")
.then((result) => {
var installmentsSelect1 = form1.querySelector('.installments');
buildInstallments(installmentsSelect1, result.installments);
}).catch((result) => {
console.error(result);
error1.classList.add('visible');
errorMessage1.innerText = result.error.message;
});
}
});
const expirationExample1 = fieldsExample1.create('expiration', {
style: {
base: {
fontSize: "16px",
fontFamily: "Quicksand, Open Sans, Segoe UI, sans-serif",
lineHeight: '18px',
fontSmoothing: 'antialiased',
fontWeight: '500',
color: "#666",
'::placeholder': {
color: "#c1c1c1"
}
},
autofilled: {
color: "#000000"
}
},
placeholder: monthStr + "/" + year
});
const cvvExample1 = fieldsExample1.create('cvv', {
style: {
base: {
fontSize: "16px",
fontFamily: "Quicksand, Open Sans, Segoe UI, sans-serif",
lineHeight: '18px',
fontSmoothing: 'antialiased',
fontWeight: '500',
color: "#666",
'::placeholder': {
color: "#c1c1c1"
}
}
},
placeholder: "123"
});
document.getElementById('fields-form-example-1').onsubmit = function (e) {
e.preventDefault();
// Trigger HTML5 validation UI on the form if any of the inputs fail
// validation.
var plainInputsValid = true;
Array.prototype.forEach.call(form1.querySelectorAll('input'), function (
input
) {
if (input.checkValidity && !input.checkValidity()) {
plainInputsValid = false;
return;
}
});
if (!plainInputsValid) {
triggerBrowserValidation(form1);
return;
}
if (errorMessage1.innerText) {
return;
}
// Show a loading screen...
example1.classList.add('submitting');
dlocalInstance.createToken(cvvExample1, {
name: document.getElementById('example-1-name').value
}).then((result) => {
error1.classList.remove('visible');
errorMessage1.innerText = "";
example1.classList.remove('submitting');
example1.querySelector(".token").innerText = result.token;
example1.classList.add("submitted");
}).catch((result) => {
example1.classList.remove('submitting');
error1.classList.add('visible');
errorMessage1.innerText = result.error.message;
});
}
registerClearBtn("example-1", [panExample1, expirationExample1, cvvExample1])
registerEvents("example-1", [panExample1, expirationExample1, cvvExample1], ["example-1-pan", "example-1-expiration", "example-1-cvv"])
panExample1.mount(document.getElementById('example-1-pan'));
expirationExample1.mount(document.getElementById('example-1-expiration'));
cvvExample1.mount(document.getElementById('example-1-cvv'));