@dintero/checkout-web-sdk 0.4.5 → 0.5.1
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/.github/workflows/release.yml +7 -1
- package/README.md +12 -3
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/base.css +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/block-navigation.js +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/checkout.ts.html +7 -4
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/createIframeAsync.ts.html +14 -14
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/favicon.png +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/index.html +17 -17
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/index.ts.html +102 -30
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/prettify.css +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/prettify.js +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/sorter.js +0 -0
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/subscribe.ts.html +15 -15
- package/coverage/{Chrome Headless 105.0.5173.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/url.ts.html +1 -1
- package/dist/declarations/src/checkout.d.ts +2 -1
- package/dist/dintero-checkout-web-sdk.cjs.dev.js +72 -60
- package/dist/dintero-checkout-web-sdk.cjs.prod.js +72 -60
- package/dist/dintero-checkout-web-sdk.esm.js +72 -60
- package/dist/dintero-checkout-web-sdk.umd.min.js +1 -1
- package/dist/dintero-checkout-web-sdk.umd.min.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import 'native-promise-only';
|
|
|
2
2
|
|
|
3
3
|
var pkg = {
|
|
4
4
|
name: "@dintero/checkout-web-sdk",
|
|
5
|
-
version: "0.
|
|
5
|
+
version: "0.5.1",
|
|
6
6
|
description: "Dintero Checkout SDK for web frontends",
|
|
7
7
|
main: "dist/dintero-checkout-web-sdk.cjs.js",
|
|
8
8
|
module: "dist/dintero-checkout-web-sdk.esm.js",
|
|
@@ -42,7 +42,7 @@ var pkg = {
|
|
|
42
42
|
"karma-typescript": "^5.0.3",
|
|
43
43
|
mocha: "^8.1.1",
|
|
44
44
|
prettier: "^2.6.2",
|
|
45
|
-
puppeteer: "^
|
|
45
|
+
puppeteer: "^19.0.0",
|
|
46
46
|
"semantic-release": "^19.0.2",
|
|
47
47
|
sinon: "^14.0.0",
|
|
48
48
|
typescript: "^4.2.4"
|
|
@@ -53,7 +53,6 @@ var pkg = {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
let CheckoutEvents;
|
|
56
|
-
|
|
57
56
|
(function (CheckoutEvents) {
|
|
58
57
|
CheckoutEvents["SessionNotFound"] = "SessionNotFound";
|
|
59
58
|
CheckoutEvents["SessionLoaded"] = "SessionLoaded";
|
|
@@ -67,21 +66,20 @@ let CheckoutEvents;
|
|
|
67
66
|
CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
|
|
68
67
|
CheckoutEvents["ValidateSession"] = "ValidateSession";
|
|
69
68
|
})(CheckoutEvents || (CheckoutEvents = {}));
|
|
70
|
-
|
|
71
69
|
let InternalCheckoutEvents;
|
|
72
|
-
|
|
73
70
|
(function (InternalCheckoutEvents) {
|
|
74
71
|
InternalCheckoutEvents["HeightChanged"] = "HeightChanged";
|
|
75
72
|
InternalCheckoutEvents["LanguageChanged"] = "LanguageChanged";
|
|
73
|
+
InternalCheckoutEvents["ScrollToTop"] = "ScrollToTop";
|
|
76
74
|
})(InternalCheckoutEvents || (InternalCheckoutEvents = {}));
|
|
77
75
|
|
|
78
76
|
/**
|
|
79
77
|
* Wraps window.location.assign()
|
|
80
78
|
*/
|
|
81
|
-
|
|
82
79
|
const windowLocationAssign = url => {
|
|
83
80
|
window.location.assign(url);
|
|
84
81
|
};
|
|
82
|
+
|
|
85
83
|
/**
|
|
86
84
|
* Get the url for the session./yarn-error.log
|
|
87
85
|
.DS_Store
|
|
@@ -95,12 +93,11 @@ const getSessionUrl = options => {
|
|
|
95
93
|
ui,
|
|
96
94
|
shouldCallValidateSession
|
|
97
95
|
} = options;
|
|
98
|
-
|
|
99
96
|
if (!endpoint) {
|
|
100
97
|
throw new Error("Invalid endpoint");
|
|
101
|
-
}
|
|
102
|
-
|
|
98
|
+
}
|
|
103
99
|
|
|
100
|
+
// Compose url for view session endpoint with optional language parameter.
|
|
104
101
|
let languageParam = language ? `language=${language}` : "";
|
|
105
102
|
let uiParam = ui ? `ui=${ui}` : "";
|
|
106
103
|
let sdk = `sdk=${pkg.version}`;
|
|
@@ -119,12 +116,14 @@ const createIframeAsync = (container, endpoint, url) => {
|
|
|
119
116
|
if (!container || !container.appendChild) {
|
|
120
117
|
throw new Error("Invalid container");
|
|
121
118
|
}
|
|
119
|
+
const iframe = document.createElement("iframe");
|
|
122
120
|
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
// No border, transparent and stretch to 100% of the container width.
|
|
125
122
|
iframe.setAttribute("frameborder", "0");
|
|
126
123
|
iframe.setAttribute("allowTransparency", "true");
|
|
127
|
-
iframe.setAttribute("style", "width:100%; height:0;");
|
|
124
|
+
iframe.setAttribute("style", "width:100%; height:0;");
|
|
125
|
+
|
|
126
|
+
// TODO: Get this to work as expected, might be tricky with current
|
|
128
127
|
// tests since they will require the csp to be "unsafe-inline".
|
|
129
128
|
// The server needs to add the same property in the Content Security
|
|
130
129
|
// Policy headers in the response for this to work. A CSP header set by
|
|
@@ -132,25 +131,27 @@ const createIframeAsync = (container, endpoint, url) => {
|
|
|
132
131
|
// CSP from the iframe host.
|
|
133
132
|
// Content Security Policy, should be limited to "endpoint".
|
|
134
133
|
// iframe.setAttribute("csp", `default-src ${endpoint}`);
|
|
134
|
+
|
|
135
135
|
// Apply extra restrictions to the content in the iframe.
|
|
136
136
|
// allow popups is needed to open terms in new window
|
|
137
|
+
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox");
|
|
138
|
+
|
|
139
|
+
// The download priority of the resource in the <iframe>'s src attribute.
|
|
140
|
+
iframe.setAttribute("importance", "high");
|
|
137
141
|
|
|
138
|
-
|
|
142
|
+
// Set the iframe source to the url.
|
|
143
|
+
iframe.setAttribute("src", url);
|
|
139
144
|
|
|
140
|
-
|
|
145
|
+
// Resolve or reject promise when iframe loads.
|
|
141
146
|
|
|
142
|
-
iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads.
|
|
143
147
|
// // Add iframe to the container.
|
|
144
148
|
// container.appendChild(iframe);
|
|
145
|
-
|
|
146
149
|
return {
|
|
147
150
|
iframe,
|
|
148
151
|
initiate: async () => {
|
|
149
152
|
return new Promise((resolve, reject) => {
|
|
150
153
|
iframe.onload = () => resolve();
|
|
151
|
-
|
|
152
154
|
iframe.onerror = () => reject();
|
|
153
|
-
|
|
154
155
|
container.appendChild(iframe);
|
|
155
156
|
});
|
|
156
157
|
}
|
|
@@ -171,11 +172,10 @@ const postAck = (iframe, event) => {
|
|
|
171
172
|
}, event.origin || "*");
|
|
172
173
|
}
|
|
173
174
|
};
|
|
175
|
+
|
|
174
176
|
/**
|
|
175
177
|
* Post a SessionLock-event to the checkout iframe.
|
|
176
178
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
179
|
const postSessionLock = (iframe, sid) => {
|
|
180
180
|
if (iframe.contentWindow) {
|
|
181
181
|
iframe.contentWindow.postMessage({
|
|
@@ -184,10 +184,10 @@ const postSessionLock = (iframe, sid) => {
|
|
|
184
184
|
}, "*");
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
|
+
|
|
187
188
|
/**
|
|
188
189
|
* Post the validation result to the checkout iframe
|
|
189
190
|
*/
|
|
190
|
-
|
|
191
191
|
const postValidationResult = (iframe, sid, result) => {
|
|
192
192
|
if (iframe.contentWindow) {
|
|
193
193
|
iframe.contentWindow.postMessage({
|
|
@@ -197,10 +197,10 @@ const postValidationResult = (iframe, sid, result) => {
|
|
|
197
197
|
}, "*");
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
|
+
|
|
200
201
|
/**
|
|
201
202
|
* Post RefreshSession-event to the checkout iframe.
|
|
202
203
|
*/
|
|
203
|
-
|
|
204
204
|
const postSessionRefresh = (iframe, sid) => {
|
|
205
205
|
if (iframe.contentWindow) {
|
|
206
206
|
iframe.contentWindow.postMessage({
|
|
@@ -209,10 +209,10 @@ const postSessionRefresh = (iframe, sid) => {
|
|
|
209
209
|
}, "*");
|
|
210
210
|
}
|
|
211
211
|
};
|
|
212
|
+
|
|
212
213
|
/**
|
|
213
214
|
* Post setActivePaymentProductType-event to the checkout iframe.
|
|
214
215
|
*/
|
|
215
|
-
|
|
216
216
|
const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
217
217
|
if (iframe.contentWindow) {
|
|
218
218
|
iframe.contentWindow.postMessage({
|
|
@@ -222,11 +222,11 @@ const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
|
222
222
|
}, "*");
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
|
+
|
|
225
226
|
/**
|
|
226
227
|
* Subscribe to events from an iframe given a handler and a set
|
|
227
228
|
* of event types.
|
|
228
229
|
*/
|
|
229
|
-
|
|
230
230
|
const subscribe = options => {
|
|
231
231
|
const {
|
|
232
232
|
sid,
|
|
@@ -234,29 +234,30 @@ const subscribe = options => {
|
|
|
234
234
|
handler,
|
|
235
235
|
eventTypes,
|
|
236
236
|
checkout
|
|
237
|
-
} = options;
|
|
238
|
-
// filters on event type(s) in the event data.
|
|
237
|
+
} = options;
|
|
239
238
|
|
|
239
|
+
// Wrap event handler in a function that checks for correct origin and
|
|
240
|
+
// filters on event type(s) in the event data.
|
|
240
241
|
const wrappedHandler = event => {
|
|
241
242
|
const correctOrigin = event.origin === endpoint;
|
|
242
243
|
const correctWindow = event.source === checkout.iframe.contentWindow;
|
|
243
244
|
const correctSid = event.data && event.data.sid === sid;
|
|
244
245
|
const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1;
|
|
245
|
-
|
|
246
246
|
if (correctOrigin && correctWindow && correctSid && correctMessageType) {
|
|
247
247
|
postAck(checkout.iframe, event);
|
|
248
248
|
handler(event.data, checkout);
|
|
249
249
|
}
|
|
250
|
-
};
|
|
251
|
-
|
|
250
|
+
};
|
|
252
251
|
|
|
253
|
-
|
|
252
|
+
// Add event listener to the iframe.
|
|
253
|
+
window.addEventListener("message", wrappedHandler, false);
|
|
254
254
|
|
|
255
|
+
// Function to remove the event listener from the iframe.
|
|
255
256
|
const unsubscribe = () => {
|
|
256
257
|
window.removeEventListener("message", wrappedHandler, false);
|
|
257
|
-
};
|
|
258
|
-
|
|
258
|
+
};
|
|
259
259
|
|
|
260
|
+
// Return object with unsubscribe function.
|
|
260
261
|
return {
|
|
261
262
|
unsubscribe
|
|
262
263
|
};
|
|
@@ -270,32 +271,47 @@ const followHref = event => {
|
|
|
270
271
|
windowLocationAssign(event.href);
|
|
271
272
|
}
|
|
272
273
|
};
|
|
274
|
+
|
|
273
275
|
/**
|
|
274
276
|
* An event handler that sets height of the iframe.
|
|
275
277
|
*/
|
|
276
|
-
|
|
277
|
-
|
|
278
278
|
const setIframeHeight = (event, checkout) => {
|
|
279
279
|
if (event.height || event.height === 0) {
|
|
280
280
|
checkout.iframe.setAttribute("style", `width:100%; height:${event.height}px;`);
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
283
|
|
|
284
|
+
/**
|
|
285
|
+
* An event handler that scrolls to the top of the iframe. This is useful when the user
|
|
286
|
+
* is navigated to another page.
|
|
287
|
+
*/
|
|
288
|
+
const scrollToIframeTop = (event, checkout) => {
|
|
289
|
+
try {
|
|
290
|
+
checkout.iframe.scrollIntoView({
|
|
291
|
+
block: 'start',
|
|
292
|
+
behavior: 'smooth'
|
|
293
|
+
});
|
|
294
|
+
} catch (e) {
|
|
295
|
+
// Ignore erorr silenty bug log it to the console.
|
|
296
|
+
console.error(e);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* An event handler that sets language in the iframe.
|
|
302
|
+
*/
|
|
284
303
|
const setLanguage = (event, checkout) => {
|
|
285
304
|
if (event.language) {
|
|
286
305
|
checkout.language = event.language;
|
|
287
306
|
}
|
|
288
307
|
};
|
|
289
|
-
|
|
290
308
|
const handleWithResult = (sid, endpoint, handler) => {
|
|
291
309
|
return (event, checkout) => {
|
|
292
310
|
const eventKeys = ["sid", "merchant_reference", "transaction_id", "error"];
|
|
293
311
|
const pairs = eventKeys.map(key => [key, event[key]]);
|
|
294
|
-
|
|
295
312
|
if (event.type === CheckoutEvents.SessionCancel && !event.error) {
|
|
296
313
|
pairs.push(["error", "cancelled"]);
|
|
297
314
|
}
|
|
298
|
-
|
|
299
315
|
pairs.push(["language", checkout.language]);
|
|
300
316
|
pairs.push(["sdk", pkg.version]);
|
|
301
317
|
const urlQuery = pairs.filter(([key, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
|
|
@@ -303,11 +319,10 @@ const handleWithResult = (sid, endpoint, handler) => {
|
|
|
303
319
|
handler(event, checkout);
|
|
304
320
|
};
|
|
305
321
|
};
|
|
322
|
+
|
|
306
323
|
/**
|
|
307
324
|
* Show a dintero payment session in an embedded iframe.
|
|
308
325
|
*/
|
|
309
|
-
|
|
310
|
-
|
|
311
326
|
const embed = async options => {
|
|
312
327
|
const {
|
|
313
328
|
container,
|
|
@@ -326,8 +341,9 @@ const embed = async options => {
|
|
|
326
341
|
onValidateSession
|
|
327
342
|
} = options;
|
|
328
343
|
let checkout;
|
|
329
|
-
const subscriptions = [];
|
|
344
|
+
const subscriptions = [];
|
|
330
345
|
|
|
346
|
+
// Create iframe
|
|
331
347
|
const {
|
|
332
348
|
iframe,
|
|
333
349
|
initiate
|
|
@@ -338,30 +354,27 @@ const embed = async options => {
|
|
|
338
354
|
ui: "inline",
|
|
339
355
|
shouldCallValidateSession: onValidateSession !== undefined
|
|
340
356
|
}));
|
|
357
|
+
|
|
341
358
|
/**
|
|
342
359
|
* Function that removes the iframe and all event listeners.
|
|
343
360
|
*/
|
|
344
|
-
|
|
345
361
|
const destroy = () => {
|
|
346
362
|
if (iframe) {
|
|
347
363
|
subscriptions.forEach(sub => sub.unsubscribe());
|
|
348
|
-
|
|
349
364
|
if (iframe.parentElement) {
|
|
350
365
|
container.removeChild(iframe);
|
|
351
366
|
}
|
|
352
367
|
}
|
|
353
368
|
};
|
|
369
|
+
|
|
354
370
|
/**
|
|
355
371
|
* Turn an action into a promise by specifying resolve and
|
|
356
372
|
* reject events.
|
|
357
373
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
374
|
const promisifyAction = (action, resolveEvent, rejectEvent) => {
|
|
361
375
|
if (!checkout) {
|
|
362
376
|
throw new Error("Unable to create action promise: checkout is undefined");
|
|
363
377
|
}
|
|
364
|
-
|
|
365
378
|
return new Promise((resolve, reject) => {
|
|
366
379
|
const eventSubscriptions = [];
|
|
367
380
|
eventSubscriptions.push(subscribe({
|
|
@@ -387,40 +400,34 @@ const embed = async options => {
|
|
|
387
400
|
action();
|
|
388
401
|
});
|
|
389
402
|
};
|
|
390
|
-
|
|
391
403
|
const lockSession = () => {
|
|
392
404
|
return promisifyAction(() => {
|
|
393
405
|
postSessionLock(iframe, sid);
|
|
394
406
|
}, CheckoutEvents.SessionLocked, CheckoutEvents.SessionLockFailed);
|
|
395
407
|
};
|
|
396
|
-
|
|
397
408
|
const refreshSession = () => {
|
|
398
409
|
return promisifyAction(() => {
|
|
399
410
|
postSessionRefresh(iframe, sid);
|
|
400
411
|
}, CheckoutEvents.SessionUpdated, CheckoutEvents.SessionNotFound);
|
|
401
412
|
};
|
|
402
|
-
|
|
403
413
|
const setActivePaymentProductType = paymentProductType => {
|
|
404
414
|
postActivePaymentProductType(iframe, sid, paymentProductType);
|
|
405
415
|
};
|
|
406
|
-
|
|
407
416
|
const submitValidationResult = result => {
|
|
408
417
|
postValidationResult(iframe, sid, result);
|
|
409
418
|
};
|
|
410
|
-
|
|
411
419
|
const wrappedOnValidateSession = (event, checkout) => {
|
|
412
420
|
if (onValidateSession) {
|
|
413
421
|
onValidateSession(event, checkout, submitValidationResult);
|
|
414
422
|
}
|
|
415
423
|
};
|
|
416
|
-
|
|
417
424
|
const wrappedOnSessionLocked = (event, checkout) => {
|
|
418
425
|
if (onSessionLocked) {
|
|
419
426
|
onSessionLocked(event, checkout, refreshSession);
|
|
420
427
|
}
|
|
421
|
-
};
|
|
422
|
-
|
|
428
|
+
};
|
|
423
429
|
|
|
430
|
+
// Create checkout object that wraps the destroy function.
|
|
424
431
|
checkout = {
|
|
425
432
|
destroy,
|
|
426
433
|
iframe,
|
|
@@ -429,14 +436,18 @@ const embed = async options => {
|
|
|
429
436
|
refreshSession,
|
|
430
437
|
setActivePaymentProductType,
|
|
431
438
|
submitValidationResult
|
|
432
|
-
};
|
|
439
|
+
};
|
|
433
440
|
|
|
441
|
+
// Add event handlers (or in some cases add a fallback href handler).
|
|
434
442
|
[{
|
|
435
443
|
handler: setLanguage,
|
|
436
444
|
eventTypes: [InternalCheckoutEvents.LanguageChanged]
|
|
437
445
|
}, {
|
|
438
446
|
handler: setIframeHeight,
|
|
439
447
|
eventTypes: [InternalCheckoutEvents.HeightChanged]
|
|
448
|
+
}, {
|
|
449
|
+
handler: scrollToIframeTop,
|
|
450
|
+
eventTypes: [InternalCheckoutEvents.ScrollToTop]
|
|
440
451
|
}, {
|
|
441
452
|
handler: onSession,
|
|
442
453
|
eventTypes: [CheckoutEvents.SessionLoaded, CheckoutEvents.SessionUpdated]
|
|
@@ -483,23 +494,24 @@ const embed = async options => {
|
|
|
483
494
|
checkout
|
|
484
495
|
}));
|
|
485
496
|
}
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
await initiate(); // Return object with function to destroy the checkout.
|
|
497
|
+
});
|
|
489
498
|
|
|
499
|
+
// Add iframe to DOM
|
|
500
|
+
await initiate();
|
|
501
|
+
// Return object with function to destroy the checkout.
|
|
490
502
|
return checkout;
|
|
491
503
|
};
|
|
504
|
+
|
|
492
505
|
/**
|
|
493
506
|
* Redirect the customer to a payment session in the Dintero Checkout.
|
|
494
507
|
*/
|
|
495
|
-
|
|
496
508
|
const redirect = options => {
|
|
497
509
|
const {
|
|
498
510
|
sid,
|
|
499
511
|
language,
|
|
500
512
|
endpoint = "https://checkout.dintero.com"
|
|
501
|
-
} = options;
|
|
502
|
-
|
|
513
|
+
} = options;
|
|
514
|
+
// Redirect the current browser window to the checkout session url.
|
|
503
515
|
windowLocationAssign(getSessionUrl({
|
|
504
516
|
sid,
|
|
505
517
|
endpoint,
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
v0.8.1 (c) Kyle Simpson
|
|
4
4
|
MIT License: http://getify.mit-license.org
|
|
5
5
|
*/
|
|
6
|
-
var t,o,i;i=function(){var e,n,t,o=Object.prototype.toString,i="undefined"!=typeof setImmediate?function(e){return setImmediate(e)}:setTimeout;try{Object.defineProperty({},"x",{}),e=function(e,n,t,o){return Object.defineProperty(e,n,{value:t,writable:!0,configurable:!1!==o})}}catch(n){e=function(e,n,t){return e[n]=t,e}}function r(e,o){t.add(e,o),n||(n=i(t.drain))}function s(e){var n,t=typeof e;return null==e||"object"!=t&&"function"!=t||(n=e.then),"function"==typeof n&&n}function a(){for(var e=0;e<this.chain.length;e++)c(this,1===this.state?this.chain[e].success:this.chain[e].failure,this.chain[e]);this.chain.length=0}function c(e,n,t){var o,i;try{!1===n?t.reject(e.msg):(o=!0===n?e.msg:n.call(void 0,e.msg))===t.promise?t.reject(TypeError("Promise-chain cycle")):(i=s(o))?i.call(o,t.resolve,t.reject):t.resolve(o)}catch(e){t.reject(e)}}function d(e){var n,t=this;if(!t.triggered){t.triggered=!0,t.def&&(t=t.def);try{(n=s(e))?r((function(){var o=new f(t);try{n.call(e,(function(){d.apply(o,arguments)}),(function(){u.apply(o,arguments)}))}catch(e){u.call(o,e)}})):(t.msg=e,t.state=1,t.chain.length>0&&r(a,t))}catch(e){u.call(new f(t),e)}}}function u(e){var n=this;n.triggered||(n.triggered=!0,n.def&&(n=n.def),n.msg=e,n.state=2,n.chain.length>0&&r(a,n))}function l(e,n,t,o){for(var i=0;i<n.length;i++)!function(i){e.resolve(n[i]).then((function(e){t(i,e)}),o)}(i)}function f(e){this.def=e,this.triggered=!1}function h(e){this.promise=e,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function p(e){if("function"!=typeof e)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var n=new h(this);this.then=function(e,t){var o={success:"function"!=typeof e||e,failure:"function"==typeof t&&t};return o.promise=new this.constructor((function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");o.resolve=e,o.reject=n})),n.chain.push(o),0!==n.state&&r(a,n),o.promise},this.catch=function(e){return this.then(void 0,e)};try{e.call(void 0,(function(e){d.call(n,e)}),(function(e){u.call(n,e)}))}catch(e){u.call(n,e)}}t=function(){var e,t,o;function i(e,n){this.fn=e,this.self=n,this.next=void 0}return{add:function(n,r){o=new i(n,r),t?t.next=o:e=o,t=o,o=void 0},drain:function(){var o=e;for(e=t=n=void 0;o;)o.fn.call(o.self),o=o.next}}}();var y=e({},"constructor",p,!1);return p.prototype=y,e(y,"__NPO__",0,!1),e(p,"resolve",(function(e){return e&&"object"==typeof e&&1===e.__NPO__?e:new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");n(e)}))})),e(p,"reject",(function(e){return new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");t(e)}))})),e(p,"all",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):0===e.length?n.resolve([]):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");var i=e.length,r=Array(i),s=0;l(n,e,(function(e,n){r[e]=n,++s===i&&t(r)}),o)}))})),e(p,"race",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");l(n,e,(function(e,n){t(n)}),o)}))})),p},(o=n)[t="Promise"]=o[t]||i(),e.exports&&(e.exports=o[t])}));var t="0.
|
|
6
|
+
var t,o,i;i=function(){var e,n,t,o=Object.prototype.toString,i="undefined"!=typeof setImmediate?function(e){return setImmediate(e)}:setTimeout;try{Object.defineProperty({},"x",{}),e=function(e,n,t,o){return Object.defineProperty(e,n,{value:t,writable:!0,configurable:!1!==o})}}catch(n){e=function(e,n,t){return e[n]=t,e}}function r(e,o){t.add(e,o),n||(n=i(t.drain))}function s(e){var n,t=typeof e;return null==e||"object"!=t&&"function"!=t||(n=e.then),"function"==typeof n&&n}function a(){for(var e=0;e<this.chain.length;e++)c(this,1===this.state?this.chain[e].success:this.chain[e].failure,this.chain[e]);this.chain.length=0}function c(e,n,t){var o,i;try{!1===n?t.reject(e.msg):(o=!0===n?e.msg:n.call(void 0,e.msg))===t.promise?t.reject(TypeError("Promise-chain cycle")):(i=s(o))?i.call(o,t.resolve,t.reject):t.resolve(o)}catch(e){t.reject(e)}}function d(e){var n,t=this;if(!t.triggered){t.triggered=!0,t.def&&(t=t.def);try{(n=s(e))?r((function(){var o=new f(t);try{n.call(e,(function(){d.apply(o,arguments)}),(function(){u.apply(o,arguments)}))}catch(e){u.call(o,e)}})):(t.msg=e,t.state=1,t.chain.length>0&&r(a,t))}catch(e){u.call(new f(t),e)}}}function u(e){var n=this;n.triggered||(n.triggered=!0,n.def&&(n=n.def),n.msg=e,n.state=2,n.chain.length>0&&r(a,n))}function l(e,n,t,o){for(var i=0;i<n.length;i++)!function(i){e.resolve(n[i]).then((function(e){t(i,e)}),o)}(i)}function f(e){this.def=e,this.triggered=!1}function h(e){this.promise=e,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function p(e){if("function"!=typeof e)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var n=new h(this);this.then=function(e,t){var o={success:"function"!=typeof e||e,failure:"function"==typeof t&&t};return o.promise=new this.constructor((function(e,n){if("function"!=typeof e||"function"!=typeof n)throw TypeError("Not a function");o.resolve=e,o.reject=n})),n.chain.push(o),0!==n.state&&r(a,n),o.promise},this.catch=function(e){return this.then(void 0,e)};try{e.call(void 0,(function(e){d.call(n,e)}),(function(e){u.call(n,e)}))}catch(e){u.call(n,e)}}t=function(){var e,t,o;function i(e,n){this.fn=e,this.self=n,this.next=void 0}return{add:function(n,r){o=new i(n,r),t?t.next=o:e=o,t=o,o=void 0},drain:function(){var o=e;for(e=t=n=void 0;o;)o.fn.call(o.self),o=o.next}}}();var y=e({},"constructor",p,!1);return p.prototype=y,e(y,"__NPO__",0,!1),e(p,"resolve",(function(e){return e&&"object"==typeof e&&1===e.__NPO__?e:new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");n(e)}))})),e(p,"reject",(function(e){return new this((function(n,t){if("function"!=typeof n||"function"!=typeof t)throw TypeError("Not a function");t(e)}))})),e(p,"all",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):0===e.length?n.resolve([]):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");var i=e.length,r=Array(i),s=0;l(n,e,(function(e,n){r[e]=n,++s===i&&t(r)}),o)}))})),e(p,"race",(function(e){var n=this;return"[object Array]"!=o.call(e)?n.reject(TypeError("Not an array")):new n((function(t,o){if("function"!=typeof t||"function"!=typeof o)throw TypeError("Not a function");l(n,e,(function(e,n){t(n)}),o)}))})),p},(o=n)[t="Promise"]=o[t]||i(),e.exports&&(e.exports=o[t])}));var t="0.5.1";let o,i;!function(e){e.SessionNotFound="SessionNotFound",e.SessionLoaded="SessionLoaded",e.SessionUpdated="SessionUpdated",e.SessionCancel="SessionCancel",e.SessionPaymentOnHold="SessionPaymentOnHold",e.SessionPaymentAuthorized="SessionPaymentAuthorized",e.SessionPaymentError="SessionPaymentError",e.SessionLocked="SessionLocked",e.SessionLockFailed="SessionLockFailed",e.ActivePaymentProductType="ActivePaymentProductType",e.ValidateSession="ValidateSession"}(o||(o={})),function(e){e.HeightChanged="HeightChanged",e.LanguageChanged="LanguageChanged",e.ScrollToTop="ScrollToTop"}(i||(i={}));const r=e=>{window.location.assign(e)},s=e=>{const{sid:n,endpoint:o,language:i,ui:r,shouldCallValidateSession:s}=e;if(!o)throw new Error("Invalid endpoint");const a=[i?`language=${i}`:"",r?`ui=${r}`:"",`sdk=${t}`,s?"client_side_validation=true":void 0].filter((e=>e)).join("&");return`${o}/v1/view/${n}${a?"?"+a:""}`},a=e=>{const{sid:n,endpoint:t,handler:o,eventTypes:i,checkout:r}=e,s=e=>{const s=e.origin===t,a=e.source===r.iframe.contentWindow,c=e.data&&e.data.sid===n,d=-1!==i.indexOf(e.data&&e.data.type);s&&a&&c&&d&&(((e,n)=>{n.data.mid&&e.contentWindow&&e.contentWindow.postMessage({ack:n.data.mid},n.origin||"*")})(r.iframe,e),o(e.data,r))};window.addEventListener("message",s,!1);return{unsubscribe:()=>{window.removeEventListener("message",s,!1)}}},c=e=>{e.href&&r(e.href)},d=(e,n)=>{(e.height||0===e.height)&&n.iframe.setAttribute("style",`width:100%; height:${e.height}px;`)},u=(e,n)=>{try{n.iframe.scrollIntoView({block:"start",behavior:"smooth"})}catch(e){console.error(e)}},l=(e,n)=>{e.language&&(n.language=e.language)},f=(e,n,i)=>(e,r)=>{const s=["sid","merchant_reference","transaction_id","error"].map((n=>[n,e[n]]));e.type!==o.SessionCancel||e.error||s.push(["error","cancelled"]),s.push(["language",r.language]),s.push(["sdk",t]);const a=s.filter((([e,n])=>n)).map((([e,n])=>`${e}=${n}`)).join("&");r.iframe.setAttribute("src",`${n}/embedResult/?${a}`),i(e,r)};e.embed=async e=>{const{container:n,sid:t,language:r,endpoint:h="https://checkout.dintero.com",onSession:p,onSessionCancel:y,onPayment:g,onPaymentAuthorized:m,onPaymentError:v,onSessionNotFound:w,onSessionLocked:S,onSessionLockFailed:T,onActivePaymentType:b,onValidateSession:P}=e;let E;const _=[],{iframe:k,initiate:A}=((e,n,t)=>{if(!e||!e.appendChild)throw new Error("Invalid container");const o=document.createElement("iframe");return o.setAttribute("frameborder","0"),o.setAttribute("allowTransparency","true"),o.setAttribute("style","width:100%; height:0;"),o.setAttribute("sandbox","allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"),o.setAttribute("importance","high"),o.setAttribute("src",t),{iframe:o,initiate:async()=>new Promise(((n,t)=>{o.onload=()=>n(),o.onerror=()=>t(),e.appendChild(o)}))}})(n,0,s({sid:t,endpoint:h,language:r,ui:"inline",shouldCallValidateSession:void 0!==P})),j=(e,n,o)=>{if(!E)throw new Error("Unable to create action promise: checkout is undefined");return new Promise(((i,r)=>{const s=[];s.push(a({sid:t,endpoint:h,handler:e=>{s.forEach((e=>e.unsubscribe())),i(e)},eventTypes:[n],checkout:E})),s.push(a({sid:t,endpoint:h,handler:()=>{s.forEach((e=>e.unsubscribe())),r(`Received unexpected event: ${o}`)},eventTypes:[o],checkout:E})),e()}))},L=()=>j((()=>{((e,n)=>{e.contentWindow&&e.contentWindow.postMessage({type:"RefreshSession",sid:n},"*")})(k,t)}),o.SessionUpdated,o.SessionNotFound),N=e=>{((e,n,t)=>{e.contentWindow&&e.contentWindow.postMessage({type:"ValidationResult",sid:n,...t},"*")})(k,t,e)};return E={destroy:()=>{k&&(_.forEach((e=>e.unsubscribe())),k.parentElement&&n.removeChild(k))},iframe:k,language:r,lockSession:()=>j((()=>{((e,n)=>{e.contentWindow&&e.contentWindow.postMessage({type:"LockSession",sid:n},"*")})(k,t)}),o.SessionLocked,o.SessionLockFailed),refreshSession:L,setActivePaymentProductType:e=>{((e,n,t)=>{e.contentWindow&&e.contentWindow.postMessage({type:"SetActivePaymentProductType",sid:n,payment_product_type:t},"*")})(k,t,e)},submitValidationResult:N},[{handler:l,eventTypes:[i.LanguageChanged]},{handler:d,eventTypes:[i.HeightChanged]},{handler:u,eventTypes:[i.ScrollToTop]},{handler:p,eventTypes:[o.SessionLoaded,o.SessionUpdated]},{eventTypes:[o.SessionPaymentOnHold],handler:g?f(0,h,g):c},{eventTypes:[o.SessionPaymentAuthorized],handler:m||g?f(0,h,m||g):c},{handler:y?f(0,h,y):c,eventTypes:[o.SessionCancel]},{handler:v?f(0,h,v):c,eventTypes:[o.SessionPaymentError]},{handler:w,eventTypes:[o.SessionNotFound]},{handler:(e,n)=>{S&&S(e,n,L)},eventTypes:[o.SessionLocked]},{handler:T,eventTypes:[o.SessionLockFailed]},{handler:b,eventTypes:[o.ActivePaymentProductType]},{handler:b,eventTypes:[o.ActivePaymentProductType]},{handler:(e,n)=>{P&&P(e,n,N)},eventTypes:[o.ValidateSession]}].forEach((({handler:e,eventTypes:n})=>{e&&_.push(a({sid:t,endpoint:h,handler:e,eventTypes:n,checkout:E}))})),await A(),E},e.redirect=e=>{const{sid:n,language:t,endpoint:o="https://checkout.dintero.com"}=e;r(s({sid:n,endpoint:o,language:t,shouldCallValidateSession:!1}))},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
7
7
|
//# sourceMappingURL=dintero-checkout-web-sdk.umd.min.js.map
|