@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
|
@@ -213,7 +213,7 @@
|
|
|
213
213
|
<span class="cline-any cline-neutral"> </span>
|
|
214
214
|
<span class="cline-any cline-neutral"> </span>
|
|
215
215
|
<span class="cline-any cline-yes">1x</span>
|
|
216
|
-
<span class="cline-any cline-yes">
|
|
216
|
+
<span class="cline-any cline-yes">28x</span>
|
|
217
217
|
<span class="cline-any cline-yes">1x</span>
|
|
218
218
|
<span class="cline-any cline-neutral"> </span>
|
|
219
219
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -265,37 +265,37 @@
|
|
|
265
265
|
<span class="cline-any cline-neutral"> </span>
|
|
266
266
|
<span class="cline-any cline-neutral"> </span>
|
|
267
267
|
<span class="cline-any cline-yes">1x</span>
|
|
268
|
-
<span class="cline-any cline-yes">
|
|
268
|
+
<span class="cline-any cline-yes">1490x</span>
|
|
269
269
|
<span class="cline-any cline-neutral"> </span>
|
|
270
270
|
<span class="cline-any cline-neutral"> </span>
|
|
271
271
|
<span class="cline-any cline-neutral"> </span>
|
|
272
|
-
<span class="cline-any cline-yes">
|
|
273
|
-
<span class="cline-any cline-yes">
|
|
274
|
-
<span class="cline-any cline-yes">
|
|
275
|
-
<span class="cline-any cline-yes">
|
|
272
|
+
<span class="cline-any cline-yes">298x</span>
|
|
273
|
+
<span class="cline-any cline-yes">4392x</span>
|
|
274
|
+
<span class="cline-any cline-yes">4392x</span>
|
|
275
|
+
<span class="cline-any cline-yes">4392x</span>
|
|
276
276
|
<span class="cline-any cline-neutral"> </span>
|
|
277
|
-
<span class="cline-any cline-yes">
|
|
278
|
-
<span class="cline-any cline-yes">
|
|
277
|
+
<span class="cline-any cline-yes">4392x</span>
|
|
278
|
+
<span class="cline-any cline-yes">4392x</span>
|
|
279
279
|
<span class="cline-any cline-neutral"> </span>
|
|
280
280
|
<span class="cline-any cline-neutral"> </span>
|
|
281
281
|
<span class="cline-any cline-neutral"> </span>
|
|
282
282
|
<span class="cline-any cline-neutral"> </span>
|
|
283
283
|
<span class="cline-any cline-neutral"> </span>
|
|
284
|
-
<span class="cline-any cline-yes">
|
|
285
|
-
<span class="cline-any cline-yes">
|
|
284
|
+
<span class="cline-any cline-yes">28x</span>
|
|
285
|
+
<span class="cline-any cline-yes">28x</span>
|
|
286
286
|
<span class="cline-any cline-neutral"> </span>
|
|
287
287
|
<span class="cline-any cline-neutral"> </span>
|
|
288
288
|
<span class="cline-any cline-neutral"> </span>
|
|
289
289
|
<span class="cline-any cline-neutral"> </span>
|
|
290
|
-
<span class="cline-any cline-yes">
|
|
290
|
+
<span class="cline-any cline-yes">298x</span>
|
|
291
291
|
<span class="cline-any cline-neutral"> </span>
|
|
292
292
|
<span class="cline-any cline-neutral"> </span>
|
|
293
|
-
<span class="cline-any cline-yes">
|
|
294
|
-
<span class="cline-any cline-yes">
|
|
293
|
+
<span class="cline-any cline-yes">298x</span>
|
|
294
|
+
<span class="cline-any cline-yes">35x</span>
|
|
295
295
|
<span class="cline-any cline-neutral"> </span>
|
|
296
296
|
<span class="cline-any cline-neutral"> </span>
|
|
297
297
|
<span class="cline-any cline-neutral"> </span>
|
|
298
|
-
<span class="cline-any cline-yes">
|
|
298
|
+
<span class="cline-any cline-yes">298x</span>
|
|
299
299
|
<span class="cline-any cline-neutral"> </span>
|
|
300
300
|
<span class="cline-any cline-neutral"> </span>
|
|
301
301
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -427,7 +427,7 @@ export const subscribe = (options: SubscriptionOptions): Subscription => {
|
|
|
427
427
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
428
428
|
Code coverage generated by
|
|
429
429
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
430
|
-
at
|
|
430
|
+
at Sat Nov 12 2022 16:43:31 GMT+0000 (Coordinated Universal Time)
|
|
431
431
|
</div>
|
|
432
432
|
</div>
|
|
433
433
|
<script src="prettify.js"></script>
|
|
@@ -169,7 +169,7 @@ export const getSessionUrl = (options: SessionUrlOptions): string => {
|
|
|
169
169
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
170
170
|
Code coverage generated by
|
|
171
171
|
<a href="https://istanbul.js.org/" target="_blank">istanbul</a>
|
|
172
|
-
at
|
|
172
|
+
at Sat Nov 12 2022 16:43:31 GMT+0000 (Coordinated Universal Time)
|
|
173
173
|
</div>
|
|
174
174
|
</div>
|
|
175
175
|
<script src="prettify.js"></script>
|
|
@@ -14,7 +14,8 @@ export declare enum CheckoutEvents {
|
|
|
14
14
|
}
|
|
15
15
|
export declare enum InternalCheckoutEvents {
|
|
16
16
|
HeightChanged = "HeightChanged",
|
|
17
|
-
LanguageChanged = "LanguageChanged"
|
|
17
|
+
LanguageChanged = "LanguageChanged",
|
|
18
|
+
ScrollToTop = "ScrollToTop"
|
|
18
19
|
}
|
|
19
20
|
export declare type SessionNotFound = {
|
|
20
21
|
type: CheckoutEvents.SessionNotFound;
|
|
@@ -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.5.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",
|
|
@@ -46,7 +46,7 @@ var pkg = {
|
|
|
46
46
|
"karma-typescript": "^5.0.3",
|
|
47
47
|
mocha: "^8.1.1",
|
|
48
48
|
prettier: "^2.6.2",
|
|
49
|
-
puppeteer: "^
|
|
49
|
+
puppeteer: "^19.0.0",
|
|
50
50
|
"semantic-release": "^19.0.2",
|
|
51
51
|
sinon: "^14.0.0",
|
|
52
52
|
typescript: "^4.2.4"
|
|
@@ -57,7 +57,6 @@ var pkg = {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
let CheckoutEvents;
|
|
60
|
-
|
|
61
60
|
(function (CheckoutEvents) {
|
|
62
61
|
CheckoutEvents["SessionNotFound"] = "SessionNotFound";
|
|
63
62
|
CheckoutEvents["SessionLoaded"] = "SessionLoaded";
|
|
@@ -71,21 +70,20 @@ let CheckoutEvents;
|
|
|
71
70
|
CheckoutEvents["ActivePaymentProductType"] = "ActivePaymentProductType";
|
|
72
71
|
CheckoutEvents["ValidateSession"] = "ValidateSession";
|
|
73
72
|
})(CheckoutEvents || (CheckoutEvents = {}));
|
|
74
|
-
|
|
75
73
|
let InternalCheckoutEvents;
|
|
76
|
-
|
|
77
74
|
(function (InternalCheckoutEvents) {
|
|
78
75
|
InternalCheckoutEvents["HeightChanged"] = "HeightChanged";
|
|
79
76
|
InternalCheckoutEvents["LanguageChanged"] = "LanguageChanged";
|
|
77
|
+
InternalCheckoutEvents["ScrollToTop"] = "ScrollToTop";
|
|
80
78
|
})(InternalCheckoutEvents || (InternalCheckoutEvents = {}));
|
|
81
79
|
|
|
82
80
|
/**
|
|
83
81
|
* Wraps window.location.assign()
|
|
84
82
|
*/
|
|
85
|
-
|
|
86
83
|
const windowLocationAssign = url => {
|
|
87
84
|
window.location.assign(url);
|
|
88
85
|
};
|
|
86
|
+
|
|
89
87
|
/**
|
|
90
88
|
* Get the url for the session./yarn-error.log
|
|
91
89
|
.DS_Store
|
|
@@ -99,12 +97,11 @@ const getSessionUrl = options => {
|
|
|
99
97
|
ui,
|
|
100
98
|
shouldCallValidateSession
|
|
101
99
|
} = options;
|
|
102
|
-
|
|
103
100
|
if (!endpoint) {
|
|
104
101
|
throw new Error("Invalid endpoint");
|
|
105
|
-
}
|
|
106
|
-
|
|
102
|
+
}
|
|
107
103
|
|
|
104
|
+
// Compose url for view session endpoint with optional language parameter.
|
|
108
105
|
let languageParam = language ? `language=${language}` : "";
|
|
109
106
|
let uiParam = ui ? `ui=${ui}` : "";
|
|
110
107
|
let sdk = `sdk=${pkg.version}`;
|
|
@@ -123,12 +120,14 @@ const createIframeAsync = (container, endpoint, url) => {
|
|
|
123
120
|
if (!container || !container.appendChild) {
|
|
124
121
|
throw new Error("Invalid container");
|
|
125
122
|
}
|
|
123
|
+
const iframe = document.createElement("iframe");
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
// No border, transparent and stretch to 100% of the container width.
|
|
129
126
|
iframe.setAttribute("frameborder", "0");
|
|
130
127
|
iframe.setAttribute("allowTransparency", "true");
|
|
131
|
-
iframe.setAttribute("style", "width:100%; height:0;");
|
|
128
|
+
iframe.setAttribute("style", "width:100%; height:0;");
|
|
129
|
+
|
|
130
|
+
// TODO: Get this to work as expected, might be tricky with current
|
|
132
131
|
// tests since they will require the csp to be "unsafe-inline".
|
|
133
132
|
// The server needs to add the same property in the Content Security
|
|
134
133
|
// Policy headers in the response for this to work. A CSP header set by
|
|
@@ -136,25 +135,27 @@ const createIframeAsync = (container, endpoint, url) => {
|
|
|
136
135
|
// CSP from the iframe host.
|
|
137
136
|
// Content Security Policy, should be limited to "endpoint".
|
|
138
137
|
// iframe.setAttribute("csp", `default-src ${endpoint}`);
|
|
138
|
+
|
|
139
139
|
// Apply extra restrictions to the content in the iframe.
|
|
140
140
|
// allow popups is needed to open terms in new window
|
|
141
|
+
iframe.setAttribute("sandbox", "allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox");
|
|
142
|
+
|
|
143
|
+
// The download priority of the resource in the <iframe>'s src attribute.
|
|
144
|
+
iframe.setAttribute("importance", "high");
|
|
141
145
|
|
|
142
|
-
|
|
146
|
+
// Set the iframe source to the url.
|
|
147
|
+
iframe.setAttribute("src", url);
|
|
143
148
|
|
|
144
|
-
|
|
149
|
+
// Resolve or reject promise when iframe loads.
|
|
145
150
|
|
|
146
|
-
iframe.setAttribute("src", url); // Resolve or reject promise when iframe loads.
|
|
147
151
|
// // Add iframe to the container.
|
|
148
152
|
// container.appendChild(iframe);
|
|
149
|
-
|
|
150
153
|
return {
|
|
151
154
|
iframe,
|
|
152
155
|
initiate: async () => {
|
|
153
156
|
return new Promise((resolve, reject) => {
|
|
154
157
|
iframe.onload = () => resolve();
|
|
155
|
-
|
|
156
158
|
iframe.onerror = () => reject();
|
|
157
|
-
|
|
158
159
|
container.appendChild(iframe);
|
|
159
160
|
});
|
|
160
161
|
}
|
|
@@ -175,11 +176,10 @@ const postAck = (iframe, event) => {
|
|
|
175
176
|
}, event.origin || "*");
|
|
176
177
|
}
|
|
177
178
|
};
|
|
179
|
+
|
|
178
180
|
/**
|
|
179
181
|
* Post a SessionLock-event to the checkout iframe.
|
|
180
182
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
183
|
const postSessionLock = (iframe, sid) => {
|
|
184
184
|
if (iframe.contentWindow) {
|
|
185
185
|
iframe.contentWindow.postMessage({
|
|
@@ -188,10 +188,10 @@ const postSessionLock = (iframe, sid) => {
|
|
|
188
188
|
}, "*");
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
|
+
|
|
191
192
|
/**
|
|
192
193
|
* Post the validation result to the checkout iframe
|
|
193
194
|
*/
|
|
194
|
-
|
|
195
195
|
const postValidationResult = (iframe, sid, result) => {
|
|
196
196
|
if (iframe.contentWindow) {
|
|
197
197
|
iframe.contentWindow.postMessage({
|
|
@@ -201,10 +201,10 @@ const postValidationResult = (iframe, sid, result) => {
|
|
|
201
201
|
}, "*");
|
|
202
202
|
}
|
|
203
203
|
};
|
|
204
|
+
|
|
204
205
|
/**
|
|
205
206
|
* Post RefreshSession-event to the checkout iframe.
|
|
206
207
|
*/
|
|
207
|
-
|
|
208
208
|
const postSessionRefresh = (iframe, sid) => {
|
|
209
209
|
if (iframe.contentWindow) {
|
|
210
210
|
iframe.contentWindow.postMessage({
|
|
@@ -213,10 +213,10 @@ const postSessionRefresh = (iframe, sid) => {
|
|
|
213
213
|
}, "*");
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
|
+
|
|
216
217
|
/**
|
|
217
218
|
* Post setActivePaymentProductType-event to the checkout iframe.
|
|
218
219
|
*/
|
|
219
|
-
|
|
220
220
|
const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
221
221
|
if (iframe.contentWindow) {
|
|
222
222
|
iframe.contentWindow.postMessage({
|
|
@@ -226,11 +226,11 @@ const postActivePaymentProductType = (iframe, sid, paymentProductType) => {
|
|
|
226
226
|
}, "*");
|
|
227
227
|
}
|
|
228
228
|
};
|
|
229
|
+
|
|
229
230
|
/**
|
|
230
231
|
* Subscribe to events from an iframe given a handler and a set
|
|
231
232
|
* of event types.
|
|
232
233
|
*/
|
|
233
|
-
|
|
234
234
|
const subscribe = options => {
|
|
235
235
|
const {
|
|
236
236
|
sid,
|
|
@@ -238,29 +238,30 @@ const subscribe = options => {
|
|
|
238
238
|
handler,
|
|
239
239
|
eventTypes,
|
|
240
240
|
checkout
|
|
241
|
-
} = options;
|
|
242
|
-
// filters on event type(s) in the event data.
|
|
241
|
+
} = options;
|
|
243
242
|
|
|
243
|
+
// Wrap event handler in a function that checks for correct origin and
|
|
244
|
+
// filters on event type(s) in the event data.
|
|
244
245
|
const wrappedHandler = event => {
|
|
245
246
|
const correctOrigin = event.origin === endpoint;
|
|
246
247
|
const correctWindow = event.source === checkout.iframe.contentWindow;
|
|
247
248
|
const correctSid = event.data && event.data.sid === sid;
|
|
248
249
|
const correctMessageType = eventTypes.indexOf(event.data && event.data.type) !== -1;
|
|
249
|
-
|
|
250
250
|
if (correctOrigin && correctWindow && correctSid && correctMessageType) {
|
|
251
251
|
postAck(checkout.iframe, event);
|
|
252
252
|
handler(event.data, checkout);
|
|
253
253
|
}
|
|
254
|
-
};
|
|
255
|
-
|
|
254
|
+
};
|
|
256
255
|
|
|
257
|
-
|
|
256
|
+
// Add event listener to the iframe.
|
|
257
|
+
window.addEventListener("message", wrappedHandler, false);
|
|
258
258
|
|
|
259
|
+
// Function to remove the event listener from the iframe.
|
|
259
260
|
const unsubscribe = () => {
|
|
260
261
|
window.removeEventListener("message", wrappedHandler, false);
|
|
261
|
-
};
|
|
262
|
-
|
|
262
|
+
};
|
|
263
263
|
|
|
264
|
+
// Return object with unsubscribe function.
|
|
264
265
|
return {
|
|
265
266
|
unsubscribe
|
|
266
267
|
};
|
|
@@ -274,32 +275,47 @@ const followHref = event => {
|
|
|
274
275
|
windowLocationAssign(event.href);
|
|
275
276
|
}
|
|
276
277
|
};
|
|
278
|
+
|
|
277
279
|
/**
|
|
278
280
|
* An event handler that sets height of the iframe.
|
|
279
281
|
*/
|
|
280
|
-
|
|
281
|
-
|
|
282
282
|
const setIframeHeight = (event, checkout) => {
|
|
283
283
|
if (event.height || event.height === 0) {
|
|
284
284
|
checkout.iframe.setAttribute("style", `width:100%; height:${event.height}px;`);
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
287
|
|
|
288
|
+
/**
|
|
289
|
+
* An event handler that scrolls to the top of the iframe. This is useful when the user
|
|
290
|
+
* is navigated to another page.
|
|
291
|
+
*/
|
|
292
|
+
const scrollToIframeTop = (event, checkout) => {
|
|
293
|
+
try {
|
|
294
|
+
checkout.iframe.scrollIntoView({
|
|
295
|
+
block: 'start',
|
|
296
|
+
behavior: 'smooth'
|
|
297
|
+
});
|
|
298
|
+
} catch (e) {
|
|
299
|
+
// Ignore erorr silenty bug log it to the console.
|
|
300
|
+
console.error(e);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* An event handler that sets language in the iframe.
|
|
306
|
+
*/
|
|
288
307
|
const setLanguage = (event, checkout) => {
|
|
289
308
|
if (event.language) {
|
|
290
309
|
checkout.language = event.language;
|
|
291
310
|
}
|
|
292
311
|
};
|
|
293
|
-
|
|
294
312
|
const handleWithResult = (sid, endpoint, handler) => {
|
|
295
313
|
return (event, checkout) => {
|
|
296
314
|
const eventKeys = ["sid", "merchant_reference", "transaction_id", "error"];
|
|
297
315
|
const pairs = eventKeys.map(key => [key, event[key]]);
|
|
298
|
-
|
|
299
316
|
if (event.type === CheckoutEvents.SessionCancel && !event.error) {
|
|
300
317
|
pairs.push(["error", "cancelled"]);
|
|
301
318
|
}
|
|
302
|
-
|
|
303
319
|
pairs.push(["language", checkout.language]);
|
|
304
320
|
pairs.push(["sdk", pkg.version]);
|
|
305
321
|
const urlQuery = pairs.filter(([key, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
|
|
@@ -307,11 +323,10 @@ const handleWithResult = (sid, endpoint, handler) => {
|
|
|
307
323
|
handler(event, checkout);
|
|
308
324
|
};
|
|
309
325
|
};
|
|
326
|
+
|
|
310
327
|
/**
|
|
311
328
|
* Show a dintero payment session in an embedded iframe.
|
|
312
329
|
*/
|
|
313
|
-
|
|
314
|
-
|
|
315
330
|
const embed = async options => {
|
|
316
331
|
const {
|
|
317
332
|
container,
|
|
@@ -330,8 +345,9 @@ const embed = async options => {
|
|
|
330
345
|
onValidateSession
|
|
331
346
|
} = options;
|
|
332
347
|
let checkout;
|
|
333
|
-
const subscriptions = [];
|
|
348
|
+
const subscriptions = [];
|
|
334
349
|
|
|
350
|
+
// Create iframe
|
|
335
351
|
const {
|
|
336
352
|
iframe,
|
|
337
353
|
initiate
|
|
@@ -342,30 +358,27 @@ const embed = async options => {
|
|
|
342
358
|
ui: "inline",
|
|
343
359
|
shouldCallValidateSession: onValidateSession !== undefined
|
|
344
360
|
}));
|
|
361
|
+
|
|
345
362
|
/**
|
|
346
363
|
* Function that removes the iframe and all event listeners.
|
|
347
364
|
*/
|
|
348
|
-
|
|
349
365
|
const destroy = () => {
|
|
350
366
|
if (iframe) {
|
|
351
367
|
subscriptions.forEach(sub => sub.unsubscribe());
|
|
352
|
-
|
|
353
368
|
if (iframe.parentElement) {
|
|
354
369
|
container.removeChild(iframe);
|
|
355
370
|
}
|
|
356
371
|
}
|
|
357
372
|
};
|
|
373
|
+
|
|
358
374
|
/**
|
|
359
375
|
* Turn an action into a promise by specifying resolve and
|
|
360
376
|
* reject events.
|
|
361
377
|
*/
|
|
362
|
-
|
|
363
|
-
|
|
364
378
|
const promisifyAction = (action, resolveEvent, rejectEvent) => {
|
|
365
379
|
if (!checkout) {
|
|
366
380
|
throw new Error("Unable to create action promise: checkout is undefined");
|
|
367
381
|
}
|
|
368
|
-
|
|
369
382
|
return new Promise((resolve, reject) => {
|
|
370
383
|
const eventSubscriptions = [];
|
|
371
384
|
eventSubscriptions.push(subscribe({
|
|
@@ -391,40 +404,34 @@ const embed = async options => {
|
|
|
391
404
|
action();
|
|
392
405
|
});
|
|
393
406
|
};
|
|
394
|
-
|
|
395
407
|
const lockSession = () => {
|
|
396
408
|
return promisifyAction(() => {
|
|
397
409
|
postSessionLock(iframe, sid);
|
|
398
410
|
}, CheckoutEvents.SessionLocked, CheckoutEvents.SessionLockFailed);
|
|
399
411
|
};
|
|
400
|
-
|
|
401
412
|
const refreshSession = () => {
|
|
402
413
|
return promisifyAction(() => {
|
|
403
414
|
postSessionRefresh(iframe, sid);
|
|
404
415
|
}, CheckoutEvents.SessionUpdated, CheckoutEvents.SessionNotFound);
|
|
405
416
|
};
|
|
406
|
-
|
|
407
417
|
const setActivePaymentProductType = paymentProductType => {
|
|
408
418
|
postActivePaymentProductType(iframe, sid, paymentProductType);
|
|
409
419
|
};
|
|
410
|
-
|
|
411
420
|
const submitValidationResult = result => {
|
|
412
421
|
postValidationResult(iframe, sid, result);
|
|
413
422
|
};
|
|
414
|
-
|
|
415
423
|
const wrappedOnValidateSession = (event, checkout) => {
|
|
416
424
|
if (onValidateSession) {
|
|
417
425
|
onValidateSession(event, checkout, submitValidationResult);
|
|
418
426
|
}
|
|
419
427
|
};
|
|
420
|
-
|
|
421
428
|
const wrappedOnSessionLocked = (event, checkout) => {
|
|
422
429
|
if (onSessionLocked) {
|
|
423
430
|
onSessionLocked(event, checkout, refreshSession);
|
|
424
431
|
}
|
|
425
|
-
};
|
|
426
|
-
|
|
432
|
+
};
|
|
427
433
|
|
|
434
|
+
// Create checkout object that wraps the destroy function.
|
|
428
435
|
checkout = {
|
|
429
436
|
destroy,
|
|
430
437
|
iframe,
|
|
@@ -433,14 +440,18 @@ const embed = async options => {
|
|
|
433
440
|
refreshSession,
|
|
434
441
|
setActivePaymentProductType,
|
|
435
442
|
submitValidationResult
|
|
436
|
-
};
|
|
443
|
+
};
|
|
437
444
|
|
|
445
|
+
// Add event handlers (or in some cases add a fallback href handler).
|
|
438
446
|
[{
|
|
439
447
|
handler: setLanguage,
|
|
440
448
|
eventTypes: [InternalCheckoutEvents.LanguageChanged]
|
|
441
449
|
}, {
|
|
442
450
|
handler: setIframeHeight,
|
|
443
451
|
eventTypes: [InternalCheckoutEvents.HeightChanged]
|
|
452
|
+
}, {
|
|
453
|
+
handler: scrollToIframeTop,
|
|
454
|
+
eventTypes: [InternalCheckoutEvents.ScrollToTop]
|
|
444
455
|
}, {
|
|
445
456
|
handler: onSession,
|
|
446
457
|
eventTypes: [CheckoutEvents.SessionLoaded, CheckoutEvents.SessionUpdated]
|
|
@@ -487,23 +498,24 @@ const embed = async options => {
|
|
|
487
498
|
checkout
|
|
488
499
|
}));
|
|
489
500
|
}
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
await initiate(); // Return object with function to destroy the checkout.
|
|
501
|
+
});
|
|
493
502
|
|
|
503
|
+
// Add iframe to DOM
|
|
504
|
+
await initiate();
|
|
505
|
+
// Return object with function to destroy the checkout.
|
|
494
506
|
return checkout;
|
|
495
507
|
};
|
|
508
|
+
|
|
496
509
|
/**
|
|
497
510
|
* Redirect the customer to a payment session in the Dintero Checkout.
|
|
498
511
|
*/
|
|
499
|
-
|
|
500
512
|
const redirect = options => {
|
|
501
513
|
const {
|
|
502
514
|
sid,
|
|
503
515
|
language,
|
|
504
516
|
endpoint = "https://checkout.dintero.com"
|
|
505
|
-
} = options;
|
|
506
|
-
|
|
517
|
+
} = options;
|
|
518
|
+
// Redirect the current browser window to the checkout session url.
|
|
507
519
|
windowLocationAssign(getSessionUrl({
|
|
508
520
|
sid,
|
|
509
521
|
endpoint,
|