@danielseres9/adobe-commerce-checkout 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/checkout.js +98 -17
package/package.json
CHANGED
package/src/checkout.js
CHANGED
|
@@ -35,6 +35,15 @@ function getDefaultWindow() {
|
|
|
35
35
|
return typeof window !== 'undefined' ? window : undefined;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
function afterNextFrame(callback, windowRef = getDefaultWindow()) {
|
|
39
|
+
if (windowRef?.requestAnimationFrame) {
|
|
40
|
+
windowRef.requestAnimationFrame(callback);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setTimeout(callback, 0);
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
function getWorldpayCheckoutSdkUrl(environment = 'try') {
|
|
39
48
|
return WORLDPAY_CHECKOUT_SDK_URLS[environment] ?? WORLDPAY_CHECKOUT_SDK_URLS.try;
|
|
40
49
|
}
|
|
@@ -85,6 +94,10 @@ function createWorldpayDirectForm(documentRef = getDefaultDocument()) {
|
|
|
85
94
|
form.addEventListener('submit', (event) => event.preventDefault());
|
|
86
95
|
|
|
87
96
|
form.innerHTML = `
|
|
97
|
+
<div class="worldpay-direct-header">
|
|
98
|
+
<span class="worldpay-direct-title">Card details</span>
|
|
99
|
+
<span class="worldpay-direct-secure">Secured by Worldpay</span>
|
|
100
|
+
</div>
|
|
88
101
|
<div class="worldpay-direct-field-group">
|
|
89
102
|
<label class="worldpay-direct-label" for="worldpay-direct-pan-${suffix}">Card number</label>
|
|
90
103
|
<section id="worldpay-direct-pan-${suffix}" class="worldpay-direct-field"></section>
|
|
@@ -105,14 +118,40 @@ function createWorldpayDirectForm(documentRef = getDefaultDocument()) {
|
|
|
105
118
|
const style = documentRef.createElement('style');
|
|
106
119
|
style.textContent = `
|
|
107
120
|
.worldpay-direct-form {
|
|
121
|
+
background: #f7f9fb;
|
|
122
|
+
border: 1px solid #d8dee8;
|
|
123
|
+
border-radius: 8px;
|
|
124
|
+
box-sizing: border-box;
|
|
108
125
|
display: grid;
|
|
109
|
-
gap:
|
|
126
|
+
gap: 12px;
|
|
110
127
|
max-width: 520px;
|
|
128
|
+
padding: 16px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.worldpay-direct-header {
|
|
132
|
+
align-items: baseline;
|
|
133
|
+
display: flex;
|
|
134
|
+
flex-wrap: wrap;
|
|
135
|
+
gap: 8px 12px;
|
|
136
|
+
justify-content: space-between;
|
|
137
|
+
margin-bottom: 2px;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.worldpay-direct-title {
|
|
141
|
+
color: #111827;
|
|
142
|
+
font-size: 16px;
|
|
143
|
+
font-weight: 700;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.worldpay-direct-secure {
|
|
147
|
+
color: #5f6f86;
|
|
148
|
+
font-size: 12px;
|
|
149
|
+
font-weight: 600;
|
|
111
150
|
}
|
|
112
151
|
|
|
113
152
|
.worldpay-direct-row {
|
|
114
153
|
display: grid;
|
|
115
|
-
gap:
|
|
154
|
+
gap: 12px;
|
|
116
155
|
grid-template-columns: 1fr;
|
|
117
156
|
}
|
|
118
157
|
|
|
@@ -120,27 +159,44 @@ function createWorldpayDirectForm(documentRef = getDefaultDocument()) {
|
|
|
120
159
|
display: block;
|
|
121
160
|
font-size: 14px;
|
|
122
161
|
font-weight: 600;
|
|
123
|
-
margin-bottom:
|
|
162
|
+
margin-bottom: 6px;
|
|
124
163
|
}
|
|
125
164
|
|
|
126
165
|
.worldpay-direct-field {
|
|
127
|
-
|
|
128
|
-
border
|
|
129
|
-
|
|
130
|
-
|
|
166
|
+
background: #fff;
|
|
167
|
+
border: 1px solid #aeb8c7;
|
|
168
|
+
border-radius: 6px;
|
|
169
|
+
box-sizing: border-box;
|
|
170
|
+
height: 46px;
|
|
171
|
+
overflow: hidden;
|
|
172
|
+
padding: 0 12px;
|
|
173
|
+
transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.worldpay-direct-field iframe {
|
|
177
|
+
border: 0;
|
|
178
|
+
display: block;
|
|
179
|
+
height: 100%;
|
|
180
|
+
width: 100%;
|
|
131
181
|
}
|
|
132
182
|
|
|
133
183
|
.worldpay-direct-field.is-onfocus {
|
|
134
|
-
|
|
135
|
-
|
|
184
|
+
background: #fff;
|
|
185
|
+
border-color: #0f62fe;
|
|
186
|
+
box-shadow: 0 0 0 2px rgba(15, 98, 254, 0.16);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.worldpay-direct-field.is-valid {
|
|
190
|
+
border-color: #198754;
|
|
136
191
|
}
|
|
137
192
|
|
|
138
193
|
.worldpay-direct-field.is-invalid {
|
|
139
|
-
border-color: #
|
|
194
|
+
border-color: #b42318;
|
|
195
|
+
box-shadow: 0 0 0 2px rgba(180, 35, 24, 0.12);
|
|
140
196
|
}
|
|
141
197
|
|
|
142
198
|
.worldpay-direct-error {
|
|
143
|
-
color: #
|
|
199
|
+
color: #b42318;
|
|
144
200
|
font-size: 14px;
|
|
145
201
|
margin: 0;
|
|
146
202
|
}
|
|
@@ -175,11 +231,12 @@ function showWorldpayDirectError(errorElement, error) {
|
|
|
175
231
|
function initializeWorldpayDirectCheckout({
|
|
176
232
|
additionalData,
|
|
177
233
|
formRef,
|
|
234
|
+
elements,
|
|
178
235
|
documentRef = getDefaultDocument(),
|
|
179
236
|
windowRef = getDefaultWindow(),
|
|
180
237
|
}) {
|
|
181
238
|
const { checkoutId, environment } = getWorldpayDirectConfig(additionalData);
|
|
182
|
-
const { form, selectors, error } = createWorldpayDirectForm(documentRef);
|
|
239
|
+
const { form, selectors, error } = elements ?? createWorldpayDirectForm(documentRef);
|
|
183
240
|
|
|
184
241
|
if (!checkoutId) {
|
|
185
242
|
showWorldpayDirectError(error, new Error('Worldpay checkout id is missing.'));
|
|
@@ -217,6 +274,25 @@ function initializeWorldpayDirectCheckout({
|
|
|
217
274
|
},
|
|
218
275
|
},
|
|
219
276
|
enablePanFormatting: true,
|
|
277
|
+
styles: {
|
|
278
|
+
input: {
|
|
279
|
+
color: '#111827',
|
|
280
|
+
'font-family': 'Arial, Helvetica, sans-serif',
|
|
281
|
+
'font-size': '16px',
|
|
282
|
+
'font-weight': '400',
|
|
283
|
+
'letter-spacing': '0',
|
|
284
|
+
'line-height': '20px',
|
|
285
|
+
},
|
|
286
|
+
'input#pan': {
|
|
287
|
+
'letter-spacing': '1px',
|
|
288
|
+
},
|
|
289
|
+
'input.is-onfocus': {
|
|
290
|
+
color: '#111827',
|
|
291
|
+
},
|
|
292
|
+
'input.is-invalid': {
|
|
293
|
+
color: '#b42318',
|
|
294
|
+
},
|
|
295
|
+
},
|
|
220
296
|
},
|
|
221
297
|
(initError, checkout) => {
|
|
222
298
|
if (initError) {
|
|
@@ -329,12 +405,17 @@ export async function handleWorldpayPlaceOrder({
|
|
|
329
405
|
}
|
|
330
406
|
|
|
331
407
|
export function renderWorldpayDirectFields(ctx, { formRef } = {}) {
|
|
332
|
-
const
|
|
333
|
-
additionalData: ctx.additionalData,
|
|
334
|
-
formRef,
|
|
335
|
-
});
|
|
408
|
+
const elements = createWorldpayDirectForm();
|
|
336
409
|
|
|
337
|
-
ctx.replaceHTML(form);
|
|
410
|
+
ctx.replaceHTML(elements.form);
|
|
411
|
+
|
|
412
|
+
afterNextFrame(() => {
|
|
413
|
+
initializeWorldpayDirectCheckout({
|
|
414
|
+
additionalData: ctx.additionalData,
|
|
415
|
+
formRef,
|
|
416
|
+
elements,
|
|
417
|
+
});
|
|
418
|
+
});
|
|
338
419
|
}
|
|
339
420
|
|
|
340
421
|
export async function startWorldpayDirectPayment({
|