@dintero/checkout-web-sdk 0.5.0 → 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 +6 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/base.css +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/block-navigation.js +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/checkout.ts.html +1 -1
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/createIframeAsync.ts.html +2 -2
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/favicon.png +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/index.html +1 -1
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/index.ts.html +1 -1
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/prettify.css +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/prettify.js +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/sorter.js +0 -0
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/subscribe.ts.html +1 -1
- package/coverage/{Chrome Headless 106.0.5249.0 (Linux x86_64) → Chrome Headless 108.0.5351.0 (Linux x86_64)}/html/url.ts.html +1 -1
- package/dist/dintero-checkout-web-sdk.cjs.dev.js +51 -64
- package/dist/dintero-checkout-web-sdk.cjs.prod.js +51 -64
- package/dist/dintero-checkout-web-sdk.esm.js +51 -64
- 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.
|
|
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,9 +66,7 @@ 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";
|
|
@@ -79,10 +76,10 @@ let InternalCheckoutEvents;
|
|
|
79
76
|
/**
|
|
80
77
|
* Wraps window.location.assign()
|
|
81
78
|
*/
|
|
82
|
-
|
|
83
79
|
const windowLocationAssign = url => {
|
|
84
80
|
window.location.assign(url);
|
|
85
81
|
};
|
|
82
|
+
|
|
86
83
|
/**
|
|
87
84
|
* Get the url for the session./yarn-error.log
|
|
88
85
|
.DS_Store
|
|
@@ -96,12 +93,11 @@ const getSessionUrl = options => {
|
|
|
96
93
|
ui,
|
|
97
94
|
shouldCallValidateSession
|
|
98
95
|
} = options;
|
|
99
|
-
|
|
100
96
|
if (!endpoint) {
|
|
101
97
|
throw new Error("Invalid endpoint");
|
|
102
|
-
}
|
|
103
|
-
|
|
98
|
+
}
|
|
104
99
|
|
|
100
|
+
// Compose url for view session endpoint with optional language parameter.
|
|
105
101
|
let languageParam = language ? `language=${language}` : "";
|
|
106
102
|
let uiParam = ui ? `ui=${ui}` : "";
|
|
107
103
|
let sdk = `sdk=${pkg.version}`;
|
|
@@ -120,12 +116,14 @@ const createIframeAsync = (container, endpoint, url) => {
|
|
|
120
116
|
if (!container || !container.appendChild) {
|
|
121
117
|
throw new Error("Invalid container");
|
|
122
118
|
}
|
|
119
|
+
const iframe = document.createElement("iframe");
|
|
123
120
|
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
// No border, transparent and stretch to 100% of the container width.
|
|
126
122
|
iframe.setAttribute("frameborder", "0");
|
|
127
123
|
iframe.setAttribute("allowTransparency", "true");
|
|
128
|
-
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
|
|
129
127
|
// tests since they will require the csp to be "unsafe-inline".
|
|
130
128
|
// The server needs to add the same property in the Content Security
|
|
131
129
|
// Policy headers in the response for this to work. A CSP header set by
|
|
@@ -133,25 +131,27 @@ const createIframeAsync = (container, endpoint, url) => {
|
|
|
133
131
|
// CSP from the iframe host.
|
|
134
132
|
// Content Security Policy, should be limited to "endpoint".
|
|
135
133
|
// iframe.setAttribute("csp", `default-src ${endpoint}`);
|
|
134
|
+
|
|
136
135
|
// Apply extra restrictions to the content in the iframe.
|
|
137
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");
|
|
138
141
|
|
|
139
|
-
|
|
142
|
+
// Set the iframe source to the url.
|
|
143
|
+
iframe.setAttribute("src", url);
|
|
140
144
|
|
|
141
|
-
|
|
145
|
+
// Resolve or reject promise when iframe loads.
|
|
142
146
|
|
|
143
|
-
iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads.
|
|
144
147
|
// // Add iframe to the container.
|
|
145
148
|
// container.appendChild(iframe);
|
|
146
|
-
|
|
147
149
|
return {
|
|
148
150
|
iframe,
|
|
149
151
|
initiate: async () => {
|
|
150
152
|
return new Promise((resolve, reject) => {
|
|
151
153
|
iframe.onload = () => resolve();
|
|
152
|
-
|
|
153
154
|
iframe.onerror = () => reject();
|
|
154
|
-
|
|
155
155
|
container.appendChild(iframe);
|
|
156
156
|
});
|
|
157
157
|
}
|
|
@@ -172,11 +172,10 @@ const postAck = (iframe, event) => {
|
|
|
172
172
|
}, event.origin || "*");
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
|
+
|
|
175
176
|
/**
|
|
176
177
|
* Post a SessionLock-event to the checkout iframe.
|
|
177
178
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
179
|
const postSessionLock = (iframe, sid) => {
|
|
181
180
|
if (iframe.contentWindow) {
|
|
182
181
|
iframe.contentWindow.postMessage({
|
|
@@ -185,10 +184,10 @@ const postSessionLock = (iframe, sid) => {
|
|
|
185
184
|
}, "*");
|
|
186
185
|
}
|
|
187
186
|
};
|
|
187
|
+
|
|
188
188
|
/**
|
|
189
189
|
* Post the validation result to the checkout iframe
|
|
190
190
|
*/
|
|
191
|
-
|
|
192
191
|
const postValidationResult = (iframe, sid, result) => {
|
|
193
192
|
if (iframe.contentWindow) {
|
|
194
193
|
iframe.contentWindow.postMessage({
|
|
@@ -198,10 +197,10 @@ const postValidationResult = (iframe, sid, result) => {
|
|
|
198
197
|
}, "*");
|
|
199
198
|
}
|
|
200
199
|
};
|
|
200
|
+
|
|
201
201
|
/**
|
|
202
202
|
* Post RefreshSession-event to the checkout iframe.
|
|
203
203
|
*/
|
|
204
|
-
|
|
205
204
|
const postSessionRefresh = (iframe, sid) => {
|
|
206
205
|
if (iframe.contentWindow) {
|
|
207
206
|
iframe.contentWindow.postMessage({
|
|
@@ -210,10 +209,10 @@ const postSessionRefresh = (iframe, sid) => {
|
|
|
210
209
|
}, "*");
|
|
211
210
|
}
|
|
212
211
|
};
|
|
212
|
+
|
|
213
213
|
/**
|
|
214
214
|
* Post setActivePaymentProductType-event to the checkout iframe.
|
|
215
215
|
*/
|
|
216
|
-
|
|
217
216
|
const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
218
217
|
if (iframe.contentWindow) {
|
|
219
218
|
iframe.contentWindow.postMessage({
|
|
@@ -223,11 +222,11 @@ const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
|
223
222
|
}, "*");
|
|
224
223
|
}
|
|
225
224
|
};
|
|
225
|
+
|
|
226
226
|
/**
|
|
227
227
|
* Subscribe to events from an iframe given a handler and a set
|
|
228
228
|
* of event types.
|
|
229
229
|
*/
|
|
230
|
-
|
|
231
230
|
const subscribe = options => {
|
|
232
231
|
const {
|
|
233
232
|
sid,
|
|
@@ -235,29 +234,30 @@ const subscribe = options => {
|
|
|
235
234
|
handler,
|
|
236
235
|
eventTypes,
|
|
237
236
|
checkout
|
|
238
|
-
} = options;
|
|
239
|
-
// filters on event type(s) in the event data.
|
|
237
|
+
} = options;
|
|
240
238
|
|
|
239
|
+
// Wrap event handler in a function that checks for correct origin and
|
|
240
|
+
// filters on event type(s) in the event data.
|
|
241
241
|
const wrappedHandler = event => {
|
|
242
242
|
const correctOrigin = event.origin === endpoint;
|
|
243
243
|
const correctWindow = event.source === checkout.iframe.contentWindow;
|
|
244
244
|
const correctSid = event.data && event.data.sid === sid;
|
|
245
245
|
const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1;
|
|
246
|
-
|
|
247
246
|
if (correctOrigin && correctWindow && correctSid && correctMessageType) {
|
|
248
247
|
postAck(checkout.iframe, event);
|
|
249
248
|
handler(event.data, checkout);
|
|
250
249
|
}
|
|
251
|
-
};
|
|
252
|
-
|
|
250
|
+
};
|
|
253
251
|
|
|
254
|
-
|
|
252
|
+
// Add event listener to the iframe.
|
|
253
|
+
window.addEventListener("message", wrappedHandler, false);
|
|
255
254
|
|
|
255
|
+
// Function to remove the event listener from the iframe.
|
|
256
256
|
const unsubscribe = () => {
|
|
257
257
|
window.removeEventListener("message", wrappedHandler, false);
|
|
258
|
-
};
|
|
259
|
-
|
|
258
|
+
};
|
|
260
259
|
|
|
260
|
+
// Return object with unsubscribe function.
|
|
261
261
|
return {
|
|
262
262
|
unsubscribe
|
|
263
263
|
};
|
|
@@ -271,22 +271,20 @@ const followHref = event => {
|
|
|
271
271
|
windowLocationAssign(event.href);
|
|
272
272
|
}
|
|
273
273
|
};
|
|
274
|
+
|
|
274
275
|
/**
|
|
275
276
|
* An event handler that sets height of the iframe.
|
|
276
277
|
*/
|
|
277
|
-
|
|
278
|
-
|
|
279
278
|
const setIframeHeight = (event, checkout) => {
|
|
280
279
|
if (event.height || event.height === 0) {
|
|
281
280
|
checkout.iframe.setAttribute("style", `width:100%; height:${event.height}px;`);
|
|
282
281
|
}
|
|
283
282
|
};
|
|
283
|
+
|
|
284
284
|
/**
|
|
285
285
|
* An event handler that scrolls to the top of the iframe. This is useful when the user
|
|
286
286
|
* is navigated to another page.
|
|
287
287
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
288
|
const scrollToIframeTop = (event, checkout) => {
|
|
291
289
|
try {
|
|
292
290
|
checkout.iframe.scrollIntoView({
|
|
@@ -298,26 +296,22 @@ const scrollToIframeTop = (event, checkout) => {
|
|
|
298
296
|
console.error(e);
|
|
299
297
|
}
|
|
300
298
|
};
|
|
299
|
+
|
|
301
300
|
/**
|
|
302
301
|
* An event handler that sets language in the iframe.
|
|
303
302
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
303
|
const setLanguage = (event, checkout) => {
|
|
307
304
|
if (event.language) {
|
|
308
305
|
checkout.language = event.language;
|
|
309
306
|
}
|
|
310
307
|
};
|
|
311
|
-
|
|
312
308
|
const handleWithResult = (sid, endpoint, handler) => {
|
|
313
309
|
return (event, checkout) => {
|
|
314
310
|
const eventKeys = ["sid", "merchant_reference", "transaction_id", "error"];
|
|
315
311
|
const pairs = eventKeys.map(key => [key, event[key]]);
|
|
316
|
-
|
|
317
312
|
if (event.type === CheckoutEvents.SessionCancel && !event.error) {
|
|
318
313
|
pairs.push(["error", "cancelled"]);
|
|
319
314
|
}
|
|
320
|
-
|
|
321
315
|
pairs.push(["language", checkout.language]);
|
|
322
316
|
pairs.push(["sdk", pkg.version]);
|
|
323
317
|
const urlQuery = pairs.filter(([key, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
|
|
@@ -325,11 +319,10 @@ const handleWithResult = (sid, endpoint, handler) => {
|
|
|
325
319
|
handler(event, checkout);
|
|
326
320
|
};
|
|
327
321
|
};
|
|
322
|
+
|
|
328
323
|
/**
|
|
329
324
|
* Show a dintero payment session in an embedded iframe.
|
|
330
325
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
333
326
|
const embed = async options => {
|
|
334
327
|
const {
|
|
335
328
|
container,
|
|
@@ -348,8 +341,9 @@ const embed = async options => {
|
|
|
348
341
|
onValidateSession
|
|
349
342
|
} = options;
|
|
350
343
|
let checkout;
|
|
351
|
-
const subscriptions = [];
|
|
344
|
+
const subscriptions = [];
|
|
352
345
|
|
|
346
|
+
// Create iframe
|
|
353
347
|
const {
|
|
354
348
|
iframe,
|
|
355
349
|
initiate
|
|
@@ -360,30 +354,27 @@ const embed = async options => {
|
|
|
360
354
|
ui: "inline",
|
|
361
355
|
shouldCallValidateSession: onValidateSession !== undefined
|
|
362
356
|
}));
|
|
357
|
+
|
|
363
358
|
/**
|
|
364
359
|
* Function that removes the iframe and all event listeners.
|
|
365
360
|
*/
|
|
366
|
-
|
|
367
361
|
const destroy = () => {
|
|
368
362
|
if (iframe) {
|
|
369
363
|
subscriptions.forEach(sub => sub.unsubscribe());
|
|
370
|
-
|
|
371
364
|
if (iframe.parentElement) {
|
|
372
365
|
container.removeChild(iframe);
|
|
373
366
|
}
|
|
374
367
|
}
|
|
375
368
|
};
|
|
369
|
+
|
|
376
370
|
/**
|
|
377
371
|
* Turn an action into a promise by specifying resolve and
|
|
378
372
|
* reject events.
|
|
379
373
|
*/
|
|
380
|
-
|
|
381
|
-
|
|
382
374
|
const promisifyAction = (action, resolveEvent, rejectEvent) => {
|
|
383
375
|
if (!checkout) {
|
|
384
376
|
throw new Error("Unable to create action promise: checkout is undefined");
|
|
385
377
|
}
|
|
386
|
-
|
|
387
378
|
return new Promise((resolve, reject) => {
|
|
388
379
|
const eventSubscriptions = [];
|
|
389
380
|
eventSubscriptions.push(subscribe({
|
|
@@ -409,40 +400,34 @@ const embed = async options => {
|
|
|
409
400
|
action();
|
|
410
401
|
});
|
|
411
402
|
};
|
|
412
|
-
|
|
413
403
|
const lockSession = () => {
|
|
414
404
|
return promisifyAction(() => {
|
|
415
405
|
postSessionLock(iframe, sid);
|
|
416
406
|
}, CheckoutEvents.SessionLocked, CheckoutEvents.SessionLockFailed);
|
|
417
407
|
};
|
|
418
|
-
|
|
419
408
|
const refreshSession = () => {
|
|
420
409
|
return promisifyAction(() => {
|
|
421
410
|
postSessionRefresh(iframe, sid);
|
|
422
411
|
}, CheckoutEvents.SessionUpdated, CheckoutEvents.SessionNotFound);
|
|
423
412
|
};
|
|
424
|
-
|
|
425
413
|
const setActivePaymentProductType = paymentProductType => {
|
|
426
414
|
postActivePaymentProductType(iframe, sid, paymentProductType);
|
|
427
415
|
};
|
|
428
|
-
|
|
429
416
|
const submitValidationResult = result => {
|
|
430
417
|
postValidationResult(iframe, sid, result);
|
|
431
418
|
};
|
|
432
|
-
|
|
433
419
|
const wrappedOnValidateSession = (event, checkout) => {
|
|
434
420
|
if (onValidateSession) {
|
|
435
421
|
onValidateSession(event, checkout, submitValidationResult);
|
|
436
422
|
}
|
|
437
423
|
};
|
|
438
|
-
|
|
439
424
|
const wrappedOnSessionLocked = (event, checkout) => {
|
|
440
425
|
if (onSessionLocked) {
|
|
441
426
|
onSessionLocked(event, checkout, refreshSession);
|
|
442
427
|
}
|
|
443
|
-
};
|
|
444
|
-
|
|
428
|
+
};
|
|
445
429
|
|
|
430
|
+
// Create checkout object that wraps the destroy function.
|
|
446
431
|
checkout = {
|
|
447
432
|
destroy,
|
|
448
433
|
iframe,
|
|
@@ -451,8 +436,9 @@ const embed = async options => {
|
|
|
451
436
|
refreshSession,
|
|
452
437
|
setActivePaymentProductType,
|
|
453
438
|
submitValidationResult
|
|
454
|
-
};
|
|
439
|
+
};
|
|
455
440
|
|
|
441
|
+
// Add event handlers (or in some cases add a fallback href handler).
|
|
456
442
|
[{
|
|
457
443
|
handler: setLanguage,
|
|
458
444
|
eventTypes: [InternalCheckoutEvents.LanguageChanged]
|
|
@@ -508,23 +494,24 @@ const embed = async options => {
|
|
|
508
494
|
checkout
|
|
509
495
|
}));
|
|
510
496
|
}
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
await initiate(); // Return object with function to destroy the checkout.
|
|
497
|
+
});
|
|
514
498
|
|
|
499
|
+
// Add iframe to DOM
|
|
500
|
+
await initiate();
|
|
501
|
+
// Return object with function to destroy the checkout.
|
|
515
502
|
return checkout;
|
|
516
503
|
};
|
|
504
|
+
|
|
517
505
|
/**
|
|
518
506
|
* Redirect the customer to a payment session in the Dintero Checkout.
|
|
519
507
|
*/
|
|
520
|
-
|
|
521
508
|
const redirect = options => {
|
|
522
509
|
const {
|
|
523
510
|
sid,
|
|
524
511
|
language,
|
|
525
512
|
endpoint = "https://checkout.dintero.com"
|
|
526
|
-
} = options;
|
|
527
|
-
|
|
513
|
+
} = options;
|
|
514
|
+
// Redirect the current browser window to the checkout session url.
|
|
528
515
|
windowLocationAssign(getSessionUrl({
|
|
529
516
|
sid,
|
|
530
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.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.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
|