@paystack/inline-js 2.23.0-dev.1 → 2.23.0-dev.3
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/README.md +39 -1
- package/dist/inline.js +400 -637
- package/es/inline.js +400 -637
- package/lib/inline.js +400 -637
- package/package.json +11 -2
package/lib/inline.js
CHANGED
|
@@ -2,68 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
function _arrayLikeToArray(r, a) {
|
|
4
4
|
(null == a || a > r.length) && (a = r.length);
|
|
5
|
-
|
|
6
5
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
7
|
-
|
|
8
6
|
return n;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
function _arrayWithHoles(r) {
|
|
12
9
|
if (Array.isArray(r)) return r;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
11
|
function _arrayWithoutHoles(r) {
|
|
16
12
|
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
20
|
-
try {
|
|
21
|
-
var i = n[a](c),
|
|
22
|
-
u = i.value;
|
|
23
|
-
} catch (n) {
|
|
24
|
-
return void e(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _asyncToGenerator(n) {
|
|
31
|
-
return function () {
|
|
32
|
-
var t = this,
|
|
33
|
-
e = arguments;
|
|
34
|
-
return new Promise(function (r, o) {
|
|
35
|
-
var a = n.apply(t, e);
|
|
36
|
-
|
|
37
|
-
function _next(n) {
|
|
38
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function _throw(n) {
|
|
42
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_next(void 0);
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
14
|
function _classCallCheck(a, n) {
|
|
51
15
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
52
16
|
}
|
|
53
|
-
|
|
54
17
|
function _defineProperties(e, r) {
|
|
55
18
|
for (var t = 0; t < r.length; t++) {
|
|
56
19
|
var o = r[t];
|
|
57
20
|
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
58
21
|
}
|
|
59
22
|
}
|
|
60
|
-
|
|
61
23
|
function _createClass(e, r, t) {
|
|
62
24
|
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
63
25
|
writable: !1
|
|
64
26
|
}), e;
|
|
65
27
|
}
|
|
66
|
-
|
|
67
28
|
function _defineProperty(e, r, t) {
|
|
68
29
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
69
30
|
value: t,
|
|
@@ -72,23 +33,19 @@ function _defineProperty(e, r, t) {
|
|
|
72
33
|
writable: !0
|
|
73
34
|
}) : e[r] = t, e;
|
|
74
35
|
}
|
|
75
|
-
|
|
76
36
|
function _iterableToArray(r) {
|
|
77
37
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
78
38
|
}
|
|
79
|
-
|
|
80
39
|
function _iterableToArrayLimit(r, l) {
|
|
81
40
|
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
82
|
-
|
|
83
41
|
if (null != t) {
|
|
84
42
|
var e,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
43
|
+
n,
|
|
44
|
+
i,
|
|
45
|
+
u,
|
|
46
|
+
a = [],
|
|
47
|
+
f = !0,
|
|
48
|
+
o = !1;
|
|
92
49
|
try {
|
|
93
50
|
if (i = (t = t.call(r)).next, 0 === l) {
|
|
94
51
|
if (Object(t) !== t) return;
|
|
@@ -103,32 +60,25 @@ function _iterableToArrayLimit(r, l) {
|
|
|
103
60
|
if (o) throw n;
|
|
104
61
|
}
|
|
105
62
|
}
|
|
106
|
-
|
|
107
63
|
return a;
|
|
108
64
|
}
|
|
109
65
|
}
|
|
110
|
-
|
|
111
66
|
function _nonIterableRest() {
|
|
112
67
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
113
68
|
}
|
|
114
|
-
|
|
115
69
|
function _nonIterableSpread() {
|
|
116
70
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
117
71
|
}
|
|
118
|
-
|
|
119
72
|
function ownKeys(e, r) {
|
|
120
73
|
var t = Object.keys(e);
|
|
121
|
-
|
|
122
74
|
if (Object.getOwnPropertySymbols) {
|
|
123
75
|
var o = Object.getOwnPropertySymbols(e);
|
|
124
76
|
r && (o = o.filter(function (r) {
|
|
125
77
|
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
126
78
|
})), t.push.apply(t, o);
|
|
127
79
|
}
|
|
128
|
-
|
|
129
80
|
return t;
|
|
130
81
|
}
|
|
131
|
-
|
|
132
82
|
function _objectSpread2(e) {
|
|
133
83
|
for (var r = 1; r < arguments.length; r++) {
|
|
134
84
|
var t = null != arguments[r] ? arguments[r] : {};
|
|
@@ -138,65 +88,48 @@ function _objectSpread2(e) {
|
|
|
138
88
|
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
139
89
|
});
|
|
140
90
|
}
|
|
141
|
-
|
|
142
91
|
return e;
|
|
143
92
|
}
|
|
144
|
-
|
|
145
93
|
function _objectWithoutProperties(e, t) {
|
|
146
94
|
if (null == e) return {};
|
|
147
|
-
|
|
148
95
|
var o,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
96
|
+
r,
|
|
97
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
152
98
|
if (Object.getOwnPropertySymbols) {
|
|
153
99
|
var n = Object.getOwnPropertySymbols(e);
|
|
154
|
-
|
|
155
100
|
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
156
101
|
}
|
|
157
|
-
|
|
158
102
|
return i;
|
|
159
103
|
}
|
|
160
|
-
|
|
161
104
|
function _objectWithoutPropertiesLoose(r, e) {
|
|
162
105
|
if (null == r) return {};
|
|
163
106
|
var t = {};
|
|
164
|
-
|
|
165
107
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
166
108
|
if (-1 !== e.indexOf(n)) continue;
|
|
167
109
|
t[n] = r[n];
|
|
168
110
|
}
|
|
169
|
-
|
|
170
111
|
return t;
|
|
171
112
|
}
|
|
172
|
-
|
|
173
113
|
function _slicedToArray(r, e) {
|
|
174
114
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
175
115
|
}
|
|
176
|
-
|
|
177
116
|
function _toConsumableArray(r) {
|
|
178
117
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
179
118
|
}
|
|
180
|
-
|
|
181
119
|
function _toPrimitive(t, r) {
|
|
182
120
|
if ("object" != typeof t || !t) return t;
|
|
183
121
|
var e = t[Symbol.toPrimitive];
|
|
184
|
-
|
|
185
122
|
if (void 0 !== e) {
|
|
186
123
|
var i = e.call(t, r || "default");
|
|
187
124
|
if ("object" != typeof i) return i;
|
|
188
125
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
189
126
|
}
|
|
190
|
-
|
|
191
127
|
return ("string" === r ? String : Number)(t);
|
|
192
128
|
}
|
|
193
|
-
|
|
194
129
|
function _toPropertyKey(t) {
|
|
195
130
|
var i = _toPrimitive(t, "string");
|
|
196
|
-
|
|
197
131
|
return "symbol" == typeof i ? i : i + "";
|
|
198
132
|
}
|
|
199
|
-
|
|
200
133
|
function _typeof(o) {
|
|
201
134
|
"@babel/helpers - typeof";
|
|
202
135
|
|
|
@@ -206,7 +139,6 @@ function _typeof(o) {
|
|
|
206
139
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
207
140
|
}, _typeof(o);
|
|
208
141
|
}
|
|
209
|
-
|
|
210
142
|
function _unsupportedIterableToArray(r, a) {
|
|
211
143
|
if (r) {
|
|
212
144
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -252,18 +184,16 @@ var configurations = {
|
|
|
252
184
|
staging: stagingConfig,
|
|
253
185
|
production: productionConfig
|
|
254
186
|
};
|
|
255
|
-
/* eslint-disable */
|
|
256
187
|
|
|
188
|
+
/* eslint-disable */
|
|
257
189
|
var config = configurations['staging'] || stagingConfig;
|
|
258
190
|
|
|
259
191
|
function randomId() {
|
|
260
192
|
var text = '';
|
|
261
193
|
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
262
|
-
|
|
263
194
|
for (var i = 0; i < 5; i += 1) {
|
|
264
195
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
265
196
|
}
|
|
266
|
-
|
|
267
197
|
return text;
|
|
268
198
|
}
|
|
269
199
|
|
|
@@ -297,15 +227,12 @@ function getLastScript() {
|
|
|
297
227
|
var scripts = document.getElementsByTagName('script');
|
|
298
228
|
return scripts[scripts.length - 1];
|
|
299
229
|
}
|
|
300
|
-
|
|
301
230
|
function getSourceScript() {
|
|
302
231
|
return document.currentScript || getLastScript();
|
|
303
232
|
}
|
|
304
|
-
|
|
305
233
|
function getDataAttributes() {
|
|
306
234
|
var dataAttributes = [];
|
|
307
235
|
var sourceScript = getSourceScript();
|
|
308
|
-
|
|
309
236
|
if (sourceScript) {
|
|
310
237
|
var attributes = Array.prototype.slice.call(sourceScript.attributes);
|
|
311
238
|
dataAttributes = Object.keys(attributes).filter(function (key) {
|
|
@@ -315,10 +242,8 @@ function getDataAttributes() {
|
|
|
315
242
|
return attributes[index].nodeName;
|
|
316
243
|
});
|
|
317
244
|
}
|
|
318
|
-
|
|
319
245
|
return dataAttributes;
|
|
320
246
|
}
|
|
321
|
-
|
|
322
247
|
function scriptCanUseDataAttributes() {
|
|
323
248
|
var hasDataAttributes = getDataAttributes().length > 0;
|
|
324
249
|
var hasParentForm = getSourceScript() && getSourceScript().parentElement.tagName === 'FORM';
|
|
@@ -330,30 +255,23 @@ function getDataAttributesAsParameters() {
|
|
|
330
255
|
return g[1].toUpperCase();
|
|
331
256
|
});
|
|
332
257
|
}
|
|
333
|
-
|
|
334
258
|
function validateLazyParameters(parameters) {
|
|
335
259
|
if (parameters.buttonId && !document.getElementById(parameters.buttonId)) {
|
|
336
260
|
throw new Error('Please make sure the buttonId is an element available in the DOM');
|
|
337
261
|
}
|
|
338
|
-
|
|
339
262
|
var updatedParameters = _objectSpread2({}, parameters);
|
|
340
|
-
|
|
341
263
|
updatedParameters.buttonText = parameters.buttonText || 'Pay';
|
|
342
264
|
updatedParameters.buttonVariant = 'normal';
|
|
343
265
|
updatedParameters.buttonWordmarkVariant = 'normal';
|
|
344
266
|
var allowedVariants = ['normal', 'light'];
|
|
345
|
-
|
|
346
267
|
if (parameters.buttonVariant && allowedVariants.indexOf(parameters.buttonVariant) > -1) {
|
|
347
268
|
updatedParameters.buttonVariant = parameters.buttonVariant;
|
|
348
269
|
}
|
|
349
|
-
|
|
350
270
|
if (parameters.buttonWordmarkVariant && allowedVariants.indexOf(parameters.buttonWordmarkVariant) > -1) {
|
|
351
271
|
updatedParameters.buttonWordmarkVariant = parameters.buttonWordmarkVariant;
|
|
352
272
|
}
|
|
353
|
-
|
|
354
273
|
return updatedParameters;
|
|
355
274
|
}
|
|
356
|
-
|
|
357
275
|
var parameters = {};
|
|
358
276
|
var sourceScript = getSourceScript();
|
|
359
277
|
var dataAttributes = getDataAttributes();
|
|
@@ -378,7 +296,6 @@ var loaderHTML = "\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head>\n <me
|
|
|
378
296
|
var backgroundCSS = "\n z-index: 999999999999999;\n background: transparent;\n background: rgba(0, 0, 0, 0.75); \n border: 0px none transparent;\n overflow-x: hidden;\n overflow-y: hidden;\n margin: 0;\n padding: 0;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n position: fixed;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n transition: opacity 0.3s;\n -webkit-transition: opacity 0.3s;\n visibility: hidden;\n display: none;\n";
|
|
379
297
|
var checkoutCSS = "\n z-index: 999999999999999;\n background: transparent;\n border: 0px none transparent;\n overflow-x: hidden;\n overflow-y: hidden;\n margin: 0;\n padding: 0;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n position: fixed;\n left: 0;\n top: 0;\n width: 100%;\n visibility: hidden;\n display: none;\n height: 100%;\n";
|
|
380
298
|
var embedCSS = "\n background: transparent;\n background: rgba(0,0,0,0);\n border: 0px none transparent;\n overflow-x: hidden;\n overflow-y: hidden;\n nmargin: 0;\n padding: 0;\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n visibility: hidden;\n display: none;\n";
|
|
381
|
-
|
|
382
299
|
function generateInlineButtonCSS(variant) {
|
|
383
300
|
var baseCSS = "\n box-sizing: border-box;\n display: inline-block;\n line-height: 1;\n white-space: nowrap;\n margin: 0 0 10px;\n text-align: center;\n -webkit-appearance: none;\n outline: none;\n font-size: 14px;\n font-weight: 600;\n border-radius: 6px;\n cursor: pointer;\n padding: 16px 24px;\n box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.15);\n transition: all .3s ease;\n border: none;\n min-width: 190px;\n ";
|
|
384
301
|
var greenCSS = "\n background: linear-gradient(180deg,#44b669 0,#40ad57);\n text-shadow: 1px 1px 1px rgba(0,0,0,.1);\n color: #ffffff;\n ";
|
|
@@ -389,7 +306,6 @@ function generateInlineButtonCSS(variant) {
|
|
|
389
306
|
};
|
|
390
307
|
return "".concat(baseCSS).concat(colorVariants[variant]);
|
|
391
308
|
}
|
|
392
|
-
|
|
393
309
|
function generateInlineButtonHTML(options) {
|
|
394
310
|
var wordmarkVariants = {
|
|
395
311
|
normal: secureByPaystack,
|
|
@@ -402,15 +318,14 @@ var defaultCustomApplePayStyles = {
|
|
|
402
318
|
height: '50px',
|
|
403
319
|
width: 'auto',
|
|
404
320
|
borderRadius: '3px',
|
|
405
|
-
padding: '
|
|
321
|
+
padding: '0px',
|
|
406
322
|
locale: 'en',
|
|
407
|
-
type: '
|
|
323
|
+
type: 'plain'
|
|
408
324
|
};
|
|
409
325
|
var parseApplePayCustomStyles = function parseApplePayCustomStyles(styles) {
|
|
410
326
|
if (!(styles && _typeof(styles) === 'object')) {
|
|
411
327
|
return defaultCustomApplePayStyles;
|
|
412
328
|
}
|
|
413
|
-
|
|
414
329
|
var customStyles = Object.keys(defaultCustomApplePayStyles).reduce(function (newDefaultStyles, key) {
|
|
415
330
|
return _objectSpread2(_objectSpread2({}, newDefaultStyles), {}, _defineProperty({}, key, styles[key] || defaultCustomApplePayStyles[key]));
|
|
416
331
|
}, {});
|
|
@@ -418,22 +333,194 @@ var parseApplePayCustomStyles = function parseApplePayCustomStyles(styles) {
|
|
|
418
333
|
};
|
|
419
334
|
var generateApplePayCSS = function generateApplePayCSS(_ref) {
|
|
420
335
|
var height = _ref.height,
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
336
|
+
width = _ref.width,
|
|
337
|
+
borderRadius = _ref.borderRadius,
|
|
338
|
+
padding = _ref.padding;
|
|
424
339
|
return "\n apple-pay-button {\n --apple-pay-button-width: ".concat(width, ";\n --apple-pay-button-height: ").concat(height, ";\n --apple-pay-button-border-radius: ").concat(borderRadius, ";\n --apple-pay-button-padding: ").concat(padding, ";\n --apple-pay-button-box-sizing: border-box;\n width: ").concat(width, ";\n }\n");
|
|
425
340
|
};
|
|
426
341
|
var generateApplePayFallbackCSS = function generateApplePayFallbackCSS(_ref2) {
|
|
427
342
|
var height = _ref2.height,
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
343
|
+
width = _ref2.width,
|
|
344
|
+
borderRadius = _ref2.borderRadius,
|
|
345
|
+
padding = _ref2.padding,
|
|
346
|
+
type = _ref2.type,
|
|
347
|
+
locale = _ref2.locale;
|
|
433
348
|
return "\n @supports (-webkit-appearance: -apple-pay-button) { \n .apple-pay-button {\n display: inline-block;\n -webkit-appearance: -apple-pay-button;\n width: ".concat(width, ";\n height: ").concat(height, ";\n border-radius: ").concat(borderRadius, ";\n padding: ").concat(padding, ";\n -apple-pay-button-type: ").concat(type, ";\n -webkit-locale: ").concat(locale, ";\n }\n .apple-pay-button-black {\n -apple-pay-button-style: black;\n }\n .apple-pay-button-white {\n -apple-pay-button-style: white;\n }\n .apple-pay-button-white-with-line {\n -apple-pay-button-style: white-outline;\n }\n }\n\n @supports not (-webkit-appearance: -apple-pay-button) {\n .apple-pay-button {\n display: inline-block;\n background-size: 100% 60%;\n background-repeat: no-repeat;\n background-position: 50% 50%;\n border-radius: 5px;\n padding: 0px;\n box-sizing: border-box;\n min-width: 200px;\n min-height: 32px;\n max-height: 64px;\n }\n .apple-pay-button-black {\n background-image: -webkit-named-image(apple-pay-logo-white);\n background-color: black;\n }\n .apple-pay-button-white {\n background-image: -webkit-named-image(apple-pay-logo-black);\n background-color: white;\n }\n .apple-pay-button-white-with-line {\n background-image: -webkit-named-image(apple-pay-logo-black);\n background-color: white;\n border: .5px solid black;\n }\n }\n");
|
|
434
349
|
};
|
|
435
350
|
var preCheckoutModalCSS = "\n .pre-checkout-modal {\n display: none;\n position: fixed;\n z-index: 1;\n left: 0;\n top: 0;\n width: 100vw;\n height: 100%;\n overflow: auto;\n background-color: rgba(0, 0, 0, 0.75);\n transition: all 0.2s ease;\n }\n\n .pre-checkout-modal.show {\n display: block;\n }\n\n .pre-checkout-modal__content {\n position: absolute;\n bottom: 0;\n left: 0;\n right: 0;\n margin-left: auto;\n margin-right: auto;\n background-color: #fefefe;\n padding: 20px;\n padding-bottom: max(30px, env(safe-area-inset-bottom));\n width: 100%;\n border-radius: 6px 6px 0 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n max-width: 350px;\n\n box-sizing: border-box;\n transform: translateY(238px);\n transition: transform 0.3s cubic-bezier(.16,.81,.32,1);\n }\n\n .modal-wrapper {\n width: 100%;\n }\n\n .payment-info {\n position: relative;\n padding-bottom: 15px;\n border-bottom: solid 1px whitesmoke;\n display: flex;\n align-items: flex-start;\n justify-content: space-between;\n width: 100%;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\", \"Ubuntu\",\n \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif;\n }\n\n .customer-email {\n color: #737373;\n font-size: 13px;\n line-height: 16px;\n }\n\n .customer-info {\n flex: 1;\n text-align: right;\n }\n\n .merchant-logo {\n display: flex;\n align-items: center;\n height: 30px;\n }\n .transaction-amount {\n margin-top: 5px;\n font-size: 13px;\n line-height: 16px;\n color: #737373;\n }\n\n .amount {\n color: #29b263;\n font-weight: bold;\n }\n\n @media only screen and (min-width: 500px) {\n .pre-checkout-modal__content {\n bottom: 0;\n top: 0;\n margin: auto;\n border-radius: 6px;\n height: fit-content;\n }\n }\n\n .pre-checkout-modal__content.show {\n transform: translateY(0);\n margin: 0 auto;\n margin-top: 100px;\n }\n\n .pre-checkout-modal__content > * {\n margin-top: 0;\n margin-bottom: 40px;\n }\n .pre-checkout-modal__content > *:last-child {\n margin-bottom: 0;\n }\n\n .pre-checkout-modal__content svg {\n margin: auto;\n width: 100%;\n }\n\n #inline-button-wordmark--white {\n position: absolute;\n bottom: -50px;\n margin: auto;\n left: 0;\n right: 0;\n width: fit-content;\n }\n\n #inline-button-wordmark--grey {\n display: none;\n }\n\n .pre-checkout-modal__content #apple-pay-mark--light {\n margin-bottom: 16px;\n }\n\n .pre-checkout-modal p {\n -webkit-text-size-adjust: 100%;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\", \"Ubuntu\",\n \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif;\n color: #4E4E4E;\n line-height: 140%;\n font-size: 14px;\n font-weight: 500;\n margin: 0;\n padding: 0 20px;\n text-align: center;\n letter-spacing: -0.3px;\n }\n\n .pre-checkout-modal button {\n height: 42px;\n width: 100%;\n \n box-sizing: border-box;\n border-radius: 3px;\n font-size: 14px;\n line-height: 24px;\n cursor: pointer;\n -webkit-text-size-adjust: 100%;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\", \"Ubuntu\",\n \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\", sans-serif;\n }\n\n .pre-checkout-modal .open-paystack-pop-button {\n background: #FAFAFA;\n border: 1px solid #F2F3F3;\n color: #4E4E4E;\n font-weight: 500;\n }\n\n .pre-checkout-modal .open-paystack-pop-button:hover, \n .pre-checkout-modal .open-paystack-pop-button:active, \n .pre-checkout-modal .open-paystack-pop-button:focus {\n background: #F2F3F3;\n }\n\n .pre-checkout-modal .pay-with-vault-button {\n font-weight: 700;\n background: #44b669;\n background: linear-gradient(to bottom, #44b669 0%, #40ad57 100%);\n border: solid 1px #49a861;\n text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);\n outline: none;\n color: white;\n transition: all 300ms;\n }\n\n .pre-checkout-modal .vault-instruction {\n color: #2f3d4d;\n font-size: 14px;\n letter-spacing: normal;\n line-height: 1.4;\n margin: 0 auto 24px;\n padding: 0;\n }\n .vault-logo-container {\n width: 74px;\n height: 20px;\n margin: 0 auto 24px\n }\n .vault-logo-container img {\n height: 100%;\n width: 100%;\n border-radius: 8px;\n }\n .vault-divider {\n margin-bottom: 16px;\n margin-top: 24px;\n position: relative;\n }\n .vault-divider__container {\n align-items: center;\n bottom: 0;\n display: flex;\n left: 0;\n position: absolute;\n right: 0;\n top: 0;\n }\n .vault-divider__line {\n border: 1px dashed #ccced0;\n width: 100%;\n }\n .vault-divider__text-container {\n display: flex;\n justify-content: center;\n position: relative;\n }\n .vault-divider__text {\n background-color: #fff;\n color: #999da1;\n font-size: 14px;\n font-weight: 500;\n letter-spacing: -.3px;\n line-height: 19.6px;\n margin-bottom: 2px;\n padding: 0 8px;\n }\n\n #payment-request-button {\n width: 100%;\n height: fit-content;\n margin: 24px 0 16px 0;\n }\n\n #paystackpop-button {\n padding: 0 16px;\n }\n\n #apple-pay-close-button {\n position: absolute;\n text-align: center;\n top: 0;\n right: -26px;\n height: 16px;\n width: 16px;\n padding: 0;\n display: inline-block;\n z-index: 3;\n border-radius: 50%;\n background: transparent;\n transition: all 300ms;\n outline: none;\n cursor: pointer;\n border: none;\n }\n\n #apple-pay-close-button svg {\n width: initial;\n }\n \n #apple-pay-close-button:hover {\n background-color: #e22b28;\n }\n\n @media only screen and (max-width: 500px) {\n .pre-checkout-modal__content {\n max-width: 500px;\n border-radius: 0;\n padding-bottom: 0;\n }\n\n .modal-wrapper {\n padding: 0;\n }\n\n .vault-logo-container {\n width: 74px;\n height: 20px;\n }\n\n #inline-button-wordmark--white {\n display: none\n }\n \n #inline-button-wordmark--grey {\n display: block;\n width: 100%;\n margin: 16px 0;\n height: 13px;\n }\n\n #apple-pay-close-button {\n display: none;\n }\n }\n";
|
|
436
351
|
|
|
352
|
+
var amountSubunitToBase = function amountSubunitToBase() {
|
|
353
|
+
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
354
|
+
return Number(parseFloat(amount / 100).toFixed(2));
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
var requestConfig = {
|
|
358
|
+
headers: {
|
|
359
|
+
accept: 'application/json, text/plain, */*',
|
|
360
|
+
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
|
|
361
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
362
|
+
'sec-ch-ua-mobile': '?0',
|
|
363
|
+
'sec-fetch-dest': 'empty',
|
|
364
|
+
'sec-fetch-mode': 'cors',
|
|
365
|
+
'sec-fetch-site': 'cross-site'
|
|
366
|
+
},
|
|
367
|
+
referrerPolicy: 'no-referrer-when-downgrade',
|
|
368
|
+
method: 'POST',
|
|
369
|
+
mode: 'cors',
|
|
370
|
+
credentials: 'omit'
|
|
371
|
+
};
|
|
372
|
+
function createFormBody(params) {
|
|
373
|
+
var formBody = Object.keys(params).reduce(function (formBodyArray, key) {
|
|
374
|
+
var encodedKey = encodeURIComponent(key);
|
|
375
|
+
var encodedValue = encodeURIComponent(params[key]);
|
|
376
|
+
var encodedFormBody = "".concat(encodedKey, "=").concat(encodedValue);
|
|
377
|
+
return [].concat(_toConsumableArray(formBodyArray), [encodedFormBody]);
|
|
378
|
+
}, []);
|
|
379
|
+
return formBody.join('&');
|
|
380
|
+
}
|
|
381
|
+
var APPLE_PAY_CAPABILITY_STATUS = {
|
|
382
|
+
AVAILABLE: 'paymentCredentialsAvailable',
|
|
383
|
+
UNAVAILABLE: 'paymentCredentialsUnavailable',
|
|
384
|
+
UNKNOWN: 'paymentCredentialStatusUnknown',
|
|
385
|
+
UNSUPPORTED: 'applePayUnsupported'
|
|
386
|
+
};
|
|
387
|
+
var formatIntervalString = function formatIntervalString(interval) {
|
|
388
|
+
var plans = {
|
|
389
|
+
biannually: 'BIANNUAL PLAN',
|
|
390
|
+
annually: 'ANNUAL PLAN'
|
|
391
|
+
};
|
|
392
|
+
return plans[interval] || "".concat(interval.toUpperCase(), " PLAN");
|
|
393
|
+
};
|
|
394
|
+
var generateApplePaymentRequestObject = function generateApplePaymentRequestObject(_ref) {
|
|
395
|
+
var currency = _ref.currency,
|
|
396
|
+
amount = _ref.amount,
|
|
397
|
+
merchantName = _ref.merchantName,
|
|
398
|
+
interval = _ref.interval;
|
|
399
|
+
return _objectSpread2({
|
|
400
|
+
countryCode: 'NG',
|
|
401
|
+
currencyCode: currency,
|
|
402
|
+
merchantCapabilities: ['supports3DS', 'supportsCredit', 'supportsDebit'],
|
|
403
|
+
supportedNetworks: ['visa', 'masterCard'],
|
|
404
|
+
requiredBillingContactFields: ['postalAddress', 'name', 'phone', 'email'],
|
|
405
|
+
total: {
|
|
406
|
+
label: "".concat(merchantName, " - Paystack"),
|
|
407
|
+
type: 'final',
|
|
408
|
+
amount: String(amountSubunitToBase(amount))
|
|
409
|
+
}
|
|
410
|
+
}, typeof interval === 'string' && interval.trim() !== '' && {
|
|
411
|
+
lineItems: [{
|
|
412
|
+
label: formatIntervalString(interval),
|
|
413
|
+
amount: String(amountSubunitToBase(amount))
|
|
414
|
+
}]
|
|
415
|
+
});
|
|
416
|
+
};
|
|
417
|
+
var validateApplePaySession = function validateApplePaySession(_ref2) {
|
|
418
|
+
var transactionId = _ref2.transactionId,
|
|
419
|
+
validationURL = _ref2.validationURL,
|
|
420
|
+
merchantName = _ref2.merchantName,
|
|
421
|
+
_ref2$domainName = _ref2.domainName,
|
|
422
|
+
domainName = _ref2$domainName === void 0 ? window && window.location && window.location.hostname : _ref2$domainName;
|
|
423
|
+
var validateSessionUrl = "".concat(config.paymentBaseUrl).concat(config.applePayValidateSessionPath);
|
|
424
|
+
var params = {
|
|
425
|
+
transaction: transactionId,
|
|
426
|
+
sessionUrl: validationURL,
|
|
427
|
+
displayName: merchantName,
|
|
428
|
+
domainName: domainName
|
|
429
|
+
};
|
|
430
|
+
var formBody = createFormBody(params);
|
|
431
|
+
var validateSession = fetch(validateSessionUrl, _objectSpread2(_objectSpread2({}, requestConfig), {}, {
|
|
432
|
+
body: formBody
|
|
433
|
+
})).then(function (response) {
|
|
434
|
+
return response.json();
|
|
435
|
+
});
|
|
436
|
+
return validateSession;
|
|
437
|
+
};
|
|
438
|
+
var chargeApplePay = function chargeApplePay(_ref3) {
|
|
439
|
+
var transactionId = _ref3.transactionId,
|
|
440
|
+
payment = _ref3.payment;
|
|
441
|
+
var chargeApplePayUrl = "".concat(config.paymentBaseUrl).concat(config.applePayChargePath);
|
|
442
|
+
var params = {
|
|
443
|
+
transaction: transactionId,
|
|
444
|
+
paymentObject: JSON.stringify(payment)
|
|
445
|
+
};
|
|
446
|
+
var formBody = createFormBody(params);
|
|
447
|
+
var charge = fetch(chargeApplePayUrl, _objectSpread2(_objectSpread2({}, requestConfig), {}, {
|
|
448
|
+
body: formBody
|
|
449
|
+
})).then(function (response) {
|
|
450
|
+
return response.json();
|
|
451
|
+
});
|
|
452
|
+
return charge;
|
|
453
|
+
};
|
|
454
|
+
var deviceSupportsApplePay = function deviceSupportsApplePay() {
|
|
455
|
+
try {
|
|
456
|
+
return !!(window.ApplePaySession && window.ApplePaySession.supportsVersion(config.applePayVersion));
|
|
457
|
+
} catch (error) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
var getApplePayCapabilityStatusFromResponse = function getApplePayCapabilityStatusFromResponse(capabilities) {
|
|
462
|
+
if (!capabilities) {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
if (typeof capabilities === 'string') {
|
|
466
|
+
return capabilities;
|
|
467
|
+
}
|
|
468
|
+
if (typeof capabilities.paymentCredentialStatus === 'string') {
|
|
469
|
+
return capabilities.paymentCredentialStatus;
|
|
470
|
+
}
|
|
471
|
+
return null;
|
|
472
|
+
};
|
|
473
|
+
var getApplePayCapabilityStatus = function getApplePayCapabilityStatus() {
|
|
474
|
+
try {
|
|
475
|
+
if (!deviceSupportsApplePay()) {
|
|
476
|
+
return Promise.resolve(null);
|
|
477
|
+
}
|
|
478
|
+
var _window = window,
|
|
479
|
+
ApplePaySession = _window.ApplePaySession;
|
|
480
|
+
if (typeof ApplePaySession.applePayCapabilities === 'function') {
|
|
481
|
+
return Promise.resolve(ApplePaySession.applePayCapabilities()).then(function (capabilities) {
|
|
482
|
+
return getApplePayCapabilityStatusFromResponse(capabilities);
|
|
483
|
+
}).catch(function () {
|
|
484
|
+
try {
|
|
485
|
+
if (window.ApplePaySession.canMakePayments()) {
|
|
486
|
+
return APPLE_PAY_CAPABILITY_STATUS.UNKNOWN;
|
|
487
|
+
}
|
|
488
|
+
} catch (fallbackError) {
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
return APPLE_PAY_CAPABILITY_STATUS.UNSUPPORTED;
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
if (typeof ApplePaySession.canMakePayments === 'function') {
|
|
495
|
+
return Promise.resolve(ApplePaySession.canMakePayments()).then(function (canMakePayments) {
|
|
496
|
+
return canMakePayments ? APPLE_PAY_CAPABILITY_STATUS.UNKNOWN : APPLE_PAY_CAPABILITY_STATUS.UNSUPPORTED;
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
return Promise.resolve(null);
|
|
500
|
+
} catch (error) {
|
|
501
|
+
try {
|
|
502
|
+
if (window.ApplePaySession.canMakePayments()) {
|
|
503
|
+
return Promise.resolve(APPLE_PAY_CAPABILITY_STATUS.UNKNOWN);
|
|
504
|
+
}
|
|
505
|
+
} catch (fallbackError) {
|
|
506
|
+
return Promise.resolve(null);
|
|
507
|
+
}
|
|
508
|
+
return Promise.resolve(APPLE_PAY_CAPABILITY_STATUS.UNSUPPORTED);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
var applePayCapabilityCanShowButton = function applePayCapabilityCanShowButton(status) {
|
|
512
|
+
return [APPLE_PAY_CAPABILITY_STATUS.AVAILABLE, APPLE_PAY_CAPABILITY_STATUS.UNKNOWN].includes(status);
|
|
513
|
+
};
|
|
514
|
+
var canUseApplePay = function canUseApplePay(channels) {
|
|
515
|
+
var availableChannels = channels || [];
|
|
516
|
+
if (!availableChannels.includes('apple_pay')) {
|
|
517
|
+
return Promise.resolve(false);
|
|
518
|
+
}
|
|
519
|
+
return getApplePayCapabilityStatus().then(function (capabilityStatus) {
|
|
520
|
+
return applePayCapabilityCanShowButton(capabilityStatus);
|
|
521
|
+
});
|
|
522
|
+
};
|
|
523
|
+
|
|
437
524
|
/* eslint-env browser */
|
|
438
525
|
function findHighestZIndex() {
|
|
439
526
|
var highestZIndex = 0;
|
|
@@ -441,7 +528,6 @@ function findHighestZIndex() {
|
|
|
441
528
|
elements.forEach(function (element) {
|
|
442
529
|
var computedStyle = window.getComputedStyle(element);
|
|
443
530
|
var zIndex = parseFloat(computedStyle.zIndex);
|
|
444
|
-
|
|
445
531
|
if (!Number.isNaN(zIndex) && zIndex > highestZIndex) {
|
|
446
532
|
highestZIndex = zIndex;
|
|
447
533
|
}
|
|
@@ -460,7 +546,6 @@ function createIframe(id) {
|
|
|
460
546
|
iframe.style.display = 'none';
|
|
461
547
|
return iframe;
|
|
462
548
|
}
|
|
463
|
-
|
|
464
549
|
function mountCheckoutIframe(id) {
|
|
465
550
|
var iframe = createIframe("inline-checkout-".concat(id));
|
|
466
551
|
iframe.src = "".concat(config.checkoutUrl, "popup");
|
|
@@ -493,22 +578,20 @@ function mountEmbedCheckoutIframe(id, src) {
|
|
|
493
578
|
function getApplePayButton(container) {
|
|
494
579
|
return container.querySelector('apple-pay-button') || container.querySelector('#apple-pay-button');
|
|
495
580
|
}
|
|
581
|
+
var applePaySdkPromise;
|
|
496
582
|
var loadScript = function loadScript(url, _ref) {
|
|
497
583
|
var container = _ref.container,
|
|
498
|
-
|
|
584
|
+
integrity = _ref.integrity;
|
|
499
585
|
return new Promise(function (resolve, reject) {
|
|
500
586
|
if (!url) {
|
|
501
587
|
reject('No script url');
|
|
502
588
|
}
|
|
503
|
-
|
|
504
589
|
var script = document.createElement('script');
|
|
505
590
|
script.src = url;
|
|
506
591
|
script.crossOrigin = 'anonymous';
|
|
507
|
-
|
|
508
592
|
if (integrity) {
|
|
509
593
|
script.integrity = integrity;
|
|
510
594
|
}
|
|
511
|
-
|
|
512
595
|
script.addEventListener('load', function () {
|
|
513
596
|
resolve(true);
|
|
514
597
|
});
|
|
@@ -516,7 +599,6 @@ var loadScript = function loadScript(url, _ref) {
|
|
|
516
599
|
script.remove();
|
|
517
600
|
reject(false);
|
|
518
601
|
});
|
|
519
|
-
|
|
520
602
|
if (container) {
|
|
521
603
|
container.appendChild(script);
|
|
522
604
|
} else {
|
|
@@ -524,6 +606,27 @@ var loadScript = function loadScript(url, _ref) {
|
|
|
524
606
|
}
|
|
525
607
|
});
|
|
526
608
|
};
|
|
609
|
+
var applePayButtonComponentIsAvailable = function applePayButtonComponentIsAvailable() {
|
|
610
|
+
return !!(window && window.customElements && window.customElements.get('apple-pay-button'));
|
|
611
|
+
};
|
|
612
|
+
var ensureApplePaySdkLoaded = function ensureApplePaySdkLoaded(container) {
|
|
613
|
+
if (applePayButtonComponentIsAvailable()) {
|
|
614
|
+
return Promise.resolve(true);
|
|
615
|
+
}
|
|
616
|
+
if (applePaySdkPromise) {
|
|
617
|
+
return applePaySdkPromise;
|
|
618
|
+
}
|
|
619
|
+
applePaySdkPromise = loadScript(APPLE_PAY_SDK_SOURCE, {
|
|
620
|
+
container: container,
|
|
621
|
+
integrity: APPLE_PAY_SDK_INTEGRITY_HASH
|
|
622
|
+
}).then(function () {
|
|
623
|
+
return true;
|
|
624
|
+
}).catch(function (error) {
|
|
625
|
+
applePaySdkPromise = null;
|
|
626
|
+
throw error;
|
|
627
|
+
});
|
|
628
|
+
return applePaySdkPromise;
|
|
629
|
+
};
|
|
527
630
|
function appendIframeToContainer(containerId, iframe) {
|
|
528
631
|
var container = document.getElementById(containerId);
|
|
529
632
|
container.innerHTML = '';
|
|
@@ -535,7 +638,6 @@ function appendIframeToContainer(containerId, iframe) {
|
|
|
535
638
|
}
|
|
536
639
|
function hideLoader(iframe) {
|
|
537
640
|
var bgWindow = iframe.contentWindow.document;
|
|
538
|
-
|
|
539
641
|
if (bgWindow) {
|
|
540
642
|
bgWindow.getElementById('app-loader').style.display = 'none';
|
|
541
643
|
}
|
|
@@ -545,14 +647,11 @@ function animateCheckoutIn(domElements) {
|
|
|
545
647
|
if (!domElements) {
|
|
546
648
|
reject('No dom element provided');
|
|
547
649
|
}
|
|
548
|
-
|
|
549
650
|
var checkoutIframe = domElements.checkoutIframe,
|
|
550
|
-
|
|
551
|
-
|
|
651
|
+
backgroundIframe = domElements.backgroundIframe;
|
|
552
652
|
if (!checkoutIframe || !backgroundIframe) {
|
|
553
653
|
reject('No dom element provided');
|
|
554
654
|
}
|
|
555
|
-
|
|
556
655
|
checkoutIframe.style.display = '';
|
|
557
656
|
checkoutIframe.style.visibility = 'visible';
|
|
558
657
|
backgroundIframe.style.display = '';
|
|
@@ -565,14 +664,11 @@ function animateCheckoutOut(domElements) {
|
|
|
565
664
|
if (!domElements) {
|
|
566
665
|
reject('No dom element provided');
|
|
567
666
|
}
|
|
568
|
-
|
|
569
667
|
var checkoutIframe = domElements.checkoutIframe,
|
|
570
|
-
|
|
571
|
-
|
|
668
|
+
backgroundIframe = domElements.backgroundIframe;
|
|
572
669
|
if (!checkoutIframe || !backgroundIframe) {
|
|
573
670
|
reject('No dom element provided');
|
|
574
671
|
}
|
|
575
|
-
|
|
576
672
|
backgroundIframe.style.opacity = 0;
|
|
577
673
|
checkoutIframe.style.display = 'none';
|
|
578
674
|
checkoutIframe.style.visibility = 'hidden';
|
|
@@ -586,7 +682,6 @@ function animateCheckoutOut(domElements) {
|
|
|
586
682
|
}
|
|
587
683
|
function mountLazyInlineButton(options) {
|
|
588
684
|
var inlineButton;
|
|
589
|
-
|
|
590
685
|
if (options.id) {
|
|
591
686
|
inlineButton = document.getElementById(options.id);
|
|
592
687
|
inlineButton.setAttribute('data-inline-id', options.id);
|
|
@@ -595,34 +690,29 @@ function mountLazyInlineButton(options) {
|
|
|
595
690
|
inlineDiv.id = "inline-button-".concat(options.inlineId);
|
|
596
691
|
inlineDiv.innerHTML = generateInlineButtonHTML(options);
|
|
597
692
|
options.parent.parentNode.insertBefore(inlineDiv, options.parent.nextSibling);
|
|
598
|
-
|
|
599
693
|
var _inlineDiv$getElement = inlineDiv.getElementsByTagName('button');
|
|
600
|
-
|
|
601
694
|
var _inlineDiv$getElement2 = _slicedToArray(_inlineDiv$getElement, 1);
|
|
602
|
-
|
|
603
695
|
inlineButton = _inlineDiv$getElement2[0];
|
|
604
696
|
}
|
|
605
|
-
|
|
606
697
|
return inlineButton;
|
|
607
698
|
}
|
|
608
699
|
function animateEmbedCheckoutIn(checkoutIframe) {
|
|
609
700
|
return new Promise(function (resolve, reject) {
|
|
610
701
|
if (!checkoutIframe) {
|
|
611
702
|
reject('No dom element provided');
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
703
|
+
}
|
|
704
|
+
// eslint-disable-next-line no-param-reassign
|
|
705
|
+
checkoutIframe.style.display = '';
|
|
706
|
+
// eslint-disable-next-line no-param-reassign
|
|
617
707
|
checkoutIframe.style.visibility = 'visible';
|
|
618
708
|
resolve();
|
|
619
709
|
});
|
|
620
710
|
}
|
|
621
711
|
function mountInput(options) {
|
|
622
712
|
var type = options.type,
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
713
|
+
value = options.value,
|
|
714
|
+
name = options.name,
|
|
715
|
+
parent = options.parent;
|
|
626
716
|
var input = document.createElement('input');
|
|
627
717
|
input.type = type;
|
|
628
718
|
input.value = value;
|
|
@@ -631,17 +721,15 @@ function mountInput(options) {
|
|
|
631
721
|
}
|
|
632
722
|
function mountApplePayButton(container, _ref2) {
|
|
633
723
|
var styles = _ref2.styles,
|
|
634
|
-
|
|
724
|
+
theme = _ref2.theme;
|
|
635
725
|
var style = document.createElement('style');
|
|
636
726
|
var applePayCSS = generateApplePayCSS(styles);
|
|
637
727
|
style.type = 'text/css';
|
|
638
|
-
|
|
639
728
|
if (style.styleSheet) {
|
|
640
729
|
style.styleSheet.cssText = applePayCSS;
|
|
641
730
|
} else {
|
|
642
731
|
style.appendChild(document.createTextNode(applePayCSS));
|
|
643
732
|
}
|
|
644
|
-
|
|
645
733
|
container.appendChild(style);
|
|
646
734
|
var button = document.createElement('apple-pay-button');
|
|
647
735
|
button.setAttribute('buttonstyle', theme === 'light' ? 'white' : 'black');
|
|
@@ -651,17 +739,15 @@ function mountApplePayButton(container, _ref2) {
|
|
|
651
739
|
}
|
|
652
740
|
function mountApplePayFallbackButton(container, _ref3) {
|
|
653
741
|
var styles = _ref3.styles,
|
|
654
|
-
|
|
742
|
+
theme = _ref3.theme;
|
|
655
743
|
var style = document.createElement('style');
|
|
656
744
|
var applePayCSS = generateApplePayFallbackCSS(styles);
|
|
657
745
|
style.type = 'text/css';
|
|
658
|
-
|
|
659
746
|
if (style.styleSheet) {
|
|
660
747
|
style.styleSheet.cssText = applePayCSS;
|
|
661
748
|
} else {
|
|
662
749
|
style.appendChild(document.createTextNode(applePayCSS));
|
|
663
750
|
}
|
|
664
|
-
|
|
665
751
|
container.appendChild(style);
|
|
666
752
|
var button = document.createElement('button');
|
|
667
753
|
button.classList.add('apple-pay-button', theme === 'light' ? 'apple-pay-button-white' : 'apple-pay-button-black');
|
|
@@ -674,100 +760,47 @@ function mountApplePayFallbackButton(container, _ref3) {
|
|
|
674
760
|
function getPaymentRequestContainer(container) {
|
|
675
761
|
return document.querySelector("#".concat(container));
|
|
676
762
|
}
|
|
677
|
-
function mountPaymentRequestButtons(container, _ref4
|
|
763
|
+
function mountPaymentRequestButtons(container, _ref4) {
|
|
678
764
|
var _ref4$channels = _ref4.channels,
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
765
|
+
channels = _ref4$channels === void 0 ? [] : _ref4$channels,
|
|
766
|
+
_ref4$styles = _ref4.styles,
|
|
767
|
+
styles = _ref4$styles === void 0 ? {} : _ref4$styles;
|
|
682
768
|
var mountedElements = {
|
|
683
769
|
applePay: false
|
|
684
770
|
};
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
unsupported = (capabilities === null || capabilities === void 0 ? void 0 : capabilities.paymentCredentialStatus) === 'applePayUnsupported';
|
|
715
|
-
|
|
716
|
-
if (!unsupported) {
|
|
717
|
-
_context.next = 7;
|
|
718
|
-
break;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
throw new Error('Apple Pay is not supported on this device');
|
|
722
|
-
|
|
723
|
-
case 7:
|
|
724
|
-
_context.next = 15;
|
|
725
|
-
break;
|
|
726
|
-
|
|
727
|
-
case 9:
|
|
728
|
-
_context.prev = 9;
|
|
729
|
-
_context.t0 = _context["catch"](0);
|
|
730
|
-
|
|
731
|
-
if (!(_context.t0.message === 'Apple Pay is not supported on this device')) {
|
|
732
|
-
_context.next = 13;
|
|
733
|
-
break;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
throw _context.t0;
|
|
737
|
-
|
|
738
|
-
case 13:
|
|
739
|
-
if ((_window$ApplePaySessi2 = window.ApplePaySession) !== null && _window$ApplePaySessi2 !== void 0 && (_window$ApplePaySessi3 = _window$ApplePaySessi2.canMakePayments) !== null && _window$ApplePaySessi3 !== void 0 && _window$ApplePaySessi3.call(_window$ApplePaySessi2)) {
|
|
740
|
-
_context.next = 15;
|
|
741
|
-
break;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
throw new Error('Apple Pay is not supported on this device');
|
|
745
|
-
|
|
746
|
-
case 15:
|
|
747
|
-
mountApplePayButton(container, {
|
|
748
|
-
styles: parseApplePayCustomStyles(styles.applePay),
|
|
749
|
-
theme: styles.theme
|
|
750
|
-
});
|
|
751
|
-
mountedElements.applePay = true;
|
|
752
|
-
resolve(mountedElements);
|
|
753
|
-
|
|
754
|
-
case 18:
|
|
755
|
-
case "end":
|
|
756
|
-
return _context.stop();
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}, _callee, null, [[0, 9]]);
|
|
760
|
-
}))).catch(function () {
|
|
761
|
-
mountApplePayFallbackButton(container, {
|
|
762
|
-
styles: parseApplePayCustomStyles(styles.applePay),
|
|
763
|
-
theme: styles.theme
|
|
764
|
-
});
|
|
765
|
-
mountedElements.applePay = true;
|
|
766
|
-
resolve(mountedElements);
|
|
771
|
+
if (!container) {
|
|
772
|
+
return Promise.reject(new Error('Container to mount elements was not provided'));
|
|
773
|
+
}
|
|
774
|
+
if (!channels.includes('apple_pay')) {
|
|
775
|
+
return Promise.reject(new Error('No wallet payment method is available on this device'));
|
|
776
|
+
}
|
|
777
|
+
return ensureApplePaySdkLoaded(container).catch(function () {
|
|
778
|
+
// Safari can still render the fallback button using the native ApplePaySession.
|
|
779
|
+
return null;
|
|
780
|
+
}).then(function () {
|
|
781
|
+
return canUseApplePay(channels);
|
|
782
|
+
}).then(function (applePayAvailable) {
|
|
783
|
+
if (!applePayAvailable) {
|
|
784
|
+
throw new Error('No wallet payment method is available on this device');
|
|
785
|
+
}
|
|
786
|
+
if (getApplePayButton(container)) {
|
|
787
|
+
mountedElements.applePay = true;
|
|
788
|
+
return mountedElements;
|
|
789
|
+
}
|
|
790
|
+
try {
|
|
791
|
+
mountApplePayButton(container, {
|
|
792
|
+
styles: parseApplePayCustomStyles(styles.applePay),
|
|
793
|
+
theme: styles.theme
|
|
794
|
+
});
|
|
795
|
+
} catch (error) {
|
|
796
|
+
// If the web component is unavailable, fall back to the CSS-based Apple Pay button.
|
|
797
|
+
mountApplePayFallbackButton(container, {
|
|
798
|
+
styles: parseApplePayCustomStyles(styles.applePay),
|
|
799
|
+
theme: styles.theme
|
|
767
800
|
});
|
|
768
|
-
} else {
|
|
769
|
-
reject('Container to mount elements was not provided');
|
|
770
801
|
}
|
|
802
|
+
mountedElements.applePay = true;
|
|
803
|
+
return mountedElements;
|
|
771
804
|
});
|
|
772
805
|
}
|
|
773
806
|
function removeAllChildNodes(parent) {
|
|
@@ -780,7 +813,6 @@ var preCheckoutModalButtonId = {
|
|
|
780
813
|
PAYSTACK_POP_BUTTON: 'paystackpop-button',
|
|
781
814
|
PAY_WITH_VAULT_BUTTON: 'pay-with-vault-button'
|
|
782
815
|
};
|
|
783
|
-
|
|
784
816
|
function createOpenPaystackPopButton(buttonText) {
|
|
785
817
|
var openPaystackPopButton = document.createElement('button');
|
|
786
818
|
openPaystackPopButton.id = preCheckoutModalButtonId.PAYSTACK_POP_BUTTON;
|
|
@@ -788,17 +820,14 @@ function createOpenPaystackPopButton(buttonText) {
|
|
|
788
820
|
openPaystackPopButton.innerText = buttonText;
|
|
789
821
|
return openPaystackPopButton;
|
|
790
822
|
}
|
|
791
|
-
|
|
792
823
|
function getPreCheckoutModalOpenPaystackPopButton(modal) {
|
|
793
824
|
return modal.querySelector("#".concat(preCheckoutModalButtonId.PAYSTACK_POP_BUTTON));
|
|
794
825
|
}
|
|
795
|
-
|
|
796
826
|
function createPaymentRequestContainer() {
|
|
797
827
|
var paymentRequestContainer = document.createElement('div');
|
|
798
828
|
paymentRequestContainer.id = preCheckoutModalButtonId.PAYMENT_REQUEST_BUTTON;
|
|
799
829
|
return paymentRequestContainer;
|
|
800
830
|
}
|
|
801
|
-
|
|
802
831
|
function getPreCheckoutModalPaymentRequestContainer(modal) {
|
|
803
832
|
return modal.querySelector("#".concat(preCheckoutModalButtonId.PAYMENT_REQUEST_BUTTON));
|
|
804
833
|
}
|
|
@@ -806,7 +835,6 @@ function removePreCheckoutModalPaymentRequestContainer(modal) {
|
|
|
806
835
|
var paymentRequestContainer = getPreCheckoutModalPaymentRequestContainer(modal);
|
|
807
836
|
paymentRequestContainer.remove();
|
|
808
837
|
}
|
|
809
|
-
|
|
810
838
|
function createPayWithVaultButton() {
|
|
811
839
|
var payWithVaultButton = document.createElement('button');
|
|
812
840
|
payWithVaultButton.className = 'pay-with-vault-button';
|
|
@@ -814,11 +842,9 @@ function createPayWithVaultButton() {
|
|
|
814
842
|
payWithVaultButton.innerText = 'Pay with Vault';
|
|
815
843
|
return payWithVaultButton;
|
|
816
844
|
}
|
|
817
|
-
|
|
818
845
|
function getPreCheckoutModalPayWithVaultButton(modal) {
|
|
819
846
|
return modal.querySelector("#".concat(preCheckoutModalButtonId.PAY_WITH_VAULT_BUTTON));
|
|
820
847
|
}
|
|
821
|
-
|
|
822
848
|
function vaultPreCheckoutModalView(container) {
|
|
823
849
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
824
850
|
var logoContainer = document.createElement('div');
|
|
@@ -836,20 +862,17 @@ function vaultPreCheckoutModalView(container) {
|
|
|
836
862
|
divider.className = 'vault-divider';
|
|
837
863
|
divider.innerHTML = '<div id="vault-divider" class="vault-divider__container"><div class="vault-divider__line"></div></div><div class="vault-divider__text-container"><span class="vault-divider__text">or</span></div>';
|
|
838
864
|
container.appendChild(divider);
|
|
839
|
-
|
|
840
865
|
if (options.canPayWithApplePay) {
|
|
841
866
|
var paymentRequestContainer = createPaymentRequestContainer();
|
|
842
867
|
container.appendChild(paymentRequestContainer);
|
|
843
868
|
}
|
|
844
|
-
|
|
845
869
|
if (options.hasOtherPaymentMethods) {
|
|
846
870
|
var openPaystackPopButton = createOpenPaystackPopButton('Use other payment methods');
|
|
847
871
|
container.appendChild(openPaystackPopButton);
|
|
848
872
|
}
|
|
849
873
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
var hasOtherPaymentMethods = _ref6.hasOtherPaymentMethods;
|
|
874
|
+
function defaultPreCheckoutModalView(container, _ref5) {
|
|
875
|
+
var hasOtherPaymentMethods = _ref5.hasOtherPaymentMethods;
|
|
853
876
|
var applePayIcon = document.createElement('div');
|
|
854
877
|
applePayIcon.innerHTML = applePayMarkLight;
|
|
855
878
|
container.appendChild(applePayIcon);
|
|
@@ -859,31 +882,25 @@ function defaultPreCheckoutModalView(container, _ref6) {
|
|
|
859
882
|
container.appendChild(instruction);
|
|
860
883
|
var paymentRequestContainer = createPaymentRequestContainer();
|
|
861
884
|
container.appendChild(paymentRequestContainer);
|
|
862
|
-
|
|
863
885
|
if (hasOtherPaymentMethods) {
|
|
864
886
|
var openPaystackPopButton = createOpenPaystackPopButton('More payment options');
|
|
865
887
|
container.appendChild(openPaystackPopButton);
|
|
866
888
|
}
|
|
867
889
|
}
|
|
868
|
-
|
|
869
890
|
function hasNonPrecheckoutPaymentMethods(channels) {
|
|
870
891
|
return channels.some(function (channel) {
|
|
871
892
|
return channel !== 'apple_pay';
|
|
872
893
|
});
|
|
873
894
|
}
|
|
874
|
-
|
|
875
895
|
function mountPreCheckoutModal(id, transaction) {
|
|
876
896
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
877
897
|
var mountedModal = document.querySelector("#pre-checkout-modal-".concat(id));
|
|
878
|
-
|
|
879
898
|
if (mountedModal) {
|
|
880
899
|
if (getPreCheckoutModalOpenPaystackPopButton(mountedModal) && getPreCheckoutModalPaymentRequestContainer(mountedModal)) {
|
|
881
900
|
return mountedModal;
|
|
882
901
|
}
|
|
883
|
-
|
|
884
902
|
mountedModal.remove();
|
|
885
903
|
}
|
|
886
|
-
|
|
887
904
|
var modal = document.createElement('div');
|
|
888
905
|
modal.classList.add('pre-checkout-modal');
|
|
889
906
|
modal.id = "pre-checkout-modal-".concat(id);
|
|
@@ -891,16 +908,14 @@ function mountPreCheckoutModal(id, transaction) {
|
|
|
891
908
|
var content = document.createElement('div');
|
|
892
909
|
content.classList.add('pre-checkout-modal__content');
|
|
893
910
|
modal.appendChild(content);
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
channels = _ref7.channels;
|
|
903
|
-
|
|
911
|
+
var _ref6 = transaction || {},
|
|
912
|
+
merchantLogo = _ref6.merchant_logo,
|
|
913
|
+
merchantName = _ref6.merchant_name,
|
|
914
|
+
email = _ref6.email,
|
|
915
|
+
amount = _ref6.amount,
|
|
916
|
+
currency = _ref6.currency,
|
|
917
|
+
label = _ref6.label,
|
|
918
|
+
channels = _ref6.channels;
|
|
904
919
|
var formattedAmount = new Intl.NumberFormat('en', {
|
|
905
920
|
style: 'currency',
|
|
906
921
|
currency: currency,
|
|
@@ -915,7 +930,6 @@ function mountPreCheckoutModal(id, transaction) {
|
|
|
915
930
|
content.innerHTML += closeButton;
|
|
916
931
|
var wrapper = document.createElement('div');
|
|
917
932
|
wrapper.classList.add('modal-wrapper');
|
|
918
|
-
|
|
919
933
|
if (options.canPayWithVault) {
|
|
920
934
|
vaultPreCheckoutModalView(wrapper, {
|
|
921
935
|
canPayWithApplePay: options.canPayWithApplePay,
|
|
@@ -926,7 +940,6 @@ function mountPreCheckoutModal(id, transaction) {
|
|
|
926
940
|
hasOtherPaymentMethods: hasNonPrecheckoutPaymentMethods(channels)
|
|
927
941
|
});
|
|
928
942
|
}
|
|
929
|
-
|
|
930
943
|
wrapper.innerHTML = wrapper.innerHTML + secureByPaystackWhite + secureByPaystackGrey;
|
|
931
944
|
content.appendChild(wrapper);
|
|
932
945
|
var style = document.createElement('style');
|
|
@@ -963,7 +976,6 @@ function showErrorInPreCheckoutModal(modal) {
|
|
|
963
976
|
if (!modal) {
|
|
964
977
|
return;
|
|
965
978
|
}
|
|
966
|
-
|
|
967
979
|
var appleIcon = modal.querySelector('#apple-pay-mark--light');
|
|
968
980
|
appleIcon.innerHTML = errorIcon;
|
|
969
981
|
var applePayDescription = modal.querySelector('#apple-pay-description');
|
|
@@ -1200,33 +1212,32 @@ function validate(args) {
|
|
|
1200
1212
|
this.message = message;
|
|
1201
1213
|
this.issues = issues || [];
|
|
1202
1214
|
}
|
|
1203
|
-
|
|
1204
1215
|
if (!args || _typeof(args) !== 'object') {
|
|
1205
1216
|
throw new ValidationError('Transaction parameters should be a non-empty object');
|
|
1206
1217
|
}
|
|
1218
|
+
var transactionParameters = args;
|
|
1207
1219
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1220
|
+
// If it's a transaction resumption, move on
|
|
1210
1221
|
if ('accessCode' in transactionParameters) {
|
|
1211
1222
|
var accessCode = transactionParameters.accessCode;
|
|
1212
1223
|
return {
|
|
1213
1224
|
accessCode: accessCode
|
|
1214
1225
|
};
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1226
|
+
}
|
|
1217
1227
|
|
|
1228
|
+
// Filter unneeded parameters
|
|
1218
1229
|
Object.keys(transactionParameters).forEach(function (key) {
|
|
1219
1230
|
var usedParameter = allParameters.find(function (parameter) {
|
|
1220
1231
|
return parameter.value === key;
|
|
1221
1232
|
}) !== undefined;
|
|
1222
|
-
|
|
1223
1233
|
if (!usedParameter) {
|
|
1224
1234
|
delete transactionParameters[key];
|
|
1225
1235
|
}
|
|
1226
1236
|
});
|
|
1227
1237
|
var transactionKeys = Object.keys(transactionParameters);
|
|
1228
|
-
var validationErrors = [];
|
|
1238
|
+
var validationErrors = [];
|
|
1229
1239
|
|
|
1240
|
+
// Check for required parameters
|
|
1230
1241
|
var requiredParameters = allParameters.filter(function (param) {
|
|
1231
1242
|
return param.required;
|
|
1232
1243
|
});
|
|
@@ -1235,50 +1246,44 @@ function validate(args) {
|
|
|
1235
1246
|
var parameterHasAlternative = key.or ? key.or.some(function (option) {
|
|
1236
1247
|
return transactionParameters[option];
|
|
1237
1248
|
}) : null;
|
|
1238
|
-
|
|
1239
1249
|
if (parameterIsMissing && !parameterHasAlternative) {
|
|
1240
1250
|
validationErrors.push({
|
|
1241
1251
|
message: "Required parameter missing: ".concat(key.value)
|
|
1242
1252
|
});
|
|
1243
1253
|
}
|
|
1244
|
-
});
|
|
1254
|
+
});
|
|
1245
1255
|
|
|
1256
|
+
// Check for validity
|
|
1246
1257
|
transactionKeys.forEach(function (key) {
|
|
1247
1258
|
var parameterValue = transactionParameters[key];
|
|
1248
1259
|
var parameterObject = allParameters.find(function (parameter) {
|
|
1249
1260
|
return parameter.value === key;
|
|
1250
1261
|
});
|
|
1251
|
-
|
|
1252
1262
|
var providedType = _typeof(parameterValue);
|
|
1253
|
-
|
|
1254
1263
|
if (providedType === 'object' && Array.isArray(parameterValue)) {
|
|
1255
1264
|
providedType = 'array';
|
|
1256
1265
|
}
|
|
1257
|
-
|
|
1258
1266
|
var invalidType = parameterObject.types.indexOf(providedType) <= -1;
|
|
1259
|
-
|
|
1260
1267
|
if (invalidType) {
|
|
1261
1268
|
validationErrors.push({
|
|
1262
1269
|
message: "Invalid parameter type: ".concat(key),
|
|
1263
1270
|
validTypes: parameterObject.types
|
|
1264
1271
|
});
|
|
1265
1272
|
}
|
|
1266
|
-
});
|
|
1273
|
+
});
|
|
1267
1274
|
|
|
1275
|
+
// Override keys where necessary
|
|
1268
1276
|
transactionKeys.forEach(function (key) {
|
|
1269
1277
|
var parameterObject = allParameters.find(function (parameter) {
|
|
1270
1278
|
return parameter.value === key;
|
|
1271
1279
|
});
|
|
1272
|
-
|
|
1273
1280
|
if (parameterObject.override) {
|
|
1274
1281
|
delete transactionParameters[parameterObject.override];
|
|
1275
1282
|
}
|
|
1276
1283
|
});
|
|
1277
|
-
|
|
1278
1284
|
if (validationErrors.length) {
|
|
1279
1285
|
throw new ValidationError('Invalid transaction parameters', validationErrors);
|
|
1280
1286
|
}
|
|
1281
|
-
|
|
1282
1287
|
return transactionParameters;
|
|
1283
1288
|
}
|
|
1284
1289
|
|
|
@@ -1287,31 +1292,26 @@ function splitURL(url) {
|
|
|
1287
1292
|
if ((url === null || url === void 0 ? void 0 : url.length) > 500) {
|
|
1288
1293
|
return url.split('?')[0];
|
|
1289
1294
|
}
|
|
1290
|
-
|
|
1291
1295
|
return url;
|
|
1292
1296
|
}
|
|
1293
|
-
|
|
1294
1297
|
function getReferrer() {
|
|
1295
1298
|
var _window$location = window.location,
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1299
|
+
_window$location$href = _window$location.href,
|
|
1300
|
+
href = _window$location$href === void 0 ? '' : _window$location$href,
|
|
1301
|
+
_window$location$ance = _window$location.ancestorOrigins,
|
|
1302
|
+
ancestorOrigins = _window$location$ance === void 0 ? [] : _window$location$ance;
|
|
1300
1303
|
return [href].concat(_toConsumableArray(ancestorOrigins)).map(splitURL).join(',');
|
|
1301
1304
|
}
|
|
1302
1305
|
|
|
1303
1306
|
function buildQuery(parameters) {
|
|
1304
1307
|
var formattedParameters = _objectSpread2({}, parameters);
|
|
1305
|
-
|
|
1306
1308
|
formattedParameters.metadata = parameters.metadata || {};
|
|
1307
1309
|
formattedParameters.metadata.referrer = getReferrer();
|
|
1308
1310
|
formattedParameters.metadata = JSON.stringify(formattedParameters.metadata);
|
|
1309
1311
|
formattedParameters.mode = 'popup';
|
|
1310
|
-
|
|
1311
1312
|
if (parameters.split && typeof parameters.split !== 'string') {
|
|
1312
1313
|
formattedParameters.split = JSON.stringify(formattedParameters.split);
|
|
1313
1314
|
}
|
|
1314
|
-
|
|
1315
1315
|
var parametersToChange = [{
|
|
1316
1316
|
to: 'firstname',
|
|
1317
1317
|
from: 'firstName'
|
|
@@ -1348,21 +1348,20 @@ function buildQuery(parameters) {
|
|
|
1348
1348
|
}, {
|
|
1349
1349
|
to: 'ref',
|
|
1350
1350
|
from: 'reference'
|
|
1351
|
-
}];
|
|
1351
|
+
}];
|
|
1352
|
+
|
|
1353
|
+
// handle very old case of people disabling channels by sending card/bank params
|
|
1352
1354
|
|
|
1353
1355
|
if (formattedParameters.card !== undefined && ['false', false].indexOf(formattedParameters.card) > -1) {
|
|
1354
1356
|
formattedParameters.channels = ['bank'];
|
|
1355
1357
|
delete formattedParameters.card;
|
|
1356
1358
|
}
|
|
1357
|
-
|
|
1358
1359
|
if (formattedParameters.bank !== undefined && ['false', false].indexOf(formattedParameters.bank) > -1) {
|
|
1359
1360
|
formattedParameters.channels = ['card'];
|
|
1360
1361
|
delete formattedParameters.bank;
|
|
1361
1362
|
}
|
|
1362
|
-
|
|
1363
1363
|
parametersToChange.forEach(function (key) {
|
|
1364
1364
|
var hasValue = formattedParameters[key.from];
|
|
1365
|
-
|
|
1366
1365
|
if (hasValue) {
|
|
1367
1366
|
formattedParameters[key.to] = formattedParameters[key.from];
|
|
1368
1367
|
delete formattedParameters[key.from];
|
|
@@ -1378,22 +1377,23 @@ function buildQuery(parameters) {
|
|
|
1378
1377
|
}
|
|
1379
1378
|
|
|
1380
1379
|
/* eslint-env browser */
|
|
1380
|
+
|
|
1381
1381
|
var iOSDevices = ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'];
|
|
1382
|
+
|
|
1382
1383
|
/**
|
|
1383
1384
|
* navigator.platform is deprecated and will eventually be removed
|
|
1384
1385
|
* but the recommended alternative `navigator.userAgentData` has limited browser support
|
|
1385
1386
|
* so it is used as a fallback here.
|
|
1386
1387
|
*/
|
|
1387
|
-
|
|
1388
1388
|
var DEVICE_PLATFORM = window && window.navigator && (window.navigator.platform || window.navigator.userAgentData && window.navigator.userAgentData.platform);
|
|
1389
1389
|
var isIOS = function isIOS() {
|
|
1390
1390
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1391
|
+
platform = _ref.platform,
|
|
1392
|
+
_ref$userAgent = _ref.userAgent,
|
|
1393
|
+
userAgent = _ref$userAgent === void 0 ? window && window.navigator && window.navigator.userAgent : _ref$userAgent;
|
|
1395
1394
|
var devicePlatform = platform || DEVICE_PLATFORM;
|
|
1396
|
-
return iOSDevices.includes(devicePlatform) ||
|
|
1395
|
+
return iOSDevices.includes(devicePlatform) ||
|
|
1396
|
+
// iPAD os safari detection. iPad OS uses the same version of safari as Mac OS
|
|
1397
1397
|
userAgent.includes('Mac') && 'ontouchend' in document;
|
|
1398
1398
|
};
|
|
1399
1399
|
|
|
@@ -1427,11 +1427,10 @@ var AnalyticsAPI = {
|
|
|
1427
1427
|
var AnalyticsFunctions = {
|
|
1428
1428
|
initializeLog: function initializeLog(log) {
|
|
1429
1429
|
var _ref = log || {},
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1430
|
+
attempts = _ref.attempts,
|
|
1431
|
+
authentication = _ref.authentication,
|
|
1432
|
+
errors = _ref.errors,
|
|
1433
|
+
history = _ref.history;
|
|
1435
1434
|
this.log = {
|
|
1436
1435
|
start_time: Math.round(Date.now() / 1000),
|
|
1437
1436
|
time_spent: 0,
|
|
@@ -1453,10 +1452,8 @@ var AnalyticsFunctions = {
|
|
|
1453
1452
|
switch (response.status) {
|
|
1454
1453
|
case 'success':
|
|
1455
1454
|
return this.logApiSuccess(channel);
|
|
1456
|
-
|
|
1457
1455
|
case 'failed':
|
|
1458
1456
|
return this.logApiError(response.message);
|
|
1459
|
-
|
|
1460
1457
|
default:
|
|
1461
1458
|
return false;
|
|
1462
1459
|
}
|
|
@@ -1471,11 +1468,9 @@ var AnalyticsFunctions = {
|
|
|
1471
1468
|
},
|
|
1472
1469
|
logAttempt: function logAttempt(channel) {
|
|
1473
1470
|
var message = 'Attempted to pay';
|
|
1474
|
-
|
|
1475
1471
|
if (channel) {
|
|
1476
1472
|
message += " with ".concat(channel);
|
|
1477
1473
|
}
|
|
1478
|
-
|
|
1479
1474
|
this.log.attempts += 1;
|
|
1480
1475
|
this.log.history.push({
|
|
1481
1476
|
type: 'action',
|
|
@@ -1486,11 +1481,9 @@ var AnalyticsFunctions = {
|
|
|
1486
1481
|
},
|
|
1487
1482
|
logApiError: function logApiError(error) {
|
|
1488
1483
|
var message = 'Error';
|
|
1489
|
-
|
|
1490
1484
|
if (error) {
|
|
1491
1485
|
message += ": ".concat(error);
|
|
1492
1486
|
}
|
|
1493
|
-
|
|
1494
1487
|
this.log.errors += 1;
|
|
1495
1488
|
this.log.history.push({
|
|
1496
1489
|
type: 'error',
|
|
@@ -1501,11 +1494,9 @@ var AnalyticsFunctions = {
|
|
|
1501
1494
|
},
|
|
1502
1495
|
logApiSuccess: function logApiSuccess(channel) {
|
|
1503
1496
|
var message = 'Successfully paid';
|
|
1504
|
-
|
|
1505
1497
|
if (channel) {
|
|
1506
1498
|
message += " with ".concat(channel);
|
|
1507
1499
|
}
|
|
1508
|
-
|
|
1509
1500
|
this.log.success = true;
|
|
1510
1501
|
this.log.history.push({
|
|
1511
1502
|
type: 'success',
|
|
@@ -1519,9 +1510,9 @@ var AnalyticsFunctions = {
|
|
|
1519
1510
|
if (this.response) {
|
|
1520
1511
|
return AnalyticsAPI.saveLog(this.id, this.response.merchant_key, this.log);
|
|
1521
1512
|
}
|
|
1522
|
-
} catch (error) {
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
// we don't need to do anything since this should not affect the transaction
|
|
1523
1515
|
}
|
|
1524
|
-
|
|
1525
1516
|
return undefined;
|
|
1526
1517
|
},
|
|
1527
1518
|
saveIpAddress: function saveIpAddress() {
|
|
@@ -1529,9 +1520,9 @@ var AnalyticsFunctions = {
|
|
|
1529
1520
|
if (this.response) {
|
|
1530
1521
|
return AnalyticsAPI.saveIp(this.id, this.response.merchant_key);
|
|
1531
1522
|
}
|
|
1532
|
-
} catch (error) {
|
|
1523
|
+
} catch (error) {
|
|
1524
|
+
// we don't need to do anything since this should not affect the transaction
|
|
1533
1525
|
}
|
|
1534
|
-
|
|
1535
1526
|
return undefined;
|
|
1536
1527
|
}
|
|
1537
1528
|
};
|
|
@@ -1540,20 +1531,16 @@ var _excluded$1 = ["language", "connect_account"];
|
|
|
1540
1531
|
var TransactionApi = {
|
|
1541
1532
|
requestInline: function requestInline() {
|
|
1542
1533
|
var inlineTransactionInstance = this;
|
|
1543
|
-
|
|
1544
1534
|
var _this$urlParameters = this.urlParameters,
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1535
|
+
language = _this$urlParameters.language,
|
|
1536
|
+
connectAccount = _this$urlParameters.connect_account,
|
|
1537
|
+
params = _objectWithoutProperties(_this$urlParameters, _excluded$1);
|
|
1549
1538
|
var request;
|
|
1550
|
-
|
|
1551
1539
|
var headers = _objectSpread2({
|
|
1552
1540
|
'Content-Type': 'application/json'
|
|
1553
1541
|
}, language && {
|
|
1554
1542
|
'Accept-Language': language
|
|
1555
1543
|
});
|
|
1556
|
-
|
|
1557
1544
|
if (this.accessCode) {
|
|
1558
1545
|
request = fetch(new URL("transaction/verify_access_code/".concat(this.accessCode), config.paystackApiUrl).toString(), {
|
|
1559
1546
|
headers: headers
|
|
@@ -1567,19 +1554,18 @@ var TransactionApi = {
|
|
|
1567
1554
|
})
|
|
1568
1555
|
});
|
|
1569
1556
|
}
|
|
1570
|
-
|
|
1571
1557
|
return request.then(function (res) {
|
|
1572
1558
|
return res.json();
|
|
1573
1559
|
}).then(function (res) {
|
|
1574
1560
|
if (res.status === false) {
|
|
1575
1561
|
throw new Error(res.message);
|
|
1576
1562
|
}
|
|
1577
|
-
|
|
1578
1563
|
inlineTransactionInstance.response = res.data;
|
|
1579
1564
|
inlineTransactionInstance.id = res.data.id;
|
|
1580
1565
|
inlineTransactionInstance.status = res.data.transaction_status;
|
|
1581
|
-
inlineTransactionInstance.accessCode = res.data.access_code;
|
|
1566
|
+
inlineTransactionInstance.accessCode = res.data.access_code;
|
|
1582
1567
|
|
|
1568
|
+
// Analytics
|
|
1583
1569
|
inlineTransactionInstance.log = null;
|
|
1584
1570
|
Object.assign(inlineTransactionInstance, AnalyticsFunctions);
|
|
1585
1571
|
inlineTransactionInstance.initializeLog(res.data.log);
|
|
@@ -1592,7 +1578,6 @@ var TransactionApi = {
|
|
|
1592
1578
|
var InlineTransaction = /*#__PURE__*/function () {
|
|
1593
1579
|
function InlineTransaction(data) {
|
|
1594
1580
|
_classCallCheck(this, InlineTransaction);
|
|
1595
|
-
|
|
1596
1581
|
validate(data);
|
|
1597
1582
|
this.parameters = data;
|
|
1598
1583
|
this.urlParameters = buildQuery(data);
|
|
@@ -1604,12 +1589,12 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1604
1589
|
this.response = null;
|
|
1605
1590
|
this.isActive = true;
|
|
1606
1591
|
var onError = data.onError,
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1592
|
+
onLoad = data.onLoad,
|
|
1593
|
+
onSuccess = data.onSuccess,
|
|
1594
|
+
onCancel = data.onCancel,
|
|
1595
|
+
callback = data.callback,
|
|
1596
|
+
onClose = data.onClose,
|
|
1597
|
+
onBankTransferConfirmationPending = data.onBankTransferConfirmationPending;
|
|
1613
1598
|
this.callbacks = {
|
|
1614
1599
|
onError: onError,
|
|
1615
1600
|
onLoad: onLoad,
|
|
@@ -1623,12 +1608,10 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1623
1608
|
};
|
|
1624
1609
|
Object.assign(this, TransactionApi);
|
|
1625
1610
|
}
|
|
1626
|
-
|
|
1627
|
-
_createClass(InlineTransaction, [{
|
|
1611
|
+
return _createClass(InlineTransaction, [{
|
|
1628
1612
|
key: "onSetupError",
|
|
1629
1613
|
value: function onSetupError(response) {
|
|
1630
1614
|
this.logError(response);
|
|
1631
|
-
|
|
1632
1615
|
if (this.callbacks.onError) {
|
|
1633
1616
|
this.callbacks.onError(response);
|
|
1634
1617
|
}
|
|
@@ -1637,15 +1620,14 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1637
1620
|
key: "onLoad",
|
|
1638
1621
|
value: function onLoad(response) {
|
|
1639
1622
|
var id = response.id,
|
|
1640
|
-
|
|
1641
|
-
|
|
1623
|
+
customer = response.customer,
|
|
1624
|
+
accessCode = response.accessCode;
|
|
1642
1625
|
Object.assign(this, {
|
|
1643
1626
|
id: id,
|
|
1644
1627
|
customer: customer,
|
|
1645
1628
|
accessCode: accessCode
|
|
1646
1629
|
});
|
|
1647
1630
|
this.authorizationUrl = "".concat(config.checkoutUrl).concat(accessCode);
|
|
1648
|
-
|
|
1649
1631
|
if (this.callbacks.onLoad) {
|
|
1650
1632
|
this.callbacks.onLoad({
|
|
1651
1633
|
id: id,
|
|
@@ -1660,12 +1642,10 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1660
1642
|
this.isActive = false;
|
|
1661
1643
|
this.response = response;
|
|
1662
1644
|
this.status = response.status;
|
|
1663
|
-
|
|
1664
1645
|
if (this.callbacks.onSuccess) {
|
|
1665
1646
|
this.callbacks.onSuccess(response);
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1647
|
+
}
|
|
1648
|
+
// Added for backwards compatibility
|
|
1669
1649
|
if (this.deprecatedCallbacks.callback) {
|
|
1670
1650
|
this.deprecatedCallbacks.callback(response);
|
|
1671
1651
|
}
|
|
@@ -1679,10 +1659,9 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1679
1659
|
key: "onCancel",
|
|
1680
1660
|
value: function onCancel() {
|
|
1681
1661
|
if (this.callbacks.onCancel) {
|
|
1682
|
-
this.callbacks.onCancel();
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1662
|
+
this.callbacks.onCancel();
|
|
1663
|
+
}
|
|
1664
|
+
// Added for backwards compatibility
|
|
1686
1665
|
if (this.deprecatedCallbacks.onClose) {
|
|
1687
1666
|
this.deprecatedCallbacks.onClose();
|
|
1688
1667
|
}
|
|
@@ -1697,7 +1676,6 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1697
1676
|
key: "onBankTransferConfirmationPending",
|
|
1698
1677
|
value: function onBankTransferConfirmationPending() {
|
|
1699
1678
|
this.cancel();
|
|
1700
|
-
|
|
1701
1679
|
if (this.callbacks.onBankTransferConfirmationPending) {
|
|
1702
1680
|
this.callbacks.onBankTransferConfirmationPending();
|
|
1703
1681
|
}
|
|
@@ -1708,123 +1686,10 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1708
1686
|
this.errors.push(error);
|
|
1709
1687
|
}
|
|
1710
1688
|
}]);
|
|
1711
|
-
|
|
1712
|
-
return InlineTransaction;
|
|
1713
1689
|
}();
|
|
1714
1690
|
|
|
1715
|
-
var amountSubunitToBase = function amountSubunitToBase() {
|
|
1716
|
-
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
1717
|
-
return Number(parseFloat(amount / 100).toFixed(2));
|
|
1718
|
-
};
|
|
1719
|
-
|
|
1720
|
-
var requestConfig = {
|
|
1721
|
-
headers: {
|
|
1722
|
-
accept: 'application/json, text/plain, */*',
|
|
1723
|
-
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8',
|
|
1724
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
1725
|
-
'sec-ch-ua-mobile': '?0',
|
|
1726
|
-
'sec-fetch-dest': 'empty',
|
|
1727
|
-
'sec-fetch-mode': 'cors',
|
|
1728
|
-
'sec-fetch-site': 'cross-site'
|
|
1729
|
-
},
|
|
1730
|
-
referrerPolicy: 'no-referrer-when-downgrade',
|
|
1731
|
-
method: 'POST',
|
|
1732
|
-
mode: 'cors',
|
|
1733
|
-
credentials: 'omit'
|
|
1734
|
-
};
|
|
1735
|
-
function createFormBody(params) {
|
|
1736
|
-
var formBody = Object.keys(params).reduce(function (formBodyArray, key) {
|
|
1737
|
-
var encodedKey = encodeURIComponent(key);
|
|
1738
|
-
var encodedValue = encodeURIComponent(params[key]);
|
|
1739
|
-
var encodedFormBody = "".concat(encodedKey, "=").concat(encodedValue);
|
|
1740
|
-
return [].concat(_toConsumableArray(formBodyArray), [encodedFormBody]);
|
|
1741
|
-
}, []);
|
|
1742
|
-
return formBody.join('&');
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
var formatIntervalString = function formatIntervalString(interval) {
|
|
1746
|
-
var plans = {
|
|
1747
|
-
biannually: 'BIANNUAL PLAN',
|
|
1748
|
-
annually: 'ANNUAL PLAN'
|
|
1749
|
-
};
|
|
1750
|
-
return plans[interval] || "".concat(interval.toUpperCase(), " PLAN");
|
|
1751
|
-
};
|
|
1752
|
-
|
|
1753
|
-
var generateApplePaymentRequestObject = function generateApplePaymentRequestObject(_ref) {
|
|
1754
|
-
var currency = _ref.currency,
|
|
1755
|
-
amount = _ref.amount,
|
|
1756
|
-
merchantName = _ref.merchantName,
|
|
1757
|
-
interval = _ref.interval;
|
|
1758
|
-
return _objectSpread2({
|
|
1759
|
-
countryCode: 'NG',
|
|
1760
|
-
currencyCode: currency,
|
|
1761
|
-
merchantCapabilities: ['supports3DS', 'supportsCredit', 'supportsDebit'],
|
|
1762
|
-
supportedNetworks: ['visa', 'masterCard'],
|
|
1763
|
-
requiredBillingContactFields: ['postalAddress', 'name', 'phone', 'email'],
|
|
1764
|
-
total: {
|
|
1765
|
-
label: "".concat(merchantName, " - Paystack"),
|
|
1766
|
-
type: 'final',
|
|
1767
|
-
amount: String(amountSubunitToBase(amount))
|
|
1768
|
-
}
|
|
1769
|
-
}, typeof interval === 'string' && interval.trim() !== '' && {
|
|
1770
|
-
lineItems: [{
|
|
1771
|
-
label: formatIntervalString(interval),
|
|
1772
|
-
amount: String(amountSubunitToBase(amount))
|
|
1773
|
-
}]
|
|
1774
|
-
});
|
|
1775
|
-
};
|
|
1776
|
-
var validateApplePaySession = function validateApplePaySession(_ref2) {
|
|
1777
|
-
var transactionId = _ref2.transactionId,
|
|
1778
|
-
validationURL = _ref2.validationURL,
|
|
1779
|
-
merchantName = _ref2.merchantName,
|
|
1780
|
-
_ref2$domainName = _ref2.domainName,
|
|
1781
|
-
domainName = _ref2$domainName === void 0 ? window && window.location && window.location.hostname : _ref2$domainName;
|
|
1782
|
-
var validateSessionUrl = "".concat(config.paymentBaseUrl).concat(config.applePayValidateSessionPath);
|
|
1783
|
-
var params = {
|
|
1784
|
-
transaction: transactionId,
|
|
1785
|
-
sessionUrl: validationURL,
|
|
1786
|
-
displayName: merchantName,
|
|
1787
|
-
domainName: domainName
|
|
1788
|
-
};
|
|
1789
|
-
var formBody = createFormBody(params);
|
|
1790
|
-
var validateSession = fetch(validateSessionUrl, _objectSpread2(_objectSpread2({}, requestConfig), {}, {
|
|
1791
|
-
body: formBody
|
|
1792
|
-
})).then(function (response) {
|
|
1793
|
-
return response.json();
|
|
1794
|
-
});
|
|
1795
|
-
return validateSession;
|
|
1796
|
-
};
|
|
1797
|
-
var chargeApplePay = function chargeApplePay(_ref3) {
|
|
1798
|
-
var transactionId = _ref3.transactionId,
|
|
1799
|
-
payment = _ref3.payment;
|
|
1800
|
-
var chargeApplePayUrl = "".concat(config.paymentBaseUrl).concat(config.applePayChargePath);
|
|
1801
|
-
var params = {
|
|
1802
|
-
transaction: transactionId,
|
|
1803
|
-
paymentObject: JSON.stringify(payment)
|
|
1804
|
-
};
|
|
1805
|
-
var formBody = createFormBody(params);
|
|
1806
|
-
var charge = fetch(chargeApplePayUrl, _objectSpread2(_objectSpread2({}, requestConfig), {}, {
|
|
1807
|
-
body: formBody
|
|
1808
|
-
})).then(function (response) {
|
|
1809
|
-
return response.json();
|
|
1810
|
-
});
|
|
1811
|
-
return charge;
|
|
1812
|
-
};
|
|
1813
|
-
var deviceSupportsApplePay = function deviceSupportsApplePay() {
|
|
1814
|
-
try {
|
|
1815
|
-
return window.location && window.location.protocol === 'https:' && window.ApplePaySession && window.ApplePaySession.supportsVersion(config.applePayVersion);
|
|
1816
|
-
} catch (error) {
|
|
1817
|
-
return false;
|
|
1818
|
-
}
|
|
1819
|
-
};
|
|
1820
|
-
var canUseApplePay = function canUseApplePay() {
|
|
1821
|
-
var channels = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1822
|
-
return deviceSupportsApplePay() && channels.includes('apple_pay');
|
|
1823
|
-
};
|
|
1824
|
-
|
|
1825
1691
|
var canUseVault = function canUseVault() {
|
|
1826
1692
|
var _transaction$link_con, _transaction$link_con2;
|
|
1827
|
-
|
|
1828
1693
|
var transaction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1829
1694
|
return !!((_transaction$link_con = transaction.link_config) !== null && _transaction$link_con !== void 0 && _transaction$link_con.enabled && (_transaction$link_con2 = transaction.link_config) !== null && _transaction$link_con2 !== void 0 && _transaction$link_con2.has_payment_instruments);
|
|
1830
1695
|
};
|
|
@@ -1836,14 +1701,12 @@ function printDeprecationNotice(oldName, newName, extraMessage) {
|
|
|
1836
1701
|
}
|
|
1837
1702
|
|
|
1838
1703
|
var _excluded = ["preload", "inlineTransaction", "transactionData"],
|
|
1839
|
-
|
|
1704
|
+
_excluded2 = ["container", "styles", "onElementsMount"];
|
|
1840
1705
|
var inlineInstance;
|
|
1841
|
-
|
|
1842
1706
|
function findResumableTransaction(transactions, parameters) {
|
|
1843
1707
|
if (!transactions.length) {
|
|
1844
1708
|
return null;
|
|
1845
1709
|
}
|
|
1846
|
-
|
|
1847
1710
|
var similarAbandonedTransactions = transactions.filter(function (transaction) {
|
|
1848
1711
|
var isAbandoned = !transaction.status || transaction.status === 'abandoned';
|
|
1849
1712
|
var hasSimilarParameters = similarObjects(transaction.parameters, parameters);
|
|
@@ -1852,71 +1715,69 @@ function findResumableTransaction(transactions, parameters) {
|
|
|
1852
1715
|
var resumableTransaction = similarAbandonedTransactions.length ? similarAbandonedTransactions[similarAbandonedTransactions.length - 1] : null;
|
|
1853
1716
|
return resumableTransaction;
|
|
1854
1717
|
}
|
|
1855
|
-
|
|
1856
1718
|
function notifyIframeToUpdateURL(options) {
|
|
1857
1719
|
var checkoutIframe = options.checkoutIframe,
|
|
1858
|
-
|
|
1859
|
-
|
|
1720
|
+
urlParameters = options.urlParameters;
|
|
1860
1721
|
if (!checkoutIframe || !urlParameters) {
|
|
1861
1722
|
return;
|
|
1862
1723
|
}
|
|
1863
|
-
|
|
1864
1724
|
checkoutIframe.contentWindow.postMessage({
|
|
1865
1725
|
type: 'inline:url',
|
|
1866
1726
|
path: 'newTransaction',
|
|
1867
1727
|
params: urlParameters
|
|
1868
1728
|
}, '*');
|
|
1869
1729
|
}
|
|
1870
|
-
|
|
1871
1730
|
var analyticsActions = {
|
|
1872
1731
|
TRACK_CHECKOUT_CLOSED: 'trackCheckoutClosed',
|
|
1873
1732
|
TRACK_PAYMENT_ERROR: 'trackPaymentError',
|
|
1874
1733
|
TRACK_PAYMENT_ATTEMPT: 'trackPaymentAttempt',
|
|
1875
1734
|
TRACK_PAYMENT_COMPLETION: 'trackPaymentCompletion'
|
|
1876
1735
|
};
|
|
1877
|
-
|
|
1878
1736
|
function handleError(message) {
|
|
1879
1737
|
logWarning(message);
|
|
1880
1738
|
throw new Error(message);
|
|
1881
1739
|
}
|
|
1882
|
-
|
|
1740
|
+
function transactionCanUseApplePay(response, container) {
|
|
1741
|
+
if (!(response && response.channels && response.channels.includes('apple_pay'))) {
|
|
1742
|
+
return Promise.resolve(false);
|
|
1743
|
+
}
|
|
1744
|
+
return ensureApplePaySdkLoaded(container).catch(function () {
|
|
1745
|
+
// Native Apple Pay support can still be available even if the SDK fails to load.
|
|
1746
|
+
return null;
|
|
1747
|
+
}).then(function () {
|
|
1748
|
+
return canUseApplePay(response.channels);
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1883
1751
|
var Inline = /*#__PURE__*/function () {
|
|
1884
1752
|
function Inline(params) {
|
|
1885
1753
|
_classCallCheck(this, Inline);
|
|
1886
|
-
|
|
1887
1754
|
this.id = randomId();
|
|
1888
1755
|
this.transactions = [];
|
|
1889
1756
|
this.isOpen = false;
|
|
1890
1757
|
this.isLoaded = false;
|
|
1891
1758
|
this.isDeprecatedApi = params && params.isDeprecatedApi; // track deprecatedApi
|
|
1892
|
-
|
|
1893
1759
|
if (params && params.isEmbed) {
|
|
1894
1760
|
this.isEmbed = true;
|
|
1895
1761
|
} else if (params && params.isPaymentRequest) {
|
|
1896
1762
|
if (!(params.container && getPaymentRequestContainer(params.container))) {
|
|
1897
1763
|
handleError('A container is required to mount the payment request button');
|
|
1898
1764
|
}
|
|
1899
|
-
|
|
1900
1765
|
this.paymentRequestContainer = getPaymentRequestContainer(params.container);
|
|
1901
1766
|
this.paymentRequestTransaction = null;
|
|
1902
1767
|
}
|
|
1903
|
-
|
|
1904
1768
|
this.preCheckoutModal = null;
|
|
1905
1769
|
this.backgroundIframe = mountBackgroundIframe(this.id);
|
|
1906
1770
|
this.checkoutIframe = mountCheckoutIframe(this.id);
|
|
1907
1771
|
this.registerListeners();
|
|
1908
1772
|
}
|
|
1909
|
-
|
|
1910
|
-
_createClass(Inline, [{
|
|
1773
|
+
return _createClass(Inline, [{
|
|
1911
1774
|
key: "registerListeners",
|
|
1912
1775
|
value: function registerListeners() {
|
|
1913
1776
|
var _this = this;
|
|
1914
|
-
|
|
1915
1777
|
window.addEventListener('message', function (event) {
|
|
1916
1778
|
var isCheckoutIframe = "".concat(event.origin, "/") === config.checkoutUrl;
|
|
1917
1779
|
var isThisInline = _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
|
|
1918
1780
|
var isEmbed = _this.isEmbed;
|
|
1919
|
-
|
|
1920
1781
|
if (isCheckoutIframe || isThisInline) {
|
|
1921
1782
|
_this.respondToEvent(event);
|
|
1922
1783
|
} else if (isEmbed) {
|
|
@@ -1939,16 +1800,22 @@ var Inline = /*#__PURE__*/function () {
|
|
|
1939
1800
|
if (this.activeTransaction()) {
|
|
1940
1801
|
this.activeTransaction().cancel();
|
|
1941
1802
|
}
|
|
1942
|
-
|
|
1943
1803
|
inlineInstance = this;
|
|
1944
1804
|
var resumableTransaction = findResumableTransaction(this.transactions, params);
|
|
1945
1805
|
var transaction = resumableTransaction || new InlineTransaction(params);
|
|
1946
1806
|
return new Promise(function (resolve, reject) {
|
|
1947
1807
|
transaction.requestInline().then(function (response) {
|
|
1948
|
-
|
|
1808
|
+
return transactionCanUseApplePay(response).then(function (canPayWithApplePay) {
|
|
1809
|
+
return {
|
|
1810
|
+
response: response,
|
|
1811
|
+
canPayWithApplePay: canPayWithApplePay
|
|
1812
|
+
};
|
|
1813
|
+
});
|
|
1814
|
+
}).then(function (_ref) {
|
|
1815
|
+
var response = _ref.response,
|
|
1816
|
+
canPayWithApplePay = _ref.canPayWithApplePay;
|
|
1949
1817
|
var canPayWithVault = canUseVault(response);
|
|
1950
1818
|
var shouldLoadPreCheckoutModal = canPayWithVault || canPayWithApplePay;
|
|
1951
|
-
|
|
1952
1819
|
if (!shouldLoadPreCheckoutModal) {
|
|
1953
1820
|
inlineInstance.newTransaction({
|
|
1954
1821
|
inlineTransaction: transaction,
|
|
@@ -1964,11 +1831,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
1964
1831
|
canPayWithVault: canPayWithVault,
|
|
1965
1832
|
canPayWithApplePay: canPayWithApplePay
|
|
1966
1833
|
});
|
|
1834
|
+
|
|
1967
1835
|
/**
|
|
1968
1836
|
* We attempt to mount the apple pay button only
|
|
1969
1837
|
* when the customer can pay with apple pay.
|
|
1970
1838
|
*/
|
|
1971
|
-
|
|
1972
1839
|
if (canPayWithApplePay) {
|
|
1973
1840
|
inlineInstance.paymentRequestContainer = getPreCheckoutModalPaymentRequestContainer(inlineInstance.preCheckoutModal);
|
|
1974
1841
|
mountPaymentRequestButtons(inlineInstance.paymentRequestContainer, {
|
|
@@ -1983,7 +1850,7 @@ var Inline = /*#__PURE__*/function () {
|
|
|
1983
1850
|
}
|
|
1984
1851
|
}
|
|
1985
1852
|
}, response.merchant_id).then(function () {
|
|
1986
|
-
inlineInstance.registerPaymentRequestEventListeners();
|
|
1853
|
+
return inlineInstance.registerPaymentRequestEventListeners();
|
|
1987
1854
|
}).catch(function () {
|
|
1988
1855
|
/**
|
|
1989
1856
|
* If an error occurs when mounting the apple pay button,
|
|
@@ -2023,15 +1890,12 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2023
1890
|
key: "registerPreCheckoutModalEventListeners",
|
|
2024
1891
|
value: function registerPreCheckoutModalEventListeners() {
|
|
2025
1892
|
var _this2 = this;
|
|
2026
|
-
|
|
2027
1893
|
var timer;
|
|
2028
1894
|
var isShortTouch = false;
|
|
2029
1895
|
var shortTouchDurationInMs = 125;
|
|
2030
1896
|
var activeTransaction = this.activeTransaction();
|
|
2031
|
-
|
|
2032
1897
|
var handleTouchStart = function handleTouchStart(event) {
|
|
2033
1898
|
event.preventDefault();
|
|
2034
|
-
|
|
2035
1899
|
if (!isShortTouch) {
|
|
2036
1900
|
isShortTouch = true;
|
|
2037
1901
|
timer = setTimeout(function () {
|
|
@@ -2039,51 +1903,38 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2039
1903
|
}, shortTouchDurationInMs);
|
|
2040
1904
|
}
|
|
2041
1905
|
};
|
|
2042
|
-
|
|
2043
1906
|
var handleClosePreCheckoutModal = function handleClosePreCheckoutModal(event) {
|
|
2044
1907
|
if (event.target && event.target.isSameNode(inlineInstance.preCheckoutModal) && isShortTouch) {
|
|
2045
1908
|
clearTimeout(timer);
|
|
2046
1909
|
inlineInstance.closePreCheckoutModal();
|
|
2047
|
-
|
|
2048
1910
|
if (activeTransaction) {
|
|
2049
1911
|
activeTransaction.cancel();
|
|
2050
1912
|
}
|
|
2051
1913
|
}
|
|
2052
|
-
|
|
2053
1914
|
isShortTouch = false;
|
|
2054
1915
|
};
|
|
2055
|
-
|
|
2056
1916
|
document.addEventListener('touchstart', handleTouchStart, true);
|
|
2057
1917
|
document.addEventListener('touchend', handleClosePreCheckoutModal, true);
|
|
2058
1918
|
var openPaystackPopButton = getPreCheckoutModalOpenPaystackPopButton(this.preCheckoutModal);
|
|
2059
|
-
|
|
2060
1919
|
if (openPaystackPopButton) {
|
|
2061
1920
|
openPaystackPopButton.onclick = function () {
|
|
2062
1921
|
_this2.closePreCheckoutModal();
|
|
2063
|
-
|
|
2064
1922
|
_this2.animateCheckoutIn();
|
|
2065
1923
|
};
|
|
2066
1924
|
}
|
|
2067
|
-
|
|
2068
1925
|
var payWithVaultButton = getPreCheckoutModalPayWithVaultButton(this.preCheckoutModal);
|
|
2069
|
-
|
|
2070
1926
|
if (payWithVaultButton) {
|
|
2071
1927
|
payWithVaultButton.onclick = function () {
|
|
2072
1928
|
_this2.closePreCheckoutModal();
|
|
2073
|
-
|
|
2074
1929
|
_this2.animateCheckoutIn();
|
|
2075
|
-
|
|
2076
1930
|
_this2.checkoutIframe.contentWindow.postMessage({
|
|
2077
1931
|
type: 'inline:pay-with-vault'
|
|
2078
1932
|
}, '*');
|
|
2079
1933
|
};
|
|
2080
1934
|
}
|
|
2081
|
-
|
|
2082
1935
|
var preCheckoutModalCloseButton = getPreCheckoutModalCloseButton(this.preCheckoutModal);
|
|
2083
|
-
|
|
2084
1936
|
preCheckoutModalCloseButton.onclick = function () {
|
|
2085
1937
|
_this2.sendAnalyticsEventToCheckout(analyticsActions.TRACK_CHECKOUT_CLOSED);
|
|
2086
|
-
|
|
2087
1938
|
_this2.closePreCheckoutModalAndCancelTransaction();
|
|
2088
1939
|
};
|
|
2089
1940
|
}
|
|
@@ -2093,9 +1944,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2093
1944
|
if (!this.preCheckoutModal) {
|
|
2094
1945
|
return;
|
|
2095
1946
|
}
|
|
2096
|
-
|
|
2097
1947
|
if (transactionStatus === 'failed') {
|
|
2098
1948
|
showErrorInPreCheckoutModal(this.preCheckoutModal);
|
|
1949
|
+
animatePreCheckoutModalIn(this.preCheckoutModal);
|
|
2099
1950
|
} else {
|
|
2100
1951
|
hidePreCheckoutModal(this.preCheckoutModal);
|
|
2101
1952
|
this.preCheckoutModal.remove();
|
|
@@ -2107,31 +1958,25 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2107
1958
|
value: function closePreCheckoutModalAndCancelTransaction() {
|
|
2108
1959
|
if (this.preCheckoutModal) {
|
|
2109
1960
|
this.cancelTransaction();
|
|
2110
|
-
|
|
2111
1961
|
if (this.checkoutIframe && this.checkoutIframe.contentWindow) {
|
|
2112
1962
|
this.checkoutIframe.contentWindow.postMessage('close', '*');
|
|
2113
1963
|
}
|
|
2114
|
-
|
|
2115
1964
|
this.closePreCheckoutModal();
|
|
2116
1965
|
}
|
|
2117
1966
|
}
|
|
2118
1967
|
}, {
|
|
2119
1968
|
key: "newTransaction",
|
|
2120
|
-
value: function newTransaction(
|
|
2121
|
-
var preload =
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
1969
|
+
value: function newTransaction(_ref2) {
|
|
1970
|
+
var preload = _ref2.preload,
|
|
1971
|
+
inlineTransaction = _ref2.inlineTransaction,
|
|
1972
|
+
transactionData = _ref2.transactionData,
|
|
1973
|
+
options = _objectWithoutProperties(_ref2, _excluded);
|
|
2126
1974
|
var hasPaymentRequestButtons = this.paymentRequestContainer && getApplePayButton(this.paymentRequestContainer);
|
|
2127
|
-
|
|
2128
1975
|
if (this.activeTransaction() && !hasPaymentRequestButtons) {
|
|
2129
1976
|
this.activeTransaction().cancel();
|
|
2130
1977
|
}
|
|
2131
|
-
|
|
2132
1978
|
if (inlineTransaction && transactionData) {
|
|
2133
1979
|
this.transactions.push(inlineTransaction);
|
|
2134
|
-
|
|
2135
1980
|
if (!this.isDeprecatedApi) {
|
|
2136
1981
|
// TODO: reintroduce this when we resolve checkout caching issues
|
|
2137
1982
|
// this.open({ transactionData }, preload);
|
|
@@ -2140,15 +1985,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2140
1985
|
language: inlineTransaction.urlParameters.language
|
|
2141
1986
|
}, preload);
|
|
2142
1987
|
}
|
|
2143
|
-
|
|
2144
1988
|
return inlineTransaction;
|
|
2145
1989
|
}
|
|
2146
|
-
|
|
2147
1990
|
var resumableTransaction = findResumableTransaction(this.transactions, inlineTransaction ? inlineTransaction.parameters : options);
|
|
2148
|
-
|
|
2149
1991
|
if (resumableTransaction) {
|
|
2150
1992
|
resumableTransaction.isActive = true;
|
|
2151
|
-
|
|
2152
1993
|
if (!this.isDeprecatedApi) {
|
|
2153
1994
|
// We could potentially optimize this also by checking if there is a `response` property on `resumableTransaction`
|
|
2154
1995
|
this.open({
|
|
@@ -2156,77 +1997,47 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2156
1997
|
language: resumableTransaction.urlParameters.language
|
|
2157
1998
|
}, preload);
|
|
2158
1999
|
}
|
|
2159
|
-
|
|
2160
2000
|
return resumableTransaction;
|
|
2161
2001
|
}
|
|
2162
|
-
|
|
2163
2002
|
var transaction = inlineTransaction || new InlineTransaction(options);
|
|
2164
2003
|
var params = transaction.accessCode ? {
|
|
2165
2004
|
accessCode: transaction.accessCode,
|
|
2166
2005
|
language: transaction.urlParameters.language
|
|
2167
2006
|
} : transaction.urlParameters;
|
|
2168
2007
|
this.transactions.push(transaction);
|
|
2169
|
-
|
|
2170
2008
|
if (!this.isDeprecatedApi) {
|
|
2171
2009
|
this.open(params, preload);
|
|
2172
2010
|
}
|
|
2173
|
-
|
|
2174
2011
|
return transaction;
|
|
2175
2012
|
}
|
|
2176
2013
|
}, {
|
|
2177
2014
|
key: "preloadTransaction",
|
|
2178
2015
|
value: function preloadTransaction(options) {
|
|
2179
2016
|
var _this3 = this;
|
|
2180
|
-
|
|
2181
2017
|
this.newTransaction(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
2182
2018
|
preload: true
|
|
2183
2019
|
}));
|
|
2184
|
-
|
|
2185
2020
|
var loadPopup = function loadPopup() {
|
|
2186
2021
|
return _this3.animateCheckoutIn();
|
|
2187
2022
|
};
|
|
2188
|
-
|
|
2189
2023
|
return loadPopup;
|
|
2190
2024
|
}
|
|
2191
2025
|
}, {
|
|
2192
2026
|
key: "paymentRequest",
|
|
2193
2027
|
value: function paymentRequest(parameters) {
|
|
2194
2028
|
var container = parameters.container,
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2029
|
+
styles = parameters.styles,
|
|
2030
|
+
onElementsMount = parameters.onElementsMount,
|
|
2031
|
+
transactionParams = _objectWithoutProperties(parameters, _excluded2);
|
|
2199
2032
|
inlineInstance = this;
|
|
2200
2033
|
return new Promise(function (resolve, reject) {
|
|
2201
2034
|
var loadPaystackCheckoutButton = document.querySelector("#".concat(parameters.loadPaystackCheckoutButton));
|
|
2202
|
-
|
|
2203
|
-
if (!deviceSupportsApplePay()) {
|
|
2204
|
-
if (parameters && parameters.loadPaystackCheckoutButton) {
|
|
2205
|
-
if (loadPaystackCheckoutButton) {
|
|
2206
|
-
var loadPopup = inlineInstance.preloadTransaction(transactionParams);
|
|
2207
|
-
loadPaystackCheckoutButton.onclick = loadPopup;
|
|
2208
|
-
} else {
|
|
2209
|
-
logWarning("This device does not support any payment request wallet options. Please consult our documentation at https://developers.paystack.co/docs/paystack-inline to see how to load alternative payment options using 'loadPaystackCheckoutButton'");
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
|
-
if (onElementsMount) {
|
|
2214
|
-
onElementsMount(null);
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
var activeTransaction = inlineInstance.activeTransaction();
|
|
2218
|
-
resolve(activeTransaction);
|
|
2219
|
-
return;
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
2035
|
if (inlineInstance.activeTransaction()) {
|
|
2223
2036
|
inlineInstance.activeTransaction().cancel();
|
|
2224
2037
|
}
|
|
2225
|
-
|
|
2226
2038
|
if (!(container && getPaymentRequestContainer(container))) {
|
|
2227
2039
|
handleError('A container is required to mount the payment request button');
|
|
2228
2040
|
}
|
|
2229
|
-
|
|
2230
2041
|
inlineInstance.paymentRequestContainer = getPaymentRequestContainer(container);
|
|
2231
2042
|
var resumableTransaction = findResumableTransaction(inlineInstance.transactions, transactionParams);
|
|
2232
2043
|
var transaction = resumableTransaction || new InlineTransaction(transactionParams);
|
|
@@ -2248,18 +2059,14 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2248
2059
|
} else {
|
|
2249
2060
|
inlineInstance.transactions.push(transaction);
|
|
2250
2061
|
}
|
|
2251
|
-
|
|
2252
2062
|
inlineInstance.registerPaymentRequestEventListeners();
|
|
2253
|
-
|
|
2254
2063
|
if (loadPaystackCheckoutButton) {
|
|
2255
|
-
var
|
|
2064
|
+
var loadPopup = inlineInstance.preloadTransaction({
|
|
2256
2065
|
inlineTransaction: transaction,
|
|
2257
2066
|
transactionData: response
|
|
2258
2067
|
});
|
|
2259
|
-
|
|
2260
|
-
loadPaystackCheckoutButton.onclick = _loadPopup;
|
|
2068
|
+
loadPaystackCheckoutButton.onclick = loadPopup;
|
|
2261
2069
|
}
|
|
2262
|
-
|
|
2263
2070
|
resolve(transaction);
|
|
2264
2071
|
});
|
|
2265
2072
|
}).catch(function (error) {
|
|
@@ -2275,25 +2082,21 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2275
2082
|
key: "registerApplePayEventListener",
|
|
2276
2083
|
value: function registerApplePayEventListener() {
|
|
2277
2084
|
var _this4 = this;
|
|
2278
|
-
|
|
2279
2085
|
var applePayButton = getApplePayButton(this.paymentRequestContainer);
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2086
|
+
if (applePayButton) {
|
|
2087
|
+
applePayButton.onclick = function () {
|
|
2088
|
+
return _this4.startApplePay();
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2284
2091
|
}
|
|
2285
2092
|
}, {
|
|
2286
2093
|
key: "registerPaymentRequestEventListeners",
|
|
2287
2094
|
value: function registerPaymentRequestEventListeners() {
|
|
2288
2095
|
var transaction = this.activeTransaction();
|
|
2289
|
-
|
|
2290
|
-
if (transaction) {
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
} else {
|
|
2294
|
-
removeAllChildNodes(this.paymentRequestContainer);
|
|
2295
|
-
}
|
|
2296
|
-
} else {
|
|
2096
|
+
var applePayButton = this.paymentRequestContainer && getApplePayButton(this.paymentRequestContainer);
|
|
2097
|
+
if (transaction && applePayButton) {
|
|
2098
|
+
this.registerApplePayEventListener();
|
|
2099
|
+
} else if (this.paymentRequestContainer) {
|
|
2297
2100
|
removeAllChildNodes(this.paymentRequestContainer);
|
|
2298
2101
|
}
|
|
2299
2102
|
}
|
|
@@ -2301,10 +2104,8 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2301
2104
|
key: "startApplePay",
|
|
2302
2105
|
value: function startApplePay() {
|
|
2303
2106
|
var _this5 = this;
|
|
2304
|
-
|
|
2305
2107
|
var paymentMethod = 'apple pay';
|
|
2306
2108
|
var transaction = this.activeTransaction();
|
|
2307
|
-
|
|
2308
2109
|
if (transaction) {
|
|
2309
2110
|
var paymentAttemptAnalyticsPayload = {
|
|
2310
2111
|
channel: 'apple_pay',
|
|
@@ -2318,7 +2119,7 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2318
2119
|
amount: transaction.amount,
|
|
2319
2120
|
timeSpent: transaction.getTimeSpent()
|
|
2320
2121
|
};
|
|
2321
|
-
|
|
2122
|
+
var pendingPreCheckoutModalStatus = null;
|
|
2322
2123
|
try {
|
|
2323
2124
|
transaction.logAttempt(paymentMethod);
|
|
2324
2125
|
this.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ATTEMPT, paymentAttemptAnalyticsPayload);
|
|
@@ -2329,9 +2130,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2329
2130
|
interval: transaction.response.plan_details && transaction.response.plan_details.interval
|
|
2330
2131
|
});
|
|
2331
2132
|
var applePaySession = new window.ApplePaySession(config.applePayVersion, applePayPaymentRequest);
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2133
|
+
if (inlineInstance.preCheckoutModal) {
|
|
2134
|
+
hidePreCheckoutModal(inlineInstance.preCheckoutModal);
|
|
2135
|
+
}
|
|
2136
|
+
applePaySession.onvalidatemerchant = function (_ref3) {
|
|
2137
|
+
var validationURL = _ref3.validationURL;
|
|
2335
2138
|
var validateSession = validateApplePaySession({
|
|
2336
2139
|
validationURL: validationURL,
|
|
2337
2140
|
transactionId: transaction.id,
|
|
@@ -2340,63 +2143,66 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2340
2143
|
validateSession.then(function (response) {
|
|
2341
2144
|
if (response.status !== 'success') {
|
|
2342
2145
|
transaction.onSetupError(response);
|
|
2146
|
+
pendingPreCheckoutModalStatus = 'failed';
|
|
2343
2147
|
} else {
|
|
2344
2148
|
applePaySession.completeMerchantValidation(response.data);
|
|
2345
2149
|
}
|
|
2346
|
-
|
|
2347
2150
|
transaction.logValidationResponse(response.message);
|
|
2348
2151
|
}).catch(function (error) {
|
|
2349
2152
|
transaction.onSetupError(error);
|
|
2153
|
+
pendingPreCheckoutModalStatus = 'failed';
|
|
2350
2154
|
});
|
|
2351
2155
|
};
|
|
2352
|
-
|
|
2353
2156
|
applePaySession.oncancel = function () {
|
|
2354
|
-
if (
|
|
2157
|
+
if (inlineInstance.preCheckoutModal) {
|
|
2158
|
+
if (pendingPreCheckoutModalStatus) {
|
|
2159
|
+
inlineInstance.closePreCheckoutModal(pendingPreCheckoutModalStatus);
|
|
2160
|
+
pendingPreCheckoutModalStatus = null;
|
|
2161
|
+
} else {
|
|
2162
|
+
animatePreCheckoutModalIn(inlineInstance.preCheckoutModal);
|
|
2163
|
+
}
|
|
2164
|
+
} else {
|
|
2355
2165
|
transaction.onCancel();
|
|
2356
2166
|
}
|
|
2357
2167
|
};
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
var payment = _ref3.payment;
|
|
2168
|
+
applePaySession.onpaymentauthorized = function (_ref4) {
|
|
2169
|
+
var payment = _ref4.payment;
|
|
2361
2170
|
var charge = chargeApplePay({
|
|
2362
2171
|
transactionId: transaction.id,
|
|
2363
2172
|
payment: payment
|
|
2364
2173
|
});
|
|
2365
2174
|
charge.then(function (response) {
|
|
2366
2175
|
transaction.logAPIResponse(response, paymentMethod);
|
|
2367
|
-
|
|
2368
2176
|
if (response.status === 'success') {
|
|
2369
2177
|
applePaySession.completePayment(applePaySession.STATUS_SUCCESS);
|
|
2370
2178
|
transaction.onSuccess(response);
|
|
2371
|
-
|
|
2372
2179
|
_this5.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_COMPLETION, paymentCompleteAnalyticsPayload);
|
|
2373
2180
|
} else {
|
|
2374
2181
|
applePaySession.completePayment(applePaySession.STATUS_FAILURE);
|
|
2375
2182
|
transaction.onSetupError(response);
|
|
2376
|
-
|
|
2183
|
+
pendingPreCheckoutModalStatus = 'failed';
|
|
2377
2184
|
_this5.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2378
2185
|
channel: 'apple_pay',
|
|
2379
2186
|
message: response && response.message || 'Transaction attempt failed'
|
|
2380
2187
|
});
|
|
2381
2188
|
}
|
|
2382
|
-
|
|
2383
|
-
|
|
2189
|
+
if (response.status === 'success') {
|
|
2190
|
+
inlineInstance.closePreCheckoutModal(response.status);
|
|
2191
|
+
}
|
|
2384
2192
|
}).catch(function (error) {
|
|
2385
2193
|
applePaySession.completePayment(applePaySession.STATUS_FAILURE);
|
|
2386
2194
|
transaction.onSetupError(error);
|
|
2387
|
-
|
|
2195
|
+
pendingPreCheckoutModalStatus = 'failed';
|
|
2388
2196
|
_this5.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2389
2197
|
channel: 'apple_pay',
|
|
2390
2198
|
message: error && error.message || 'Error occurred'
|
|
2391
2199
|
});
|
|
2392
|
-
|
|
2393
|
-
inlineInstance.closePreCheckoutModal('failed');
|
|
2394
2200
|
});
|
|
2395
2201
|
};
|
|
2396
|
-
|
|
2397
2202
|
applePaySession.begin();
|
|
2398
2203
|
} catch (error) {
|
|
2399
2204
|
transaction.onSetupError(error);
|
|
2205
|
+
inlineInstance.closePreCheckoutModal('failed');
|
|
2400
2206
|
}
|
|
2401
2207
|
} else {
|
|
2402
2208
|
handleError('Could not initiate apple pay transaction');
|
|
@@ -2407,9 +2213,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2407
2213
|
value: function resumeTransaction(accessCode) {
|
|
2408
2214
|
var callbacks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2409
2215
|
var onSuccess = callbacks.onSuccess,
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2216
|
+
onCancel = callbacks.onCancel,
|
|
2217
|
+
onLoad = callbacks.onLoad,
|
|
2218
|
+
onError = callbacks.onError;
|
|
2413
2219
|
return this.newTransaction({
|
|
2414
2220
|
accessCode: accessCode,
|
|
2415
2221
|
onSuccess: onSuccess,
|
|
@@ -2433,7 +2239,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2433
2239
|
var transaction = this.transactions.find(function (t) {
|
|
2434
2240
|
return t.id === id;
|
|
2435
2241
|
}) || this.activeTransaction();
|
|
2436
|
-
|
|
2437
2242
|
if (transaction) {
|
|
2438
2243
|
transaction.cancel();
|
|
2439
2244
|
this.close();
|
|
@@ -2445,23 +2250,20 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2445
2250
|
if (!event) {
|
|
2446
2251
|
return;
|
|
2447
2252
|
}
|
|
2448
|
-
|
|
2449
2253
|
var activeTransaction = this.activeTransaction();
|
|
2450
|
-
|
|
2451
2254
|
try {
|
|
2452
2255
|
var actualEvent = event.data || event.message;
|
|
2453
2256
|
var eventType = actualEvent.event,
|
|
2454
|
-
|
|
2455
|
-
|
|
2257
|
+
eventData = actualEvent.data;
|
|
2456
2258
|
if (eventType) {
|
|
2457
2259
|
switch (eventType) {
|
|
2458
2260
|
case 'loaded:checkout':
|
|
2459
2261
|
this.isLoaded = true;
|
|
2460
|
-
|
|
2461
2262
|
if (activeTransaction) {
|
|
2462
2263
|
var checkoutIframe = this.checkoutIframe;
|
|
2463
2264
|
var urlParameters = activeTransaction.urlParameters,
|
|
2464
|
-
|
|
2265
|
+
response = activeTransaction.response;
|
|
2266
|
+
// TODO: reintroduce this when we resolve checkout caching issues
|
|
2465
2267
|
// const params = response
|
|
2466
2268
|
// ? { transactionData: response }
|
|
2467
2269
|
// : urlParameters;
|
|
@@ -2475,77 +2277,60 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2475
2277
|
urlParameters: params
|
|
2476
2278
|
});
|
|
2477
2279
|
}
|
|
2478
|
-
|
|
2479
2280
|
break;
|
|
2480
|
-
|
|
2481
2281
|
case 'loaded:transaction':
|
|
2482
2282
|
hideLoader(this.backgroundIframe);
|
|
2483
|
-
|
|
2484
2283
|
if (this.preCheckoutModal) {
|
|
2485
2284
|
this.openPreCheckoutModal();
|
|
2486
2285
|
}
|
|
2487
|
-
|
|
2488
2286
|
activeTransaction.onLoad(eventData);
|
|
2489
2287
|
break;
|
|
2490
|
-
|
|
2491
2288
|
case 'error':
|
|
2492
2289
|
{
|
|
2493
2290
|
var error = eventData;
|
|
2494
|
-
|
|
2495
2291
|
if (error.type === 'setup') {
|
|
2496
2292
|
activeTransaction.onSetupError(eventData);
|
|
2497
2293
|
} else {
|
|
2498
2294
|
activeTransaction.logError(eventData);
|
|
2499
2295
|
}
|
|
2500
|
-
|
|
2501
2296
|
break;
|
|
2502
2297
|
}
|
|
2503
|
-
|
|
2504
2298
|
case 'cancel':
|
|
2505
2299
|
case 'close':
|
|
2506
2300
|
{
|
|
2507
2301
|
this.close();
|
|
2508
2302
|
var status = eventData && eventData.status;
|
|
2509
|
-
|
|
2510
2303
|
if (status) {
|
|
2511
2304
|
activeTransaction.setStatus(status);
|
|
2512
2305
|
}
|
|
2513
|
-
|
|
2514
2306
|
var hasPaymentRequestButtons = this.paymentRequestContainer && getApplePayButton(this.paymentRequestContainer);
|
|
2515
2307
|
var shouldSetCurrentTransactionAsInactive = !(hasPaymentRequestButtons && !this.preCheckoutModal);
|
|
2516
|
-
|
|
2517
2308
|
if (shouldSetCurrentTransactionAsInactive) {
|
|
2518
2309
|
activeTransaction.isActive = false;
|
|
2519
2310
|
}
|
|
2520
|
-
|
|
2521
2311
|
activeTransaction.onCancel();
|
|
2522
2312
|
break;
|
|
2523
2313
|
}
|
|
2524
|
-
|
|
2525
2314
|
case 'transfer:pending':
|
|
2526
2315
|
{
|
|
2527
2316
|
this.close();
|
|
2528
|
-
|
|
2529
2317
|
var _status = eventData && eventData.status;
|
|
2530
|
-
|
|
2531
2318
|
if (_status) {
|
|
2532
2319
|
activeTransaction.setStatus(_status);
|
|
2533
2320
|
}
|
|
2534
|
-
|
|
2535
2321
|
activeTransaction.onBankTransferConfirmationPending();
|
|
2536
2322
|
break;
|
|
2537
2323
|
}
|
|
2538
|
-
|
|
2539
2324
|
case 'success':
|
|
2540
2325
|
this.close();
|
|
2541
2326
|
activeTransaction.onSuccess(eventData);
|
|
2542
2327
|
break;
|
|
2543
|
-
|
|
2544
2328
|
default:
|
|
2545
2329
|
break;
|
|
2546
2330
|
}
|
|
2547
2331
|
}
|
|
2548
|
-
} catch (error) {
|
|
2332
|
+
} catch (error) {
|
|
2333
|
+
// do nothing
|
|
2549
2334
|
}
|
|
2550
2335
|
}
|
|
2551
2336
|
}, {
|
|
@@ -2553,19 +2338,15 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2553
2338
|
value: function respondToEmbedEvents(event) {
|
|
2554
2339
|
var activeTransaction = this.activeTransaction();
|
|
2555
2340
|
var eventData = event.data || event.message;
|
|
2556
|
-
|
|
2557
2341
|
if (eventData && (typeof eventData === 'string' || eventData instanceof String)) {
|
|
2558
2342
|
var response = parseResponse(eventData);
|
|
2559
2343
|
var oldCheckoutCloseResponse = response && response.action === 'PaystackClose';
|
|
2560
|
-
|
|
2561
2344
|
if (oldCheckoutCloseResponse) {
|
|
2562
2345
|
var chargeResponse = response.data;
|
|
2563
|
-
|
|
2564
2346
|
if (chargeResponse) {
|
|
2565
2347
|
activeTransaction.onSuccess(eventData);
|
|
2566
2348
|
}
|
|
2567
2349
|
}
|
|
2568
|
-
|
|
2569
2350
|
if (response.action === 'PaystackTLSClose') {
|
|
2570
2351
|
activeTransaction.cancel();
|
|
2571
2352
|
}
|
|
@@ -2575,18 +2356,15 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2575
2356
|
key: "animateCheckoutIn",
|
|
2576
2357
|
value: function animateCheckoutIn$1() {
|
|
2577
2358
|
var _this6 = this;
|
|
2578
|
-
|
|
2579
2359
|
if (!this.isOpen) {
|
|
2580
2360
|
var checkoutIframe = this.checkoutIframe,
|
|
2581
|
-
|
|
2582
|
-
|
|
2361
|
+
backgroundIframe = this.backgroundIframe;
|
|
2583
2362
|
animateCheckoutIn({
|
|
2584
2363
|
checkoutIframe: checkoutIframe,
|
|
2585
2364
|
backgroundIframe: backgroundIframe
|
|
2586
2365
|
}).then(function () {
|
|
2587
2366
|
_this6.checkoutIframe.contentWindow.postMessage('render', '*');
|
|
2588
2367
|
});
|
|
2589
|
-
|
|
2590
2368
|
this.isOpen = true;
|
|
2591
2369
|
}
|
|
2592
2370
|
}
|
|
@@ -2596,13 +2374,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2596
2374
|
if (!urlParameters) {
|
|
2597
2375
|
return;
|
|
2598
2376
|
}
|
|
2599
|
-
|
|
2600
2377
|
var checkoutIframe = this.checkoutIframe;
|
|
2601
2378
|
notifyIframeToUpdateURL({
|
|
2602
2379
|
checkoutIframe: checkoutIframe,
|
|
2603
2380
|
urlParameters: urlParameters
|
|
2604
2381
|
});
|
|
2605
|
-
|
|
2606
2382
|
if (!preload) {
|
|
2607
2383
|
this.animateCheckoutIn();
|
|
2608
2384
|
}
|
|
@@ -2611,13 +2387,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2611
2387
|
key: "close",
|
|
2612
2388
|
value: function close() {
|
|
2613
2389
|
var _this7 = this;
|
|
2614
|
-
|
|
2615
2390
|
if (!this.isOpen) {
|
|
2616
2391
|
return;
|
|
2617
2392
|
}
|
|
2618
|
-
|
|
2619
2393
|
var checkoutIframe = this.checkoutIframe,
|
|
2620
|
-
|
|
2394
|
+
backgroundIframe = this.backgroundIframe;
|
|
2621
2395
|
animateCheckoutOut({
|
|
2622
2396
|
checkoutIframe: checkoutIframe,
|
|
2623
2397
|
backgroundIframe: backgroundIframe
|
|
@@ -2636,23 +2410,19 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2636
2410
|
value: function setup(parameters) {
|
|
2637
2411
|
var isDeprecatedApi = true;
|
|
2638
2412
|
var isEmbed = parameters && parameters.container;
|
|
2639
|
-
|
|
2640
2413
|
if (!inlineInstance) {
|
|
2641
2414
|
inlineInstance = new Inline({
|
|
2642
2415
|
isDeprecatedApi: isDeprecatedApi,
|
|
2643
2416
|
isEmbed: isEmbed
|
|
2644
2417
|
});
|
|
2645
2418
|
}
|
|
2646
|
-
|
|
2647
2419
|
printDeprecationNotice('PaystackPop.setup()', 'new PaystackPop()', 'Please consult our documentation at https://developers.paystack.co/docs/paystack-inline');
|
|
2648
2420
|
var transaction = inlineInstance.newTransaction(parameters, 'deprecated');
|
|
2649
2421
|
var urlParameters = transaction.urlParameters;
|
|
2650
|
-
|
|
2651
2422
|
if (isEmbed) {
|
|
2652
2423
|
var inlineUrl = "".concat(config.siteUrl, "/assets/payment/production/inline.html?").concat(serialize(urlParameters));
|
|
2653
2424
|
var iframe = mountEmbedCheckoutIframe(inlineInstance.id, inlineUrl);
|
|
2654
2425
|
appendIframeToContainer(parameters.container, iframe);
|
|
2655
|
-
|
|
2656
2426
|
iframe.onload = function onLoad() {
|
|
2657
2427
|
iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), '*');
|
|
2658
2428
|
animateEmbedCheckoutIn(iframe);
|
|
@@ -2664,22 +2434,16 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2664
2434
|
inlineInstance.open(urlParameters);
|
|
2665
2435
|
};
|
|
2666
2436
|
}
|
|
2667
|
-
|
|
2668
2437
|
return transaction;
|
|
2669
2438
|
}
|
|
2670
2439
|
}]);
|
|
2671
|
-
|
|
2672
|
-
return Inline;
|
|
2673
2440
|
}();
|
|
2674
|
-
|
|
2675
2441
|
if (scriptCanUseDataAttributes()) {
|
|
2676
2442
|
var parameters = getDataAttributesAsParameters();
|
|
2677
2443
|
var parentForm = getSourceScript().parentElement;
|
|
2678
|
-
|
|
2679
2444
|
if (!inlineInstance) {
|
|
2680
2445
|
inlineInstance = new Inline();
|
|
2681
2446
|
}
|
|
2682
|
-
|
|
2683
2447
|
var transaction;
|
|
2684
2448
|
var inlineButton = mountLazyInlineButton({
|
|
2685
2449
|
inlineId: inlineInstance.id,
|
|
@@ -2693,7 +2457,6 @@ if (scriptCanUseDataAttributes()) {
|
|
|
2693
2457
|
});
|
|
2694
2458
|
inlineButton.addEventListener('click', function (e) {
|
|
2695
2459
|
e.preventDefault();
|
|
2696
|
-
|
|
2697
2460
|
if (!transaction) {
|
|
2698
2461
|
transaction = inlineInstance.newTransaction(_objectSpread2(_objectSpread2({}, parameters), {}, {
|
|
2699
2462
|
onSuccess: function onSuccess(response) {
|