@dintero/checkout-web-sdk 0.0.16 → 0.3.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/dependabot.yml +10 -0
- package/.github/workflows/{blank.yml → build.yml} +6 -5
- package/.github/workflows/release.yml +33 -0
- package/.releaserc.json +11 -0
- package/CHANGELOG.md +7 -0
- package/README.md +85 -17
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/base.css +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/block-navigation.js +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/checkout.ts.html +75 -6
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/createIframeAsync.ts.html +15 -15
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/favicon.png +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/index.html +40 -40
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7)/html/checkout-web-sdk.ts.html → Chrome Headless 99.0.4844.0 (Linux x86_64)/html/index.ts.html } +227 -32
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/prettify.css +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/prettify.js +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/sort-arrow-sprite.png +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/sorter.js +0 -0
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/subscribe.ts.html +92 -26
- package/coverage/{Chrome Headless 80.0.3987.0 (Mac OS 10.15.7) → Chrome Headless 99.0.4844.0 (Linux x86_64)}/html/url.ts.html +23 -17
- package/dist/declarations/src/checkout.d.ts +75 -57
- package/dist/declarations/src/createIframeAsync.d.ts +10 -10
- package/dist/declarations/src/index.d.ts +43 -39
- package/dist/declarations/src/subscribe.d.ts +41 -33
- package/dist/declarations/src/url.d.ts +16 -15
- package/dist/dintero-checkout-web-sdk.cjs.dev.js +84 -16
- package/dist/dintero-checkout-web-sdk.cjs.prod.js +84 -16
- package/dist/dintero-checkout-web-sdk.esm.js +84 -16
- 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 +49 -46
- package/coverage/Chrome Headless 80.0.3987.0 (Mac OS 10.15.7)/html/dintero-checkout-web-sdk.ts.html +0 -908
- package/coverage/Chrome Headless 80.0.3987.0 (Mac OS 10.15.7)/html/index.ts.html +0 -908
- package/dist/declarations/package.d.ts +0 -49
|
@@ -1,33 +1,41 @@
|
|
|
1
|
-
import { CheckoutEvents, InternalCheckoutEvents, SessionEvent } from "./checkout";
|
|
2
|
-
import { DinteroCheckoutInstance } from ".";
|
|
3
|
-
/**
|
|
4
|
-
* Unsubscribe handler from event(s).
|
|
5
|
-
*/
|
|
6
|
-
export declare type SubscriptionHandler = (sessionEvent: SessionEvent, checkout: DinteroCheckoutInstance) => void;
|
|
7
|
-
interface SubscriptionOptions {
|
|
8
|
-
sid: string;
|
|
9
|
-
endpoint: string;
|
|
10
|
-
handler: SubscriptionHandler;
|
|
11
|
-
eventTypes: (CheckoutEvents | InternalCheckoutEvents)[];
|
|
12
|
-
checkout: DinteroCheckoutInstance;
|
|
13
|
-
}
|
|
14
|
-
export declare type Subscription = {
|
|
15
|
-
/**
|
|
16
|
-
* Unsubscribe handler from event(s).
|
|
17
|
-
*/
|
|
18
|
-
unsubscribe: () => void;
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Post a SessionLock-event to the checkout iframe.
|
|
22
|
-
*/
|
|
23
|
-
export declare const postSessionLock: (iframe: HTMLIFrameElement, sid: string) => void;
|
|
24
|
-
/**
|
|
25
|
-
* Post
|
|
26
|
-
*/
|
|
27
|
-
export declare const
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { CheckoutEvents, InternalCheckoutEvents, SessionEvent, SessionValidationCallback } from "./checkout";
|
|
2
|
+
import { DinteroCheckoutInstance } from ".";
|
|
3
|
+
/**
|
|
4
|
+
* Unsubscribe handler from event(s).
|
|
5
|
+
*/
|
|
6
|
+
export declare type SubscriptionHandler = (sessionEvent: SessionEvent, checkout: DinteroCheckoutInstance) => void;
|
|
7
|
+
interface SubscriptionOptions {
|
|
8
|
+
sid: string;
|
|
9
|
+
endpoint: string;
|
|
10
|
+
handler: SubscriptionHandler;
|
|
11
|
+
eventTypes: (CheckoutEvents | InternalCheckoutEvents)[];
|
|
12
|
+
checkout: DinteroCheckoutInstance;
|
|
13
|
+
}
|
|
14
|
+
export declare type Subscription = {
|
|
15
|
+
/**
|
|
16
|
+
* Unsubscribe handler from event(s).
|
|
17
|
+
*/
|
|
18
|
+
unsubscribe: () => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Post a SessionLock-event to the checkout iframe.
|
|
22
|
+
*/
|
|
23
|
+
export declare const postSessionLock: (iframe: HTMLIFrameElement, sid: string) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Post the validation result to the checkout iframe
|
|
26
|
+
*/
|
|
27
|
+
export declare const postValidationResult: (iframe: HTMLIFrameElement, sid: string, result: SessionValidationCallback) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Post RefreshSession-event to the checkout iframe.
|
|
30
|
+
*/
|
|
31
|
+
export declare const postSessionRefresh: (iframe: HTMLIFrameElement, sid: string) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Post setActivePaymentProductType-event to the checkout iframe.
|
|
34
|
+
*/
|
|
35
|
+
export declare const postActivePaymentProductType: (iframe: HTMLIFrameElement, sid: string, paymentProductType?: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to events from an iframe given a handler and a set
|
|
38
|
+
* of event types.
|
|
39
|
+
*/
|
|
40
|
+
export declare const subscribe: (options: SubscriptionOptions) => Subscription;
|
|
41
|
+
export {};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps window.location.assign()
|
|
3
|
-
*/
|
|
4
|
-
export declare const windowLocationAssign: (url: string) => void;
|
|
5
|
-
/**
|
|
6
|
-
* Get the url for the session./yarn-error.log
|
|
7
|
-
.DS_Store
|
|
8
|
-
*/
|
|
9
|
-
export interface SessionUrlOptions {
|
|
10
|
-
sid: string;
|
|
11
|
-
endpoint: string;
|
|
12
|
-
language: string | undefined;
|
|
13
|
-
ui?: "fullscreen" | "inline";
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Wraps window.location.assign()
|
|
3
|
+
*/
|
|
4
|
+
export declare const windowLocationAssign: (url: string) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Get the url for the session./yarn-error.log
|
|
7
|
+
.DS_Store
|
|
8
|
+
*/
|
|
9
|
+
export interface SessionUrlOptions {
|
|
10
|
+
sid: string;
|
|
11
|
+
endpoint: string;
|
|
12
|
+
language: string | undefined;
|
|
13
|
+
ui?: "fullscreen" | "inline";
|
|
14
|
+
shouldCallValidateSession: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const getSessionUrl: (options: SessionUrlOptions) => string;
|
|
@@ -6,7 +6,7 @@ require('native-promise-only');
|
|
|
6
6
|
|
|
7
7
|
var pkg = {
|
|
8
8
|
name: "@dintero/checkout-web-sdk",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.3.1",
|
|
10
10
|
description: "Dintero Checkout SDK for web frontends",
|
|
11
11
|
main: "dist/dintero-checkout-web-sdk.cjs.js",
|
|
12
12
|
module: "dist/dintero-checkout-web-sdk.esm.js",
|
|
@@ -18,12 +18,14 @@ var pkg = {
|
|
|
18
18
|
},
|
|
19
19
|
scripts: {
|
|
20
20
|
build: "preconstruct build",
|
|
21
|
-
test: "karma start"
|
|
21
|
+
test: "karma start",
|
|
22
|
+
"semantic-release": "semantic-release",
|
|
23
|
+
prepublishOnly: "npm run build"
|
|
22
24
|
},
|
|
23
25
|
"private": false,
|
|
24
26
|
repository: {
|
|
25
27
|
type: "git",
|
|
26
|
-
url: "
|
|
28
|
+
url: "https://github.com/Dintero/Dintero.Checkout.Web.SDK.git"
|
|
27
29
|
},
|
|
28
30
|
homepage: "https://github.com/Dintero/Dintero.Checkout.Web.SDK#readme",
|
|
29
31
|
author: "Sven Nicolai Viig <sven@dintero.com> (http://dintero.com)",
|
|
@@ -34,18 +36,19 @@ var pkg = {
|
|
|
34
36
|
devDependencies: {
|
|
35
37
|
"@babel/preset-env": "^7.14.1",
|
|
36
38
|
"@babel/preset-typescript": "^7.13.0",
|
|
37
|
-
"@preconstruct/cli": "^2.1.
|
|
39
|
+
"@preconstruct/cli": "^2.1.5",
|
|
40
|
+
"@semantic-release/git": "^10.0.1",
|
|
38
41
|
chai: "^4.2.0",
|
|
39
|
-
karma: "^
|
|
42
|
+
karma: "^6.3.14",
|
|
40
43
|
"karma-chai": "^0.1.0",
|
|
41
44
|
"karma-chrome-launcher": "^3.1.0",
|
|
42
45
|
"karma-mocha": "^2.0.1",
|
|
43
46
|
"karma-typescript": "^5.0.3",
|
|
44
47
|
mocha: "^8.1.1",
|
|
45
48
|
prettier: "^1.19.1",
|
|
46
|
-
puppeteer: "^
|
|
47
|
-
|
|
48
|
-
sinon: "^
|
|
49
|
+
puppeteer: "^13.3.2",
|
|
50
|
+
"semantic-release": "^19.0.2",
|
|
51
|
+
sinon: "^13.0.1",
|
|
49
52
|
typescript: "^4.2.4"
|
|
50
53
|
},
|
|
51
54
|
dependencies: {
|
|
@@ -65,6 +68,8 @@ let CheckoutEvents;
|
|
|
65
68
|
CheckoutEvents["SessionPaymentError"] = "SessionPaymentError";
|
|
66
69
|
CheckoutEvents["SessionLocked"] = "SessionLocked";
|
|
67
70
|
CheckoutEvents["SessionLockFailed"] = "SessionLockFailed";
|
|
71
|
+
CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
|
|
72
|
+
CheckoutEvents["ValidateSession"] = "ValidateSession";
|
|
68
73
|
})(CheckoutEvents || (CheckoutEvents = {}));
|
|
69
74
|
|
|
70
75
|
let InternalCheckoutEvents;
|
|
@@ -91,7 +96,8 @@ const getSessionUrl = options => {
|
|
|
91
96
|
sid,
|
|
92
97
|
endpoint,
|
|
93
98
|
language,
|
|
94
|
-
ui
|
|
99
|
+
ui,
|
|
100
|
+
shouldCallValidateSession
|
|
95
101
|
} = options;
|
|
96
102
|
|
|
97
103
|
if (!endpoint) {
|
|
@@ -102,7 +108,8 @@ const getSessionUrl = options => {
|
|
|
102
108
|
let languageParam = language ? `language=${language}` : "";
|
|
103
109
|
let uiParam = ui ? `ui=${ui}` : "";
|
|
104
110
|
let sdk = `sdk=${pkg.version}`;
|
|
105
|
-
|
|
111
|
+
let validate = shouldCallValidateSession ? `client_side_validation=true` : undefined;
|
|
112
|
+
const params = [languageParam, uiParam, sdk, validate].filter(x => x).join("&");
|
|
106
113
|
return `${endpoint}/v1/view/${sid}${params ? "?" + params : ""}`;
|
|
107
114
|
};
|
|
108
115
|
|
|
@@ -181,6 +188,19 @@ const postSessionLock = (iframe, sid) => {
|
|
|
181
188
|
}, "*");
|
|
182
189
|
}
|
|
183
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* Post the validation result to the checkout iframe
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
const postValidationResult = (iframe, sid, result) => {
|
|
196
|
+
if (iframe.contentWindow) {
|
|
197
|
+
iframe.contentWindow.postMessage({
|
|
198
|
+
type: "ValidationResult",
|
|
199
|
+
sid,
|
|
200
|
+
...result
|
|
201
|
+
}, "*");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
184
204
|
/**
|
|
185
205
|
* Post RefreshSession-event to the checkout iframe.
|
|
186
206
|
*/
|
|
@@ -193,6 +213,19 @@ const postSessionRefresh = (iframe, sid) => {
|
|
|
193
213
|
}, "*");
|
|
194
214
|
}
|
|
195
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* Post setActivePaymentProductType-event to the checkout iframe.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
221
|
+
if (iframe.contentWindow) {
|
|
222
|
+
iframe.contentWindow.postMessage({
|
|
223
|
+
type: "SetActivePaymentProductType",
|
|
224
|
+
sid,
|
|
225
|
+
payment_product_type: paymentProductType
|
|
226
|
+
}, "*");
|
|
227
|
+
}
|
|
228
|
+
};
|
|
196
229
|
/**
|
|
197
230
|
* Subscribe to events from an iframe given a handler and a set
|
|
198
231
|
* of event types.
|
|
@@ -292,18 +325,21 @@ const embed = async options => {
|
|
|
292
325
|
onPaymentError,
|
|
293
326
|
onSessionNotFound,
|
|
294
327
|
onSessionLocked,
|
|
295
|
-
onSessionLockFailed
|
|
328
|
+
onSessionLockFailed,
|
|
329
|
+
onActivePaymentType,
|
|
330
|
+
onValidateSession
|
|
296
331
|
} = options;
|
|
297
332
|
const subscriptions = []; // Create iframe
|
|
298
333
|
|
|
299
334
|
const {
|
|
300
335
|
iframe,
|
|
301
336
|
initiate
|
|
302
|
-
} =
|
|
337
|
+
} = createIframeAsync(container, endpoint, getSessionUrl({
|
|
303
338
|
sid,
|
|
304
339
|
endpoint,
|
|
305
340
|
language,
|
|
306
|
-
ui: "inline"
|
|
341
|
+
ui: "inline",
|
|
342
|
+
shouldCallValidateSession: onValidateSession !== undefined
|
|
307
343
|
}));
|
|
308
344
|
/**
|
|
309
345
|
* Function that removes the iframe and all event listeners.
|
|
@@ -325,6 +361,26 @@ const embed = async options => {
|
|
|
325
361
|
|
|
326
362
|
const refreshSession = () => {
|
|
327
363
|
postSessionRefresh(iframe, sid);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const setActivePaymentProductType = paymentProductType => {
|
|
367
|
+
postActivePaymentProductType(iframe, sid, paymentProductType);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const submitValidationResult = result => {
|
|
371
|
+
postValidationResult(iframe, sid, result);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const wrappedOnValidateSession = (event, checkout) => {
|
|
375
|
+
if (onValidateSession) {
|
|
376
|
+
onValidateSession(event, checkout, submitValidationResult);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const wrappedOnSessionLocked = (event, checkout) => {
|
|
381
|
+
if (onSessionLocked) {
|
|
382
|
+
onSessionLocked(event, checkout, refreshSession);
|
|
383
|
+
}
|
|
328
384
|
}; // Create checkout object that wraps the destroy function.
|
|
329
385
|
|
|
330
386
|
|
|
@@ -333,7 +389,9 @@ const embed = async options => {
|
|
|
333
389
|
iframe,
|
|
334
390
|
language,
|
|
335
391
|
lockSession,
|
|
336
|
-
refreshSession
|
|
392
|
+
refreshSession,
|
|
393
|
+
setActivePaymentProductType,
|
|
394
|
+
submitValidationResult
|
|
337
395
|
}; // Add event handlers (or in some cases add a fallback href handler).
|
|
338
396
|
|
|
339
397
|
[{
|
|
@@ -361,11 +419,20 @@ const embed = async options => {
|
|
|
361
419
|
handler: onSessionNotFound,
|
|
362
420
|
eventTypes: [CheckoutEvents.SessionNotFound]
|
|
363
421
|
}, {
|
|
364
|
-
handler:
|
|
422
|
+
handler: wrappedOnSessionLocked,
|
|
365
423
|
eventTypes: [CheckoutEvents.SessionLocked]
|
|
366
424
|
}, {
|
|
367
425
|
handler: onSessionLockFailed,
|
|
368
426
|
eventTypes: [CheckoutEvents.SessionLockFailed]
|
|
427
|
+
}, {
|
|
428
|
+
handler: onActivePaymentType,
|
|
429
|
+
eventTypes: [CheckoutEvents.ActivePaymentProductType]
|
|
430
|
+
}, {
|
|
431
|
+
handler: onActivePaymentType,
|
|
432
|
+
eventTypes: [CheckoutEvents.ActivePaymentProductType]
|
|
433
|
+
}, {
|
|
434
|
+
handler: wrappedOnValidateSession,
|
|
435
|
+
eventTypes: [CheckoutEvents.ValidateSession]
|
|
369
436
|
}].forEach(({
|
|
370
437
|
handler,
|
|
371
438
|
eventTypes
|
|
@@ -399,7 +466,8 @@ const redirect = options => {
|
|
|
399
466
|
windowLocationAssign(getSessionUrl({
|
|
400
467
|
sid,
|
|
401
468
|
endpoint,
|
|
402
|
-
language
|
|
469
|
+
language,
|
|
470
|
+
shouldCallValidateSession: false
|
|
403
471
|
}));
|
|
404
472
|
};
|
|
405
473
|
|
|
@@ -6,7 +6,7 @@ require('native-promise-only');
|
|
|
6
6
|
|
|
7
7
|
var pkg = {
|
|
8
8
|
name: "@dintero/checkout-web-sdk",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.3.1",
|
|
10
10
|
description: "Dintero Checkout SDK for web frontends",
|
|
11
11
|
main: "dist/dintero-checkout-web-sdk.cjs.js",
|
|
12
12
|
module: "dist/dintero-checkout-web-sdk.esm.js",
|
|
@@ -18,12 +18,14 @@ var pkg = {
|
|
|
18
18
|
},
|
|
19
19
|
scripts: {
|
|
20
20
|
build: "preconstruct build",
|
|
21
|
-
test: "karma start"
|
|
21
|
+
test: "karma start",
|
|
22
|
+
"semantic-release": "semantic-release",
|
|
23
|
+
prepublishOnly: "npm run build"
|
|
22
24
|
},
|
|
23
25
|
"private": false,
|
|
24
26
|
repository: {
|
|
25
27
|
type: "git",
|
|
26
|
-
url: "
|
|
28
|
+
url: "https://github.com/Dintero/Dintero.Checkout.Web.SDK.git"
|
|
27
29
|
},
|
|
28
30
|
homepage: "https://github.com/Dintero/Dintero.Checkout.Web.SDK#readme",
|
|
29
31
|
author: "Sven Nicolai Viig <sven@dintero.com> (http://dintero.com)",
|
|
@@ -34,18 +36,19 @@ var pkg = {
|
|
|
34
36
|
devDependencies: {
|
|
35
37
|
"@babel/preset-env": "^7.14.1",
|
|
36
38
|
"@babel/preset-typescript": "^7.13.0",
|
|
37
|
-
"@preconstruct/cli": "^2.1.
|
|
39
|
+
"@preconstruct/cli": "^2.1.5",
|
|
40
|
+
"@semantic-release/git": "^10.0.1",
|
|
38
41
|
chai: "^4.2.0",
|
|
39
|
-
karma: "^
|
|
42
|
+
karma: "^6.3.14",
|
|
40
43
|
"karma-chai": "^0.1.0",
|
|
41
44
|
"karma-chrome-launcher": "^3.1.0",
|
|
42
45
|
"karma-mocha": "^2.0.1",
|
|
43
46
|
"karma-typescript": "^5.0.3",
|
|
44
47
|
mocha: "^8.1.1",
|
|
45
48
|
prettier: "^1.19.1",
|
|
46
|
-
puppeteer: "^
|
|
47
|
-
|
|
48
|
-
sinon: "^
|
|
49
|
+
puppeteer: "^13.3.2",
|
|
50
|
+
"semantic-release": "^19.0.2",
|
|
51
|
+
sinon: "^13.0.1",
|
|
49
52
|
typescript: "^4.2.4"
|
|
50
53
|
},
|
|
51
54
|
dependencies: {
|
|
@@ -65,6 +68,8 @@ let CheckoutEvents;
|
|
|
65
68
|
CheckoutEvents["SessionPaymentError"] = "SessionPaymentError";
|
|
66
69
|
CheckoutEvents["SessionLocked"] = "SessionLocked";
|
|
67
70
|
CheckoutEvents["SessionLockFailed"] = "SessionLockFailed";
|
|
71
|
+
CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
|
|
72
|
+
CheckoutEvents["ValidateSession"] = "ValidateSession";
|
|
68
73
|
})(CheckoutEvents || (CheckoutEvents = {}));
|
|
69
74
|
|
|
70
75
|
let InternalCheckoutEvents;
|
|
@@ -91,7 +96,8 @@ const getSessionUrl = options => {
|
|
|
91
96
|
sid,
|
|
92
97
|
endpoint,
|
|
93
98
|
language,
|
|
94
|
-
ui
|
|
99
|
+
ui,
|
|
100
|
+
shouldCallValidateSession
|
|
95
101
|
} = options;
|
|
96
102
|
|
|
97
103
|
if (!endpoint) {
|
|
@@ -102,7 +108,8 @@ const getSessionUrl = options => {
|
|
|
102
108
|
let languageParam = language ? `language=${language}` : "";
|
|
103
109
|
let uiParam = ui ? `ui=${ui}` : "";
|
|
104
110
|
let sdk = `sdk=${pkg.version}`;
|
|
105
|
-
|
|
111
|
+
let validate = shouldCallValidateSession ? `client_side_validation=true` : undefined;
|
|
112
|
+
const params = [languageParam, uiParam, sdk, validate].filter(x => x).join("&");
|
|
106
113
|
return `${endpoint}/v1/view/${sid}${params ? "?" + params : ""}`;
|
|
107
114
|
};
|
|
108
115
|
|
|
@@ -181,6 +188,19 @@ const postSessionLock = (iframe, sid) => {
|
|
|
181
188
|
}, "*");
|
|
182
189
|
}
|
|
183
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* Post the validation result to the checkout iframe
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
const postValidationResult = (iframe, sid, result) => {
|
|
196
|
+
if (iframe.contentWindow) {
|
|
197
|
+
iframe.contentWindow.postMessage({
|
|
198
|
+
type: "ValidationResult",
|
|
199
|
+
sid,
|
|
200
|
+
...result
|
|
201
|
+
}, "*");
|
|
202
|
+
}
|
|
203
|
+
};
|
|
184
204
|
/**
|
|
185
205
|
* Post RefreshSession-event to the checkout iframe.
|
|
186
206
|
*/
|
|
@@ -193,6 +213,19 @@ const postSessionRefresh = (iframe, sid) => {
|
|
|
193
213
|
}, "*");
|
|
194
214
|
}
|
|
195
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* Post setActivePaymentProductType-event to the checkout iframe.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
221
|
+
if (iframe.contentWindow) {
|
|
222
|
+
iframe.contentWindow.postMessage({
|
|
223
|
+
type: "SetActivePaymentProductType",
|
|
224
|
+
sid,
|
|
225
|
+
payment_product_type: paymentProductType
|
|
226
|
+
}, "*");
|
|
227
|
+
}
|
|
228
|
+
};
|
|
196
229
|
/**
|
|
197
230
|
* Subscribe to events from an iframe given a handler and a set
|
|
198
231
|
* of event types.
|
|
@@ -292,18 +325,21 @@ const embed = async options => {
|
|
|
292
325
|
onPaymentError,
|
|
293
326
|
onSessionNotFound,
|
|
294
327
|
onSessionLocked,
|
|
295
|
-
onSessionLockFailed
|
|
328
|
+
onSessionLockFailed,
|
|
329
|
+
onActivePaymentType,
|
|
330
|
+
onValidateSession
|
|
296
331
|
} = options;
|
|
297
332
|
const subscriptions = []; // Create iframe
|
|
298
333
|
|
|
299
334
|
const {
|
|
300
335
|
iframe,
|
|
301
336
|
initiate
|
|
302
|
-
} =
|
|
337
|
+
} = createIframeAsync(container, endpoint, getSessionUrl({
|
|
303
338
|
sid,
|
|
304
339
|
endpoint,
|
|
305
340
|
language,
|
|
306
|
-
ui: "inline"
|
|
341
|
+
ui: "inline",
|
|
342
|
+
shouldCallValidateSession: onValidateSession !== undefined
|
|
307
343
|
}));
|
|
308
344
|
/**
|
|
309
345
|
* Function that removes the iframe and all event listeners.
|
|
@@ -325,6 +361,26 @@ const embed = async options => {
|
|
|
325
361
|
|
|
326
362
|
const refreshSession = () => {
|
|
327
363
|
postSessionRefresh(iframe, sid);
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const setActivePaymentProductType = paymentProductType => {
|
|
367
|
+
postActivePaymentProductType(iframe, sid, paymentProductType);
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const submitValidationResult = result => {
|
|
371
|
+
postValidationResult(iframe, sid, result);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
const wrappedOnValidateSession = (event, checkout) => {
|
|
375
|
+
if (onValidateSession) {
|
|
376
|
+
onValidateSession(event, checkout, submitValidationResult);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const wrappedOnSessionLocked = (event, checkout) => {
|
|
381
|
+
if (onSessionLocked) {
|
|
382
|
+
onSessionLocked(event, checkout, refreshSession);
|
|
383
|
+
}
|
|
328
384
|
}; // Create checkout object that wraps the destroy function.
|
|
329
385
|
|
|
330
386
|
|
|
@@ -333,7 +389,9 @@ const embed = async options => {
|
|
|
333
389
|
iframe,
|
|
334
390
|
language,
|
|
335
391
|
lockSession,
|
|
336
|
-
refreshSession
|
|
392
|
+
refreshSession,
|
|
393
|
+
setActivePaymentProductType,
|
|
394
|
+
submitValidationResult
|
|
337
395
|
}; // Add event handlers (or in some cases add a fallback href handler).
|
|
338
396
|
|
|
339
397
|
[{
|
|
@@ -361,11 +419,20 @@ const embed = async options => {
|
|
|
361
419
|
handler: onSessionNotFound,
|
|
362
420
|
eventTypes: [CheckoutEvents.SessionNotFound]
|
|
363
421
|
}, {
|
|
364
|
-
handler:
|
|
422
|
+
handler: wrappedOnSessionLocked,
|
|
365
423
|
eventTypes: [CheckoutEvents.SessionLocked]
|
|
366
424
|
}, {
|
|
367
425
|
handler: onSessionLockFailed,
|
|
368
426
|
eventTypes: [CheckoutEvents.SessionLockFailed]
|
|
427
|
+
}, {
|
|
428
|
+
handler: onActivePaymentType,
|
|
429
|
+
eventTypes: [CheckoutEvents.ActivePaymentProductType]
|
|
430
|
+
}, {
|
|
431
|
+
handler: onActivePaymentType,
|
|
432
|
+
eventTypes: [CheckoutEvents.ActivePaymentProductType]
|
|
433
|
+
}, {
|
|
434
|
+
handler: wrappedOnValidateSession,
|
|
435
|
+
eventTypes: [CheckoutEvents.ValidateSession]
|
|
369
436
|
}].forEach(({
|
|
370
437
|
handler,
|
|
371
438
|
eventTypes
|
|
@@ -399,7 +466,8 @@ const redirect = options => {
|
|
|
399
466
|
windowLocationAssign(getSessionUrl({
|
|
400
467
|
sid,
|
|
401
468
|
endpoint,
|
|
402
|
-
language
|
|
469
|
+
language,
|
|
470
|
+
shouldCallValidateSession: false
|
|
403
471
|
}));
|
|
404
472
|
};
|
|
405
473
|
|