@paystack/inline-js 2.23.0-dev.2 → 2.23.0-dev.4
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 +36 -0
- package/dist/inline.js +147 -401
- package/es/inline.js +147 -401
- package/lib/inline.js +147 -401
- package/package.json +11 -2
package/lib/inline.js
CHANGED
|
@@ -2,37 +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
14
|
function _classCallCheck(a, n) {
|
|
20
15
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
function _defineProperties(e, r) {
|
|
24
18
|
for (var t = 0; t < r.length; t++) {
|
|
25
19
|
var o = r[t];
|
|
26
20
|
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
27
21
|
}
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
function _createClass(e, r, t) {
|
|
31
24
|
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
32
25
|
writable: !1
|
|
33
26
|
}), e;
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
function _defineProperty(e, r, t) {
|
|
37
29
|
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
38
30
|
value: t,
|
|
@@ -41,23 +33,19 @@ function _defineProperty(e, r, t) {
|
|
|
41
33
|
writable: !0
|
|
42
34
|
}) : e[r] = t, e;
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
function _iterableToArray(r) {
|
|
46
37
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
function _iterableToArrayLimit(r, l) {
|
|
50
40
|
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
51
|
-
|
|
52
41
|
if (null != t) {
|
|
53
42
|
var e,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
n,
|
|
44
|
+
i,
|
|
45
|
+
u,
|
|
46
|
+
a = [],
|
|
47
|
+
f = !0,
|
|
48
|
+
o = !1;
|
|
61
49
|
try {
|
|
62
50
|
if (i = (t = t.call(r)).next, 0 === l) {
|
|
63
51
|
if (Object(t) !== t) return;
|
|
@@ -72,32 +60,25 @@ function _iterableToArrayLimit(r, l) {
|
|
|
72
60
|
if (o) throw n;
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
|
|
76
63
|
return a;
|
|
77
64
|
}
|
|
78
65
|
}
|
|
79
|
-
|
|
80
66
|
function _nonIterableRest() {
|
|
81
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.");
|
|
82
68
|
}
|
|
83
|
-
|
|
84
69
|
function _nonIterableSpread() {
|
|
85
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.");
|
|
86
71
|
}
|
|
87
|
-
|
|
88
72
|
function ownKeys(e, r) {
|
|
89
73
|
var t = Object.keys(e);
|
|
90
|
-
|
|
91
74
|
if (Object.getOwnPropertySymbols) {
|
|
92
75
|
var o = Object.getOwnPropertySymbols(e);
|
|
93
76
|
r && (o = o.filter(function (r) {
|
|
94
77
|
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
95
78
|
})), t.push.apply(t, o);
|
|
96
79
|
}
|
|
97
|
-
|
|
98
80
|
return t;
|
|
99
81
|
}
|
|
100
|
-
|
|
101
82
|
function _objectSpread2(e) {
|
|
102
83
|
for (var r = 1; r < arguments.length; r++) {
|
|
103
84
|
var t = null != arguments[r] ? arguments[r] : {};
|
|
@@ -107,65 +88,48 @@ function _objectSpread2(e) {
|
|
|
107
88
|
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
108
89
|
});
|
|
109
90
|
}
|
|
110
|
-
|
|
111
91
|
return e;
|
|
112
92
|
}
|
|
113
|
-
|
|
114
93
|
function _objectWithoutProperties(e, t) {
|
|
115
94
|
if (null == e) return {};
|
|
116
|
-
|
|
117
95
|
var o,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
96
|
+
r,
|
|
97
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
121
98
|
if (Object.getOwnPropertySymbols) {
|
|
122
99
|
var n = Object.getOwnPropertySymbols(e);
|
|
123
|
-
|
|
124
100
|
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
125
101
|
}
|
|
126
|
-
|
|
127
102
|
return i;
|
|
128
103
|
}
|
|
129
|
-
|
|
130
104
|
function _objectWithoutPropertiesLoose(r, e) {
|
|
131
105
|
if (null == r) return {};
|
|
132
106
|
var t = {};
|
|
133
|
-
|
|
134
107
|
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
135
108
|
if (-1 !== e.indexOf(n)) continue;
|
|
136
109
|
t[n] = r[n];
|
|
137
110
|
}
|
|
138
|
-
|
|
139
111
|
return t;
|
|
140
112
|
}
|
|
141
|
-
|
|
142
113
|
function _slicedToArray(r, e) {
|
|
143
114
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
144
115
|
}
|
|
145
|
-
|
|
146
116
|
function _toConsumableArray(r) {
|
|
147
117
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
148
118
|
}
|
|
149
|
-
|
|
150
119
|
function _toPrimitive(t, r) {
|
|
151
120
|
if ("object" != typeof t || !t) return t;
|
|
152
121
|
var e = t[Symbol.toPrimitive];
|
|
153
|
-
|
|
154
122
|
if (void 0 !== e) {
|
|
155
123
|
var i = e.call(t, r || "default");
|
|
156
124
|
if ("object" != typeof i) return i;
|
|
157
125
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
158
126
|
}
|
|
159
|
-
|
|
160
127
|
return ("string" === r ? String : Number)(t);
|
|
161
128
|
}
|
|
162
|
-
|
|
163
129
|
function _toPropertyKey(t) {
|
|
164
130
|
var i = _toPrimitive(t, "string");
|
|
165
|
-
|
|
166
131
|
return "symbol" == typeof i ? i : i + "";
|
|
167
132
|
}
|
|
168
|
-
|
|
169
133
|
function _typeof(o) {
|
|
170
134
|
"@babel/helpers - typeof";
|
|
171
135
|
|
|
@@ -175,7 +139,6 @@ function _typeof(o) {
|
|
|
175
139
|
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
176
140
|
}, _typeof(o);
|
|
177
141
|
}
|
|
178
|
-
|
|
179
142
|
function _unsupportedIterableToArray(r, a) {
|
|
180
143
|
if (r) {
|
|
181
144
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -221,18 +184,16 @@ var configurations = {
|
|
|
221
184
|
staging: stagingConfig,
|
|
222
185
|
production: productionConfig
|
|
223
186
|
};
|
|
224
|
-
/* eslint-disable */
|
|
225
187
|
|
|
188
|
+
/* eslint-disable */
|
|
226
189
|
var config = configurations['staging'] || stagingConfig;
|
|
227
190
|
|
|
228
191
|
function randomId() {
|
|
229
192
|
var text = '';
|
|
230
193
|
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
231
|
-
|
|
232
194
|
for (var i = 0; i < 5; i += 1) {
|
|
233
195
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
234
196
|
}
|
|
235
|
-
|
|
236
197
|
return text;
|
|
237
198
|
}
|
|
238
199
|
|
|
@@ -266,15 +227,12 @@ function getLastScript() {
|
|
|
266
227
|
var scripts = document.getElementsByTagName('script');
|
|
267
228
|
return scripts[scripts.length - 1];
|
|
268
229
|
}
|
|
269
|
-
|
|
270
230
|
function getSourceScript() {
|
|
271
231
|
return document.currentScript || getLastScript();
|
|
272
232
|
}
|
|
273
|
-
|
|
274
233
|
function getDataAttributes() {
|
|
275
234
|
var dataAttributes = [];
|
|
276
235
|
var sourceScript = getSourceScript();
|
|
277
|
-
|
|
278
236
|
if (sourceScript) {
|
|
279
237
|
var attributes = Array.prototype.slice.call(sourceScript.attributes);
|
|
280
238
|
dataAttributes = Object.keys(attributes).filter(function (key) {
|
|
@@ -284,10 +242,8 @@ function getDataAttributes() {
|
|
|
284
242
|
return attributes[index].nodeName;
|
|
285
243
|
});
|
|
286
244
|
}
|
|
287
|
-
|
|
288
245
|
return dataAttributes;
|
|
289
246
|
}
|
|
290
|
-
|
|
291
247
|
function scriptCanUseDataAttributes() {
|
|
292
248
|
var hasDataAttributes = getDataAttributes().length > 0;
|
|
293
249
|
var hasParentForm = getSourceScript() && getSourceScript().parentElement.tagName === 'FORM';
|
|
@@ -299,30 +255,23 @@ function getDataAttributesAsParameters() {
|
|
|
299
255
|
return g[1].toUpperCase();
|
|
300
256
|
});
|
|
301
257
|
}
|
|
302
|
-
|
|
303
258
|
function validateLazyParameters(parameters) {
|
|
304
259
|
if (parameters.buttonId && !document.getElementById(parameters.buttonId)) {
|
|
305
260
|
throw new Error('Please make sure the buttonId is an element available in the DOM');
|
|
306
261
|
}
|
|
307
|
-
|
|
308
262
|
var updatedParameters = _objectSpread2({}, parameters);
|
|
309
|
-
|
|
310
263
|
updatedParameters.buttonText = parameters.buttonText || 'Pay';
|
|
311
264
|
updatedParameters.buttonVariant = 'normal';
|
|
312
265
|
updatedParameters.buttonWordmarkVariant = 'normal';
|
|
313
266
|
var allowedVariants = ['normal', 'light'];
|
|
314
|
-
|
|
315
267
|
if (parameters.buttonVariant && allowedVariants.indexOf(parameters.buttonVariant) > -1) {
|
|
316
268
|
updatedParameters.buttonVariant = parameters.buttonVariant;
|
|
317
269
|
}
|
|
318
|
-
|
|
319
270
|
if (parameters.buttonWordmarkVariant && allowedVariants.indexOf(parameters.buttonWordmarkVariant) > -1) {
|
|
320
271
|
updatedParameters.buttonWordmarkVariant = parameters.buttonWordmarkVariant;
|
|
321
272
|
}
|
|
322
|
-
|
|
323
273
|
return updatedParameters;
|
|
324
274
|
}
|
|
325
|
-
|
|
326
275
|
var parameters = {};
|
|
327
276
|
var sourceScript = getSourceScript();
|
|
328
277
|
var dataAttributes = getDataAttributes();
|
|
@@ -347,7 +296,6 @@ var loaderHTML = "\n <!DOCTYPE html>\n <html lang=\"en\">\n\n <head>\n <me
|
|
|
347
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";
|
|
348
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";
|
|
349
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";
|
|
350
|
-
|
|
351
299
|
function generateInlineButtonCSS(variant) {
|
|
352
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 ";
|
|
353
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 ";
|
|
@@ -358,7 +306,6 @@ function generateInlineButtonCSS(variant) {
|
|
|
358
306
|
};
|
|
359
307
|
return "".concat(baseCSS).concat(colorVariants[variant]);
|
|
360
308
|
}
|
|
361
|
-
|
|
362
309
|
function generateInlineButtonHTML(options) {
|
|
363
310
|
var wordmarkVariants = {
|
|
364
311
|
normal: secureByPaystack,
|
|
@@ -379,7 +326,6 @@ var parseApplePayCustomStyles = function parseApplePayCustomStyles(styles) {
|
|
|
379
326
|
if (!(styles && _typeof(styles) === 'object')) {
|
|
380
327
|
return defaultCustomApplePayStyles;
|
|
381
328
|
}
|
|
382
|
-
|
|
383
329
|
var customStyles = Object.keys(defaultCustomApplePayStyles).reduce(function (newDefaultStyles, key) {
|
|
384
330
|
return _objectSpread2(_objectSpread2({}, newDefaultStyles), {}, _defineProperty({}, key, styles[key] || defaultCustomApplePayStyles[key]));
|
|
385
331
|
}, {});
|
|
@@ -387,18 +333,18 @@ var parseApplePayCustomStyles = function parseApplePayCustomStyles(styles) {
|
|
|
387
333
|
};
|
|
388
334
|
var generateApplePayCSS = function generateApplePayCSS(_ref) {
|
|
389
335
|
var height = _ref.height,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
336
|
+
width = _ref.width,
|
|
337
|
+
borderRadius = _ref.borderRadius,
|
|
338
|
+
padding = _ref.padding;
|
|
393
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");
|
|
394
340
|
};
|
|
395
341
|
var generateApplePayFallbackCSS = function generateApplePayFallbackCSS(_ref2) {
|
|
396
342
|
var height = _ref2.height,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
343
|
+
width = _ref2.width,
|
|
344
|
+
borderRadius = _ref2.borderRadius,
|
|
345
|
+
padding = _ref2.padding,
|
|
346
|
+
type = _ref2.type,
|
|
347
|
+
locale = _ref2.locale;
|
|
402
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");
|
|
403
349
|
};
|
|
404
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";
|
|
@@ -438,7 +384,6 @@ var APPLE_PAY_CAPABILITY_STATUS = {
|
|
|
438
384
|
UNKNOWN: 'paymentCredentialStatusUnknown',
|
|
439
385
|
UNSUPPORTED: 'applePayUnsupported'
|
|
440
386
|
};
|
|
441
|
-
|
|
442
387
|
var formatIntervalString = function formatIntervalString(interval) {
|
|
443
388
|
var plans = {
|
|
444
389
|
biannually: 'BIANNUAL PLAN',
|
|
@@ -446,12 +391,11 @@ var formatIntervalString = function formatIntervalString(interval) {
|
|
|
446
391
|
};
|
|
447
392
|
return plans[interval] || "".concat(interval.toUpperCase(), " PLAN");
|
|
448
393
|
};
|
|
449
|
-
|
|
450
394
|
var generateApplePaymentRequestObject = function generateApplePaymentRequestObject(_ref) {
|
|
451
395
|
var currency = _ref.currency,
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
396
|
+
amount = _ref.amount,
|
|
397
|
+
merchantName = _ref.merchantName,
|
|
398
|
+
interval = _ref.interval;
|
|
455
399
|
return _objectSpread2({
|
|
456
400
|
countryCode: 'NG',
|
|
457
401
|
currencyCode: currency,
|
|
@@ -472,10 +416,10 @@ var generateApplePaymentRequestObject = function generateApplePaymentRequestObje
|
|
|
472
416
|
};
|
|
473
417
|
var validateApplePaySession = function validateApplePaySession(_ref2) {
|
|
474
418
|
var transactionId = _ref2.transactionId,
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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;
|
|
479
423
|
var validateSessionUrl = "".concat(config.paymentBaseUrl).concat(config.applePayValidateSessionPath);
|
|
480
424
|
var params = {
|
|
481
425
|
transaction: transactionId,
|
|
@@ -493,7 +437,7 @@ var validateApplePaySession = function validateApplePaySession(_ref2) {
|
|
|
493
437
|
};
|
|
494
438
|
var chargeApplePay = function chargeApplePay(_ref3) {
|
|
495
439
|
var transactionId = _ref3.transactionId,
|
|
496
|
-
|
|
440
|
+
payment = _ref3.payment;
|
|
497
441
|
var chargeApplePayUrl = "".concat(config.paymentBaseUrl).concat(config.applePayChargePath);
|
|
498
442
|
var params = {
|
|
499
443
|
transaction: transactionId,
|
|
@@ -514,32 +458,25 @@ var deviceSupportsApplePay = function deviceSupportsApplePay() {
|
|
|
514
458
|
return false;
|
|
515
459
|
}
|
|
516
460
|
};
|
|
517
|
-
|
|
518
461
|
var getApplePayCapabilityStatusFromResponse = function getApplePayCapabilityStatusFromResponse(capabilities) {
|
|
519
462
|
if (!capabilities) {
|
|
520
463
|
return null;
|
|
521
464
|
}
|
|
522
|
-
|
|
523
465
|
if (typeof capabilities === 'string') {
|
|
524
466
|
return capabilities;
|
|
525
467
|
}
|
|
526
|
-
|
|
527
468
|
if (typeof capabilities.paymentCredentialStatus === 'string') {
|
|
528
469
|
return capabilities.paymentCredentialStatus;
|
|
529
470
|
}
|
|
530
|
-
|
|
531
471
|
return null;
|
|
532
472
|
};
|
|
533
|
-
|
|
534
473
|
var getApplePayCapabilityStatus = function getApplePayCapabilityStatus() {
|
|
535
474
|
try {
|
|
536
475
|
if (!deviceSupportsApplePay()) {
|
|
537
476
|
return Promise.resolve(null);
|
|
538
477
|
}
|
|
539
|
-
|
|
540
478
|
var _window = window,
|
|
541
|
-
|
|
542
|
-
|
|
479
|
+
ApplePaySession = _window.ApplePaySession;
|
|
543
480
|
if (typeof ApplePaySession.applePayCapabilities === 'function') {
|
|
544
481
|
return Promise.resolve(ApplePaySession.applePayCapabilities()).then(function (capabilities) {
|
|
545
482
|
return getApplePayCapabilityStatusFromResponse(capabilities);
|
|
@@ -551,17 +488,14 @@ var getApplePayCapabilityStatus = function getApplePayCapabilityStatus() {
|
|
|
551
488
|
} catch (fallbackError) {
|
|
552
489
|
return null;
|
|
553
490
|
}
|
|
554
|
-
|
|
555
491
|
return APPLE_PAY_CAPABILITY_STATUS.UNSUPPORTED;
|
|
556
492
|
});
|
|
557
493
|
}
|
|
558
|
-
|
|
559
494
|
if (typeof ApplePaySession.canMakePayments === 'function') {
|
|
560
495
|
return Promise.resolve(ApplePaySession.canMakePayments()).then(function (canMakePayments) {
|
|
561
496
|
return canMakePayments ? APPLE_PAY_CAPABILITY_STATUS.UNKNOWN : APPLE_PAY_CAPABILITY_STATUS.UNSUPPORTED;
|
|
562
497
|
});
|
|
563
498
|
}
|
|
564
|
-
|
|
565
499
|
return Promise.resolve(null);
|
|
566
500
|
} catch (error) {
|
|
567
501
|
try {
|
|
@@ -571,7 +505,6 @@ var getApplePayCapabilityStatus = function getApplePayCapabilityStatus() {
|
|
|
571
505
|
} catch (fallbackError) {
|
|
572
506
|
return Promise.resolve(null);
|
|
573
507
|
}
|
|
574
|
-
|
|
575
508
|
return Promise.resolve(APPLE_PAY_CAPABILITY_STATUS.UNSUPPORTED);
|
|
576
509
|
}
|
|
577
510
|
};
|
|
@@ -580,11 +513,9 @@ var applePayCapabilityCanShowButton = function applePayCapabilityCanShowButton(s
|
|
|
580
513
|
};
|
|
581
514
|
var canUseApplePay = function canUseApplePay(channels) {
|
|
582
515
|
var availableChannels = channels || [];
|
|
583
|
-
|
|
584
516
|
if (!availableChannels.includes('apple_pay')) {
|
|
585
517
|
return Promise.resolve(false);
|
|
586
518
|
}
|
|
587
|
-
|
|
588
519
|
return getApplePayCapabilityStatus().then(function (capabilityStatus) {
|
|
589
520
|
return applePayCapabilityCanShowButton(capabilityStatus);
|
|
590
521
|
});
|
|
@@ -597,7 +528,6 @@ function findHighestZIndex() {
|
|
|
597
528
|
elements.forEach(function (element) {
|
|
598
529
|
var computedStyle = window.getComputedStyle(element);
|
|
599
530
|
var zIndex = parseFloat(computedStyle.zIndex);
|
|
600
|
-
|
|
601
531
|
if (!Number.isNaN(zIndex) && zIndex > highestZIndex) {
|
|
602
532
|
highestZIndex = zIndex;
|
|
603
533
|
}
|
|
@@ -616,7 +546,6 @@ function createIframe(id) {
|
|
|
616
546
|
iframe.style.display = 'none';
|
|
617
547
|
return iframe;
|
|
618
548
|
}
|
|
619
|
-
|
|
620
549
|
function mountCheckoutIframe(id) {
|
|
621
550
|
var iframe = createIframe("inline-checkout-".concat(id));
|
|
622
551
|
iframe.src = "".concat(config.checkoutUrl, "popup");
|
|
@@ -652,20 +581,17 @@ function getApplePayButton(container) {
|
|
|
652
581
|
var applePaySdkPromise;
|
|
653
582
|
var loadScript = function loadScript(url, _ref) {
|
|
654
583
|
var container = _ref.container,
|
|
655
|
-
|
|
584
|
+
integrity = _ref.integrity;
|
|
656
585
|
return new Promise(function (resolve, reject) {
|
|
657
586
|
if (!url) {
|
|
658
587
|
reject('No script url');
|
|
659
588
|
}
|
|
660
|
-
|
|
661
589
|
var script = document.createElement('script');
|
|
662
590
|
script.src = url;
|
|
663
591
|
script.crossOrigin = 'anonymous';
|
|
664
|
-
|
|
665
592
|
if (integrity) {
|
|
666
593
|
script.integrity = integrity;
|
|
667
594
|
}
|
|
668
|
-
|
|
669
595
|
script.addEventListener('load', function () {
|
|
670
596
|
resolve(true);
|
|
671
597
|
});
|
|
@@ -673,7 +599,6 @@ var loadScript = function loadScript(url, _ref) {
|
|
|
673
599
|
script.remove();
|
|
674
600
|
reject(false);
|
|
675
601
|
});
|
|
676
|
-
|
|
677
602
|
if (container) {
|
|
678
603
|
container.appendChild(script);
|
|
679
604
|
} else {
|
|
@@ -681,20 +606,16 @@ var loadScript = function loadScript(url, _ref) {
|
|
|
681
606
|
}
|
|
682
607
|
});
|
|
683
608
|
};
|
|
684
|
-
|
|
685
609
|
var applePayButtonComponentIsAvailable = function applePayButtonComponentIsAvailable() {
|
|
686
610
|
return !!(window && window.customElements && window.customElements.get('apple-pay-button'));
|
|
687
611
|
};
|
|
688
|
-
|
|
689
612
|
var ensureApplePaySdkLoaded = function ensureApplePaySdkLoaded(container) {
|
|
690
613
|
if (applePayButtonComponentIsAvailable()) {
|
|
691
614
|
return Promise.resolve(true);
|
|
692
615
|
}
|
|
693
|
-
|
|
694
616
|
if (applePaySdkPromise) {
|
|
695
617
|
return applePaySdkPromise;
|
|
696
618
|
}
|
|
697
|
-
|
|
698
619
|
applePaySdkPromise = loadScript(APPLE_PAY_SDK_SOURCE, {
|
|
699
620
|
container: container,
|
|
700
621
|
integrity: APPLE_PAY_SDK_INTEGRITY_HASH
|
|
@@ -717,7 +638,6 @@ function appendIframeToContainer(containerId, iframe) {
|
|
|
717
638
|
}
|
|
718
639
|
function hideLoader(iframe) {
|
|
719
640
|
var bgWindow = iframe.contentWindow.document;
|
|
720
|
-
|
|
721
641
|
if (bgWindow) {
|
|
722
642
|
bgWindow.getElementById('app-loader').style.display = 'none';
|
|
723
643
|
}
|
|
@@ -727,14 +647,11 @@ function animateCheckoutIn(domElements) {
|
|
|
727
647
|
if (!domElements) {
|
|
728
648
|
reject('No dom element provided');
|
|
729
649
|
}
|
|
730
|
-
|
|
731
650
|
var checkoutIframe = domElements.checkoutIframe,
|
|
732
|
-
|
|
733
|
-
|
|
651
|
+
backgroundIframe = domElements.backgroundIframe;
|
|
734
652
|
if (!checkoutIframe || !backgroundIframe) {
|
|
735
653
|
reject('No dom element provided');
|
|
736
654
|
}
|
|
737
|
-
|
|
738
655
|
checkoutIframe.style.display = '';
|
|
739
656
|
checkoutIframe.style.visibility = 'visible';
|
|
740
657
|
backgroundIframe.style.display = '';
|
|
@@ -747,14 +664,11 @@ function animateCheckoutOut(domElements) {
|
|
|
747
664
|
if (!domElements) {
|
|
748
665
|
reject('No dom element provided');
|
|
749
666
|
}
|
|
750
|
-
|
|
751
667
|
var checkoutIframe = domElements.checkoutIframe,
|
|
752
|
-
|
|
753
|
-
|
|
668
|
+
backgroundIframe = domElements.backgroundIframe;
|
|
754
669
|
if (!checkoutIframe || !backgroundIframe) {
|
|
755
670
|
reject('No dom element provided');
|
|
756
671
|
}
|
|
757
|
-
|
|
758
672
|
backgroundIframe.style.opacity = 0;
|
|
759
673
|
checkoutIframe.style.display = 'none';
|
|
760
674
|
checkoutIframe.style.visibility = 'hidden';
|
|
@@ -768,7 +682,6 @@ function animateCheckoutOut(domElements) {
|
|
|
768
682
|
}
|
|
769
683
|
function mountLazyInlineButton(options) {
|
|
770
684
|
var inlineButton;
|
|
771
|
-
|
|
772
685
|
if (options.id) {
|
|
773
686
|
inlineButton = document.getElementById(options.id);
|
|
774
687
|
inlineButton.setAttribute('data-inline-id', options.id);
|
|
@@ -777,34 +690,29 @@ function mountLazyInlineButton(options) {
|
|
|
777
690
|
inlineDiv.id = "inline-button-".concat(options.inlineId);
|
|
778
691
|
inlineDiv.innerHTML = generateInlineButtonHTML(options);
|
|
779
692
|
options.parent.parentNode.insertBefore(inlineDiv, options.parent.nextSibling);
|
|
780
|
-
|
|
781
693
|
var _inlineDiv$getElement = inlineDiv.getElementsByTagName('button');
|
|
782
|
-
|
|
783
694
|
var _inlineDiv$getElement2 = _slicedToArray(_inlineDiv$getElement, 1);
|
|
784
|
-
|
|
785
695
|
inlineButton = _inlineDiv$getElement2[0];
|
|
786
696
|
}
|
|
787
|
-
|
|
788
697
|
return inlineButton;
|
|
789
698
|
}
|
|
790
699
|
function animateEmbedCheckoutIn(checkoutIframe) {
|
|
791
700
|
return new Promise(function (resolve, reject) {
|
|
792
701
|
if (!checkoutIframe) {
|
|
793
702
|
reject('No dom element provided');
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
703
|
+
}
|
|
704
|
+
// eslint-disable-next-line no-param-reassign
|
|
705
|
+
checkoutIframe.style.display = '';
|
|
706
|
+
// eslint-disable-next-line no-param-reassign
|
|
799
707
|
checkoutIframe.style.visibility = 'visible';
|
|
800
708
|
resolve();
|
|
801
709
|
});
|
|
802
710
|
}
|
|
803
711
|
function mountInput(options) {
|
|
804
712
|
var type = options.type,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
713
|
+
value = options.value,
|
|
714
|
+
name = options.name,
|
|
715
|
+
parent = options.parent;
|
|
808
716
|
var input = document.createElement('input');
|
|
809
717
|
input.type = type;
|
|
810
718
|
input.value = value;
|
|
@@ -813,17 +721,15 @@ function mountInput(options) {
|
|
|
813
721
|
}
|
|
814
722
|
function mountApplePayButton(container, _ref2) {
|
|
815
723
|
var styles = _ref2.styles,
|
|
816
|
-
|
|
724
|
+
theme = _ref2.theme;
|
|
817
725
|
var style = document.createElement('style');
|
|
818
726
|
var applePayCSS = generateApplePayCSS(styles);
|
|
819
727
|
style.type = 'text/css';
|
|
820
|
-
|
|
821
728
|
if (style.styleSheet) {
|
|
822
729
|
style.styleSheet.cssText = applePayCSS;
|
|
823
730
|
} else {
|
|
824
731
|
style.appendChild(document.createTextNode(applePayCSS));
|
|
825
732
|
}
|
|
826
|
-
|
|
827
733
|
container.appendChild(style);
|
|
828
734
|
var button = document.createElement('apple-pay-button');
|
|
829
735
|
button.setAttribute('buttonstyle', theme === 'light' ? 'white' : 'black');
|
|
@@ -833,17 +739,15 @@ function mountApplePayButton(container, _ref2) {
|
|
|
833
739
|
}
|
|
834
740
|
function mountApplePayFallbackButton(container, _ref3) {
|
|
835
741
|
var styles = _ref3.styles,
|
|
836
|
-
|
|
742
|
+
theme = _ref3.theme;
|
|
837
743
|
var style = document.createElement('style');
|
|
838
744
|
var applePayCSS = generateApplePayFallbackCSS(styles);
|
|
839
745
|
style.type = 'text/css';
|
|
840
|
-
|
|
841
746
|
if (style.styleSheet) {
|
|
842
747
|
style.styleSheet.cssText = applePayCSS;
|
|
843
748
|
} else {
|
|
844
749
|
style.appendChild(document.createTextNode(applePayCSS));
|
|
845
750
|
}
|
|
846
|
-
|
|
847
751
|
container.appendChild(style);
|
|
848
752
|
var button = document.createElement('button');
|
|
849
753
|
button.classList.add('apple-pay-button', theme === 'light' ? 'apple-pay-button-white' : 'apple-pay-button-black');
|
|
@@ -858,21 +762,18 @@ function getPaymentRequestContainer(container) {
|
|
|
858
762
|
}
|
|
859
763
|
function mountPaymentRequestButtons(container, _ref4) {
|
|
860
764
|
var _ref4$channels = _ref4.channels,
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
765
|
+
channels = _ref4$channels === void 0 ? [] : _ref4$channels,
|
|
766
|
+
_ref4$styles = _ref4.styles,
|
|
767
|
+
styles = _ref4$styles === void 0 ? {} : _ref4$styles;
|
|
864
768
|
var mountedElements = {
|
|
865
769
|
applePay: false
|
|
866
770
|
};
|
|
867
|
-
|
|
868
771
|
if (!container) {
|
|
869
772
|
return Promise.reject(new Error('Container to mount elements was not provided'));
|
|
870
773
|
}
|
|
871
|
-
|
|
872
774
|
if (!channels.includes('apple_pay')) {
|
|
873
775
|
return Promise.reject(new Error('No wallet payment method is available on this device'));
|
|
874
776
|
}
|
|
875
|
-
|
|
876
777
|
return ensureApplePaySdkLoaded(container).catch(function () {
|
|
877
778
|
// Safari can still render the fallback button using the native ApplePaySession.
|
|
878
779
|
return null;
|
|
@@ -882,12 +783,10 @@ function mountPaymentRequestButtons(container, _ref4) {
|
|
|
882
783
|
if (!applePayAvailable) {
|
|
883
784
|
throw new Error('No wallet payment method is available on this device');
|
|
884
785
|
}
|
|
885
|
-
|
|
886
786
|
if (getApplePayButton(container)) {
|
|
887
787
|
mountedElements.applePay = true;
|
|
888
788
|
return mountedElements;
|
|
889
789
|
}
|
|
890
|
-
|
|
891
790
|
try {
|
|
892
791
|
mountApplePayButton(container, {
|
|
893
792
|
styles: parseApplePayCustomStyles(styles.applePay),
|
|
@@ -900,7 +799,6 @@ function mountPaymentRequestButtons(container, _ref4) {
|
|
|
900
799
|
theme: styles.theme
|
|
901
800
|
});
|
|
902
801
|
}
|
|
903
|
-
|
|
904
802
|
mountedElements.applePay = true;
|
|
905
803
|
return mountedElements;
|
|
906
804
|
});
|
|
@@ -915,7 +813,6 @@ var preCheckoutModalButtonId = {
|
|
|
915
813
|
PAYSTACK_POP_BUTTON: 'paystackpop-button',
|
|
916
814
|
PAY_WITH_VAULT_BUTTON: 'pay-with-vault-button'
|
|
917
815
|
};
|
|
918
|
-
|
|
919
816
|
function createOpenPaystackPopButton(buttonText) {
|
|
920
817
|
var openPaystackPopButton = document.createElement('button');
|
|
921
818
|
openPaystackPopButton.id = preCheckoutModalButtonId.PAYSTACK_POP_BUTTON;
|
|
@@ -923,17 +820,14 @@ function createOpenPaystackPopButton(buttonText) {
|
|
|
923
820
|
openPaystackPopButton.innerText = buttonText;
|
|
924
821
|
return openPaystackPopButton;
|
|
925
822
|
}
|
|
926
|
-
|
|
927
823
|
function getPreCheckoutModalOpenPaystackPopButton(modal) {
|
|
928
824
|
return modal.querySelector("#".concat(preCheckoutModalButtonId.PAYSTACK_POP_BUTTON));
|
|
929
825
|
}
|
|
930
|
-
|
|
931
826
|
function createPaymentRequestContainer() {
|
|
932
827
|
var paymentRequestContainer = document.createElement('div');
|
|
933
828
|
paymentRequestContainer.id = preCheckoutModalButtonId.PAYMENT_REQUEST_BUTTON;
|
|
934
829
|
return paymentRequestContainer;
|
|
935
830
|
}
|
|
936
|
-
|
|
937
831
|
function getPreCheckoutModalPaymentRequestContainer(modal) {
|
|
938
832
|
return modal.querySelector("#".concat(preCheckoutModalButtonId.PAYMENT_REQUEST_BUTTON));
|
|
939
833
|
}
|
|
@@ -941,7 +835,6 @@ function removePreCheckoutModalPaymentRequestContainer(modal) {
|
|
|
941
835
|
var paymentRequestContainer = getPreCheckoutModalPaymentRequestContainer(modal);
|
|
942
836
|
paymentRequestContainer.remove();
|
|
943
837
|
}
|
|
944
|
-
|
|
945
838
|
function createPayWithVaultButton() {
|
|
946
839
|
var payWithVaultButton = document.createElement('button');
|
|
947
840
|
payWithVaultButton.className = 'pay-with-vault-button';
|
|
@@ -949,11 +842,9 @@ function createPayWithVaultButton() {
|
|
|
949
842
|
payWithVaultButton.innerText = 'Pay with Vault';
|
|
950
843
|
return payWithVaultButton;
|
|
951
844
|
}
|
|
952
|
-
|
|
953
845
|
function getPreCheckoutModalPayWithVaultButton(modal) {
|
|
954
846
|
return modal.querySelector("#".concat(preCheckoutModalButtonId.PAY_WITH_VAULT_BUTTON));
|
|
955
847
|
}
|
|
956
|
-
|
|
957
848
|
function vaultPreCheckoutModalView(container) {
|
|
958
849
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
959
850
|
var logoContainer = document.createElement('div');
|
|
@@ -971,18 +862,15 @@ function vaultPreCheckoutModalView(container) {
|
|
|
971
862
|
divider.className = 'vault-divider';
|
|
972
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>';
|
|
973
864
|
container.appendChild(divider);
|
|
974
|
-
|
|
975
865
|
if (options.canPayWithApplePay) {
|
|
976
866
|
var paymentRequestContainer = createPaymentRequestContainer();
|
|
977
867
|
container.appendChild(paymentRequestContainer);
|
|
978
868
|
}
|
|
979
|
-
|
|
980
869
|
if (options.hasOtherPaymentMethods) {
|
|
981
870
|
var openPaystackPopButton = createOpenPaystackPopButton('Use other payment methods');
|
|
982
871
|
container.appendChild(openPaystackPopButton);
|
|
983
872
|
}
|
|
984
873
|
}
|
|
985
|
-
|
|
986
874
|
function defaultPreCheckoutModalView(container, _ref5) {
|
|
987
875
|
var hasOtherPaymentMethods = _ref5.hasOtherPaymentMethods;
|
|
988
876
|
var applePayIcon = document.createElement('div');
|
|
@@ -994,31 +882,25 @@ function defaultPreCheckoutModalView(container, _ref5) {
|
|
|
994
882
|
container.appendChild(instruction);
|
|
995
883
|
var paymentRequestContainer = createPaymentRequestContainer();
|
|
996
884
|
container.appendChild(paymentRequestContainer);
|
|
997
|
-
|
|
998
885
|
if (hasOtherPaymentMethods) {
|
|
999
886
|
var openPaystackPopButton = createOpenPaystackPopButton('More payment options');
|
|
1000
887
|
container.appendChild(openPaystackPopButton);
|
|
1001
888
|
}
|
|
1002
889
|
}
|
|
1003
|
-
|
|
1004
890
|
function hasNonPrecheckoutPaymentMethods(channels) {
|
|
1005
891
|
return channels.some(function (channel) {
|
|
1006
892
|
return channel !== 'apple_pay';
|
|
1007
893
|
});
|
|
1008
894
|
}
|
|
1009
|
-
|
|
1010
895
|
function mountPreCheckoutModal(id, transaction) {
|
|
1011
896
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1012
897
|
var mountedModal = document.querySelector("#pre-checkout-modal-".concat(id));
|
|
1013
|
-
|
|
1014
898
|
if (mountedModal) {
|
|
1015
899
|
if (getPreCheckoutModalOpenPaystackPopButton(mountedModal) && getPreCheckoutModalPaymentRequestContainer(mountedModal)) {
|
|
1016
900
|
return mountedModal;
|
|
1017
901
|
}
|
|
1018
|
-
|
|
1019
902
|
mountedModal.remove();
|
|
1020
903
|
}
|
|
1021
|
-
|
|
1022
904
|
var modal = document.createElement('div');
|
|
1023
905
|
modal.classList.add('pre-checkout-modal');
|
|
1024
906
|
modal.id = "pre-checkout-modal-".concat(id);
|
|
@@ -1026,16 +908,14 @@ function mountPreCheckoutModal(id, transaction) {
|
|
|
1026
908
|
var content = document.createElement('div');
|
|
1027
909
|
content.classList.add('pre-checkout-modal__content');
|
|
1028
910
|
modal.appendChild(content);
|
|
1029
|
-
|
|
1030
911
|
var _ref6 = transaction || {},
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
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;
|
|
1039
919
|
var formattedAmount = new Intl.NumberFormat('en', {
|
|
1040
920
|
style: 'currency',
|
|
1041
921
|
currency: currency,
|
|
@@ -1050,7 +930,6 @@ function mountPreCheckoutModal(id, transaction) {
|
|
|
1050
930
|
content.innerHTML += closeButton;
|
|
1051
931
|
var wrapper = document.createElement('div');
|
|
1052
932
|
wrapper.classList.add('modal-wrapper');
|
|
1053
|
-
|
|
1054
933
|
if (options.canPayWithVault) {
|
|
1055
934
|
vaultPreCheckoutModalView(wrapper, {
|
|
1056
935
|
canPayWithApplePay: options.canPayWithApplePay,
|
|
@@ -1061,13 +940,38 @@ function mountPreCheckoutModal(id, transaction) {
|
|
|
1061
940
|
hasOtherPaymentMethods: hasNonPrecheckoutPaymentMethods(channels)
|
|
1062
941
|
});
|
|
1063
942
|
}
|
|
1064
|
-
|
|
1065
943
|
wrapper.innerHTML = wrapper.innerHTML + secureByPaystackWhite + secureByPaystackGrey;
|
|
1066
944
|
content.appendChild(wrapper);
|
|
1067
945
|
var style = document.createElement('style');
|
|
1068
946
|
style.textContent = preCheckoutModalCSS;
|
|
1069
|
-
|
|
1070
|
-
|
|
947
|
+
|
|
948
|
+
// === TEMP (test): render the precheckout modal inside an iframe for ONE merchant — revert before commit ===
|
|
949
|
+
// Only the merchant whose request_inline response carries this merchant_id gets the iframe
|
|
950
|
+
// treatment; every other merchant keeps the original behaviour (modal appended to document.body).
|
|
951
|
+
var IFRAME_MODAL_MERCHANT_ID = 550652; // target merchant_id from the request inline response
|
|
952
|
+
var renderInIframe = transaction && String(transaction.merchant_id) === String(IFRAME_MODAL_MERCHANT_ID);
|
|
953
|
+
if (renderInIframe) {
|
|
954
|
+
// Host the modal + style in a full-viewport, same-origin (about:blank) iframe.
|
|
955
|
+
var hostIframe = document.createElement('iframe');
|
|
956
|
+
hostIframe.id = "pre-checkout-modal-iframe-".concat(id);
|
|
957
|
+
hostIframe.setAttribute('allow', 'payment');
|
|
958
|
+
hostIframe.style.cssText = ['position: fixed', 'top: 0', 'left: 0', 'width: 100%', 'height: 100%', 'border: 0', 'margin: 0', 'background: transparent', "z-index: ".concat(findHighestZIndex() + 1)].join(';');
|
|
959
|
+
document.body.appendChild(hostIframe);
|
|
960
|
+
var frameDocument = hostIframe.contentDocument || hostIframe.contentWindow.document;
|
|
961
|
+
frameDocument.body.style.margin = '0';
|
|
962
|
+
frameDocument.head.appendChild(style);
|
|
963
|
+
frameDocument.body.appendChild(modal);
|
|
964
|
+
|
|
965
|
+
// closePreCheckoutModal() calls modal.remove(); make that tear down the host iframe too.
|
|
966
|
+
modal.remove = function () {
|
|
967
|
+
return hostIframe.remove();
|
|
968
|
+
};
|
|
969
|
+
} else {
|
|
970
|
+
document.body.appendChild(style);
|
|
971
|
+
document.body.appendChild(modal);
|
|
972
|
+
}
|
|
973
|
+
// === END TEMP ===
|
|
974
|
+
|
|
1071
975
|
return modal;
|
|
1072
976
|
}
|
|
1073
977
|
function getPreCheckoutModalCloseButton(modal) {
|
|
@@ -1098,7 +1002,6 @@ function showErrorInPreCheckoutModal(modal) {
|
|
|
1098
1002
|
if (!modal) {
|
|
1099
1003
|
return;
|
|
1100
1004
|
}
|
|
1101
|
-
|
|
1102
1005
|
var appleIcon = modal.querySelector('#apple-pay-mark--light');
|
|
1103
1006
|
appleIcon.innerHTML = errorIcon;
|
|
1104
1007
|
var applePayDescription = modal.querySelector('#apple-pay-description');
|
|
@@ -1335,33 +1238,32 @@ function validate(args) {
|
|
|
1335
1238
|
this.message = message;
|
|
1336
1239
|
this.issues = issues || [];
|
|
1337
1240
|
}
|
|
1338
|
-
|
|
1339
1241
|
if (!args || _typeof(args) !== 'object') {
|
|
1340
1242
|
throw new ValidationError('Transaction parameters should be a non-empty object');
|
|
1341
1243
|
}
|
|
1244
|
+
var transactionParameters = args;
|
|
1342
1245
|
|
|
1343
|
-
|
|
1344
|
-
|
|
1246
|
+
// If it's a transaction resumption, move on
|
|
1345
1247
|
if ('accessCode' in transactionParameters) {
|
|
1346
1248
|
var accessCode = transactionParameters.accessCode;
|
|
1347
1249
|
return {
|
|
1348
1250
|
accessCode: accessCode
|
|
1349
1251
|
};
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1252
|
+
}
|
|
1352
1253
|
|
|
1254
|
+
// Filter unneeded parameters
|
|
1353
1255
|
Object.keys(transactionParameters).forEach(function (key) {
|
|
1354
1256
|
var usedParameter = allParameters.find(function (parameter) {
|
|
1355
1257
|
return parameter.value === key;
|
|
1356
1258
|
}) !== undefined;
|
|
1357
|
-
|
|
1358
1259
|
if (!usedParameter) {
|
|
1359
1260
|
delete transactionParameters[key];
|
|
1360
1261
|
}
|
|
1361
1262
|
});
|
|
1362
1263
|
var transactionKeys = Object.keys(transactionParameters);
|
|
1363
|
-
var validationErrors = [];
|
|
1264
|
+
var validationErrors = [];
|
|
1364
1265
|
|
|
1266
|
+
// Check for required parameters
|
|
1365
1267
|
var requiredParameters = allParameters.filter(function (param) {
|
|
1366
1268
|
return param.required;
|
|
1367
1269
|
});
|
|
@@ -1370,50 +1272,44 @@ function validate(args) {
|
|
|
1370
1272
|
var parameterHasAlternative = key.or ? key.or.some(function (option) {
|
|
1371
1273
|
return transactionParameters[option];
|
|
1372
1274
|
}) : null;
|
|
1373
|
-
|
|
1374
1275
|
if (parameterIsMissing && !parameterHasAlternative) {
|
|
1375
1276
|
validationErrors.push({
|
|
1376
1277
|
message: "Required parameter missing: ".concat(key.value)
|
|
1377
1278
|
});
|
|
1378
1279
|
}
|
|
1379
|
-
});
|
|
1280
|
+
});
|
|
1380
1281
|
|
|
1282
|
+
// Check for validity
|
|
1381
1283
|
transactionKeys.forEach(function (key) {
|
|
1382
1284
|
var parameterValue = transactionParameters[key];
|
|
1383
1285
|
var parameterObject = allParameters.find(function (parameter) {
|
|
1384
1286
|
return parameter.value === key;
|
|
1385
1287
|
});
|
|
1386
|
-
|
|
1387
1288
|
var providedType = _typeof(parameterValue);
|
|
1388
|
-
|
|
1389
1289
|
if (providedType === 'object' && Array.isArray(parameterValue)) {
|
|
1390
1290
|
providedType = 'array';
|
|
1391
1291
|
}
|
|
1392
|
-
|
|
1393
1292
|
var invalidType = parameterObject.types.indexOf(providedType) <= -1;
|
|
1394
|
-
|
|
1395
1293
|
if (invalidType) {
|
|
1396
1294
|
validationErrors.push({
|
|
1397
1295
|
message: "Invalid parameter type: ".concat(key),
|
|
1398
1296
|
validTypes: parameterObject.types
|
|
1399
1297
|
});
|
|
1400
1298
|
}
|
|
1401
|
-
});
|
|
1299
|
+
});
|
|
1402
1300
|
|
|
1301
|
+
// Override keys where necessary
|
|
1403
1302
|
transactionKeys.forEach(function (key) {
|
|
1404
1303
|
var parameterObject = allParameters.find(function (parameter) {
|
|
1405
1304
|
return parameter.value === key;
|
|
1406
1305
|
});
|
|
1407
|
-
|
|
1408
1306
|
if (parameterObject.override) {
|
|
1409
1307
|
delete transactionParameters[parameterObject.override];
|
|
1410
1308
|
}
|
|
1411
1309
|
});
|
|
1412
|
-
|
|
1413
1310
|
if (validationErrors.length) {
|
|
1414
1311
|
throw new ValidationError('Invalid transaction parameters', validationErrors);
|
|
1415
1312
|
}
|
|
1416
|
-
|
|
1417
1313
|
return transactionParameters;
|
|
1418
1314
|
}
|
|
1419
1315
|
|
|
@@ -1422,31 +1318,26 @@ function splitURL(url) {
|
|
|
1422
1318
|
if ((url === null || url === void 0 ? void 0 : url.length) > 500) {
|
|
1423
1319
|
return url.split('?')[0];
|
|
1424
1320
|
}
|
|
1425
|
-
|
|
1426
1321
|
return url;
|
|
1427
1322
|
}
|
|
1428
|
-
|
|
1429
1323
|
function getReferrer() {
|
|
1430
1324
|
var _window$location = window.location,
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1325
|
+
_window$location$href = _window$location.href,
|
|
1326
|
+
href = _window$location$href === void 0 ? '' : _window$location$href,
|
|
1327
|
+
_window$location$ance = _window$location.ancestorOrigins,
|
|
1328
|
+
ancestorOrigins = _window$location$ance === void 0 ? [] : _window$location$ance;
|
|
1435
1329
|
return [href].concat(_toConsumableArray(ancestorOrigins)).map(splitURL).join(',');
|
|
1436
1330
|
}
|
|
1437
1331
|
|
|
1438
1332
|
function buildQuery(parameters) {
|
|
1439
1333
|
var formattedParameters = _objectSpread2({}, parameters);
|
|
1440
|
-
|
|
1441
1334
|
formattedParameters.metadata = parameters.metadata || {};
|
|
1442
1335
|
formattedParameters.metadata.referrer = getReferrer();
|
|
1443
1336
|
formattedParameters.metadata = JSON.stringify(formattedParameters.metadata);
|
|
1444
1337
|
formattedParameters.mode = 'popup';
|
|
1445
|
-
|
|
1446
1338
|
if (parameters.split && typeof parameters.split !== 'string') {
|
|
1447
1339
|
formattedParameters.split = JSON.stringify(formattedParameters.split);
|
|
1448
1340
|
}
|
|
1449
|
-
|
|
1450
1341
|
var parametersToChange = [{
|
|
1451
1342
|
to: 'firstname',
|
|
1452
1343
|
from: 'firstName'
|
|
@@ -1483,21 +1374,20 @@ function buildQuery(parameters) {
|
|
|
1483
1374
|
}, {
|
|
1484
1375
|
to: 'ref',
|
|
1485
1376
|
from: 'reference'
|
|
1486
|
-
}];
|
|
1377
|
+
}];
|
|
1378
|
+
|
|
1379
|
+
// handle very old case of people disabling channels by sending card/bank params
|
|
1487
1380
|
|
|
1488
1381
|
if (formattedParameters.card !== undefined && ['false', false].indexOf(formattedParameters.card) > -1) {
|
|
1489
1382
|
formattedParameters.channels = ['bank'];
|
|
1490
1383
|
delete formattedParameters.card;
|
|
1491
1384
|
}
|
|
1492
|
-
|
|
1493
1385
|
if (formattedParameters.bank !== undefined && ['false', false].indexOf(formattedParameters.bank) > -1) {
|
|
1494
1386
|
formattedParameters.channels = ['card'];
|
|
1495
1387
|
delete formattedParameters.bank;
|
|
1496
1388
|
}
|
|
1497
|
-
|
|
1498
1389
|
parametersToChange.forEach(function (key) {
|
|
1499
1390
|
var hasValue = formattedParameters[key.from];
|
|
1500
|
-
|
|
1501
1391
|
if (hasValue) {
|
|
1502
1392
|
formattedParameters[key.to] = formattedParameters[key.from];
|
|
1503
1393
|
delete formattedParameters[key.from];
|
|
@@ -1513,22 +1403,23 @@ function buildQuery(parameters) {
|
|
|
1513
1403
|
}
|
|
1514
1404
|
|
|
1515
1405
|
/* eslint-env browser */
|
|
1406
|
+
|
|
1516
1407
|
var iOSDevices = ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'];
|
|
1408
|
+
|
|
1517
1409
|
/**
|
|
1518
1410
|
* navigator.platform is deprecated and will eventually be removed
|
|
1519
1411
|
* but the recommended alternative `navigator.userAgentData` has limited browser support
|
|
1520
1412
|
* so it is used as a fallback here.
|
|
1521
1413
|
*/
|
|
1522
|
-
|
|
1523
1414
|
var DEVICE_PLATFORM = window && window.navigator && (window.navigator.platform || window.navigator.userAgentData && window.navigator.userAgentData.platform);
|
|
1524
1415
|
var isIOS = function isIOS() {
|
|
1525
1416
|
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1417
|
+
platform = _ref.platform,
|
|
1418
|
+
_ref$userAgent = _ref.userAgent,
|
|
1419
|
+
userAgent = _ref$userAgent === void 0 ? window && window.navigator && window.navigator.userAgent : _ref$userAgent;
|
|
1530
1420
|
var devicePlatform = platform || DEVICE_PLATFORM;
|
|
1531
|
-
return iOSDevices.includes(devicePlatform) ||
|
|
1421
|
+
return iOSDevices.includes(devicePlatform) ||
|
|
1422
|
+
// iPAD os safari detection. iPad OS uses the same version of safari as Mac OS
|
|
1532
1423
|
userAgent.includes('Mac') && 'ontouchend' in document;
|
|
1533
1424
|
};
|
|
1534
1425
|
|
|
@@ -1562,11 +1453,10 @@ var AnalyticsAPI = {
|
|
|
1562
1453
|
var AnalyticsFunctions = {
|
|
1563
1454
|
initializeLog: function initializeLog(log) {
|
|
1564
1455
|
var _ref = log || {},
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1456
|
+
attempts = _ref.attempts,
|
|
1457
|
+
authentication = _ref.authentication,
|
|
1458
|
+
errors = _ref.errors,
|
|
1459
|
+
history = _ref.history;
|
|
1570
1460
|
this.log = {
|
|
1571
1461
|
start_time: Math.round(Date.now() / 1000),
|
|
1572
1462
|
time_spent: 0,
|
|
@@ -1588,10 +1478,8 @@ var AnalyticsFunctions = {
|
|
|
1588
1478
|
switch (response.status) {
|
|
1589
1479
|
case 'success':
|
|
1590
1480
|
return this.logApiSuccess(channel);
|
|
1591
|
-
|
|
1592
1481
|
case 'failed':
|
|
1593
1482
|
return this.logApiError(response.message);
|
|
1594
|
-
|
|
1595
1483
|
default:
|
|
1596
1484
|
return false;
|
|
1597
1485
|
}
|
|
@@ -1606,11 +1494,9 @@ var AnalyticsFunctions = {
|
|
|
1606
1494
|
},
|
|
1607
1495
|
logAttempt: function logAttempt(channel) {
|
|
1608
1496
|
var message = 'Attempted to pay';
|
|
1609
|
-
|
|
1610
1497
|
if (channel) {
|
|
1611
1498
|
message += " with ".concat(channel);
|
|
1612
1499
|
}
|
|
1613
|
-
|
|
1614
1500
|
this.log.attempts += 1;
|
|
1615
1501
|
this.log.history.push({
|
|
1616
1502
|
type: 'action',
|
|
@@ -1621,11 +1507,9 @@ var AnalyticsFunctions = {
|
|
|
1621
1507
|
},
|
|
1622
1508
|
logApiError: function logApiError(error) {
|
|
1623
1509
|
var message = 'Error';
|
|
1624
|
-
|
|
1625
1510
|
if (error) {
|
|
1626
1511
|
message += ": ".concat(error);
|
|
1627
1512
|
}
|
|
1628
|
-
|
|
1629
1513
|
this.log.errors += 1;
|
|
1630
1514
|
this.log.history.push({
|
|
1631
1515
|
type: 'error',
|
|
@@ -1636,11 +1520,9 @@ var AnalyticsFunctions = {
|
|
|
1636
1520
|
},
|
|
1637
1521
|
logApiSuccess: function logApiSuccess(channel) {
|
|
1638
1522
|
var message = 'Successfully paid';
|
|
1639
|
-
|
|
1640
1523
|
if (channel) {
|
|
1641
1524
|
message += " with ".concat(channel);
|
|
1642
1525
|
}
|
|
1643
|
-
|
|
1644
1526
|
this.log.success = true;
|
|
1645
1527
|
this.log.history.push({
|
|
1646
1528
|
type: 'success',
|
|
@@ -1654,9 +1536,9 @@ var AnalyticsFunctions = {
|
|
|
1654
1536
|
if (this.response) {
|
|
1655
1537
|
return AnalyticsAPI.saveLog(this.id, this.response.merchant_key, this.log);
|
|
1656
1538
|
}
|
|
1657
|
-
} catch (error) {
|
|
1539
|
+
} catch (error) {
|
|
1540
|
+
// we don't need to do anything since this should not affect the transaction
|
|
1658
1541
|
}
|
|
1659
|
-
|
|
1660
1542
|
return undefined;
|
|
1661
1543
|
},
|
|
1662
1544
|
saveIpAddress: function saveIpAddress() {
|
|
@@ -1664,9 +1546,9 @@ var AnalyticsFunctions = {
|
|
|
1664
1546
|
if (this.response) {
|
|
1665
1547
|
return AnalyticsAPI.saveIp(this.id, this.response.merchant_key);
|
|
1666
1548
|
}
|
|
1667
|
-
} catch (error) {
|
|
1549
|
+
} catch (error) {
|
|
1550
|
+
// we don't need to do anything since this should not affect the transaction
|
|
1668
1551
|
}
|
|
1669
|
-
|
|
1670
1552
|
return undefined;
|
|
1671
1553
|
}
|
|
1672
1554
|
};
|
|
@@ -1675,20 +1557,16 @@ var _excluded$1 = ["language", "connect_account"];
|
|
|
1675
1557
|
var TransactionApi = {
|
|
1676
1558
|
requestInline: function requestInline() {
|
|
1677
1559
|
var inlineTransactionInstance = this;
|
|
1678
|
-
|
|
1679
1560
|
var _this$urlParameters = this.urlParameters,
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1561
|
+
language = _this$urlParameters.language,
|
|
1562
|
+
connectAccount = _this$urlParameters.connect_account,
|
|
1563
|
+
params = _objectWithoutProperties(_this$urlParameters, _excluded$1);
|
|
1684
1564
|
var request;
|
|
1685
|
-
|
|
1686
1565
|
var headers = _objectSpread2({
|
|
1687
1566
|
'Content-Type': 'application/json'
|
|
1688
1567
|
}, language && {
|
|
1689
1568
|
'Accept-Language': language
|
|
1690
1569
|
});
|
|
1691
|
-
|
|
1692
1570
|
if (this.accessCode) {
|
|
1693
1571
|
request = fetch(new URL("transaction/verify_access_code/".concat(this.accessCode), config.paystackApiUrl).toString(), {
|
|
1694
1572
|
headers: headers
|
|
@@ -1702,19 +1580,18 @@ var TransactionApi = {
|
|
|
1702
1580
|
})
|
|
1703
1581
|
});
|
|
1704
1582
|
}
|
|
1705
|
-
|
|
1706
1583
|
return request.then(function (res) {
|
|
1707
1584
|
return res.json();
|
|
1708
1585
|
}).then(function (res) {
|
|
1709
1586
|
if (res.status === false) {
|
|
1710
1587
|
throw new Error(res.message);
|
|
1711
1588
|
}
|
|
1712
|
-
|
|
1713
1589
|
inlineTransactionInstance.response = res.data;
|
|
1714
1590
|
inlineTransactionInstance.id = res.data.id;
|
|
1715
1591
|
inlineTransactionInstance.status = res.data.transaction_status;
|
|
1716
|
-
inlineTransactionInstance.accessCode = res.data.access_code;
|
|
1592
|
+
inlineTransactionInstance.accessCode = res.data.access_code;
|
|
1717
1593
|
|
|
1594
|
+
// Analytics
|
|
1718
1595
|
inlineTransactionInstance.log = null;
|
|
1719
1596
|
Object.assign(inlineTransactionInstance, AnalyticsFunctions);
|
|
1720
1597
|
inlineTransactionInstance.initializeLog(res.data.log);
|
|
@@ -1727,7 +1604,6 @@ var TransactionApi = {
|
|
|
1727
1604
|
var InlineTransaction = /*#__PURE__*/function () {
|
|
1728
1605
|
function InlineTransaction(data) {
|
|
1729
1606
|
_classCallCheck(this, InlineTransaction);
|
|
1730
|
-
|
|
1731
1607
|
validate(data);
|
|
1732
1608
|
this.parameters = data;
|
|
1733
1609
|
this.urlParameters = buildQuery(data);
|
|
@@ -1739,12 +1615,12 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1739
1615
|
this.response = null;
|
|
1740
1616
|
this.isActive = true;
|
|
1741
1617
|
var onError = data.onError,
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1618
|
+
onLoad = data.onLoad,
|
|
1619
|
+
onSuccess = data.onSuccess,
|
|
1620
|
+
onCancel = data.onCancel,
|
|
1621
|
+
callback = data.callback,
|
|
1622
|
+
onClose = data.onClose,
|
|
1623
|
+
onBankTransferConfirmationPending = data.onBankTransferConfirmationPending;
|
|
1748
1624
|
this.callbacks = {
|
|
1749
1625
|
onError: onError,
|
|
1750
1626
|
onLoad: onLoad,
|
|
@@ -1758,12 +1634,10 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1758
1634
|
};
|
|
1759
1635
|
Object.assign(this, TransactionApi);
|
|
1760
1636
|
}
|
|
1761
|
-
|
|
1762
|
-
_createClass(InlineTransaction, [{
|
|
1637
|
+
return _createClass(InlineTransaction, [{
|
|
1763
1638
|
key: "onSetupError",
|
|
1764
1639
|
value: function onSetupError(response) {
|
|
1765
1640
|
this.logError(response);
|
|
1766
|
-
|
|
1767
1641
|
if (this.callbacks.onError) {
|
|
1768
1642
|
this.callbacks.onError(response);
|
|
1769
1643
|
}
|
|
@@ -1772,15 +1646,14 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1772
1646
|
key: "onLoad",
|
|
1773
1647
|
value: function onLoad(response) {
|
|
1774
1648
|
var id = response.id,
|
|
1775
|
-
|
|
1776
|
-
|
|
1649
|
+
customer = response.customer,
|
|
1650
|
+
accessCode = response.accessCode;
|
|
1777
1651
|
Object.assign(this, {
|
|
1778
1652
|
id: id,
|
|
1779
1653
|
customer: customer,
|
|
1780
1654
|
accessCode: accessCode
|
|
1781
1655
|
});
|
|
1782
1656
|
this.authorizationUrl = "".concat(config.checkoutUrl).concat(accessCode);
|
|
1783
|
-
|
|
1784
1657
|
if (this.callbacks.onLoad) {
|
|
1785
1658
|
this.callbacks.onLoad({
|
|
1786
1659
|
id: id,
|
|
@@ -1795,12 +1668,10 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1795
1668
|
this.isActive = false;
|
|
1796
1669
|
this.response = response;
|
|
1797
1670
|
this.status = response.status;
|
|
1798
|
-
|
|
1799
1671
|
if (this.callbacks.onSuccess) {
|
|
1800
1672
|
this.callbacks.onSuccess(response);
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1673
|
+
}
|
|
1674
|
+
// Added for backwards compatibility
|
|
1804
1675
|
if (this.deprecatedCallbacks.callback) {
|
|
1805
1676
|
this.deprecatedCallbacks.callback(response);
|
|
1806
1677
|
}
|
|
@@ -1815,9 +1686,8 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1815
1686
|
value: function onCancel() {
|
|
1816
1687
|
if (this.callbacks.onCancel) {
|
|
1817
1688
|
this.callbacks.onCancel();
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
|
|
1689
|
+
}
|
|
1690
|
+
// Added for backwards compatibility
|
|
1821
1691
|
if (this.deprecatedCallbacks.onClose) {
|
|
1822
1692
|
this.deprecatedCallbacks.onClose();
|
|
1823
1693
|
}
|
|
@@ -1832,7 +1702,6 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1832
1702
|
key: "onBankTransferConfirmationPending",
|
|
1833
1703
|
value: function onBankTransferConfirmationPending() {
|
|
1834
1704
|
this.cancel();
|
|
1835
|
-
|
|
1836
1705
|
if (this.callbacks.onBankTransferConfirmationPending) {
|
|
1837
1706
|
this.callbacks.onBankTransferConfirmationPending();
|
|
1838
1707
|
}
|
|
@@ -1843,13 +1712,10 @@ var InlineTransaction = /*#__PURE__*/function () {
|
|
|
1843
1712
|
this.errors.push(error);
|
|
1844
1713
|
}
|
|
1845
1714
|
}]);
|
|
1846
|
-
|
|
1847
|
-
return InlineTransaction;
|
|
1848
1715
|
}();
|
|
1849
1716
|
|
|
1850
1717
|
var canUseVault = function canUseVault() {
|
|
1851
1718
|
var _transaction$link_con, _transaction$link_con2;
|
|
1852
|
-
|
|
1853
1719
|
var transaction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1854
1720
|
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);
|
|
1855
1721
|
};
|
|
@@ -1861,14 +1727,12 @@ function printDeprecationNotice(oldName, newName, extraMessage) {
|
|
|
1861
1727
|
}
|
|
1862
1728
|
|
|
1863
1729
|
var _excluded = ["preload", "inlineTransaction", "transactionData"],
|
|
1864
|
-
|
|
1730
|
+
_excluded2 = ["container", "styles", "onElementsMount"];
|
|
1865
1731
|
var inlineInstance;
|
|
1866
|
-
|
|
1867
1732
|
function findResumableTransaction(transactions, parameters) {
|
|
1868
1733
|
if (!transactions.length) {
|
|
1869
1734
|
return null;
|
|
1870
1735
|
}
|
|
1871
|
-
|
|
1872
1736
|
var similarAbandonedTransactions = transactions.filter(function (transaction) {
|
|
1873
1737
|
var isAbandoned = !transaction.status || transaction.status === 'abandoned';
|
|
1874
1738
|
var hasSimilarParameters = similarObjects(transaction.parameters, parameters);
|
|
@@ -1877,39 +1741,32 @@ function findResumableTransaction(transactions, parameters) {
|
|
|
1877
1741
|
var resumableTransaction = similarAbandonedTransactions.length ? similarAbandonedTransactions[similarAbandonedTransactions.length - 1] : null;
|
|
1878
1742
|
return resumableTransaction;
|
|
1879
1743
|
}
|
|
1880
|
-
|
|
1881
1744
|
function notifyIframeToUpdateURL(options) {
|
|
1882
1745
|
var checkoutIframe = options.checkoutIframe,
|
|
1883
|
-
|
|
1884
|
-
|
|
1746
|
+
urlParameters = options.urlParameters;
|
|
1885
1747
|
if (!checkoutIframe || !urlParameters) {
|
|
1886
1748
|
return;
|
|
1887
1749
|
}
|
|
1888
|
-
|
|
1889
1750
|
checkoutIframe.contentWindow.postMessage({
|
|
1890
1751
|
type: 'inline:url',
|
|
1891
1752
|
path: 'newTransaction',
|
|
1892
1753
|
params: urlParameters
|
|
1893
1754
|
}, '*');
|
|
1894
1755
|
}
|
|
1895
|
-
|
|
1896
1756
|
var analyticsActions = {
|
|
1897
1757
|
TRACK_CHECKOUT_CLOSED: 'trackCheckoutClosed',
|
|
1898
1758
|
TRACK_PAYMENT_ERROR: 'trackPaymentError',
|
|
1899
1759
|
TRACK_PAYMENT_ATTEMPT: 'trackPaymentAttempt',
|
|
1900
1760
|
TRACK_PAYMENT_COMPLETION: 'trackPaymentCompletion'
|
|
1901
1761
|
};
|
|
1902
|
-
|
|
1903
1762
|
function handleError(message) {
|
|
1904
1763
|
logWarning(message);
|
|
1905
1764
|
throw new Error(message);
|
|
1906
1765
|
}
|
|
1907
|
-
|
|
1908
1766
|
function transactionCanUseApplePay(response, container) {
|
|
1909
1767
|
if (!(response && response.channels && response.channels.includes('apple_pay'))) {
|
|
1910
1768
|
return Promise.resolve(false);
|
|
1911
1769
|
}
|
|
1912
|
-
|
|
1913
1770
|
return ensureApplePaySdkLoaded(container).catch(function () {
|
|
1914
1771
|
// Native Apple Pay support can still be available even if the SDK fails to load.
|
|
1915
1772
|
return null;
|
|
@@ -1917,44 +1774,36 @@ function transactionCanUseApplePay(response, container) {
|
|
|
1917
1774
|
return canUseApplePay(response.channels);
|
|
1918
1775
|
});
|
|
1919
1776
|
}
|
|
1920
|
-
|
|
1921
1777
|
var Inline = /*#__PURE__*/function () {
|
|
1922
1778
|
function Inline(params) {
|
|
1923
1779
|
_classCallCheck(this, Inline);
|
|
1924
|
-
|
|
1925
1780
|
this.id = randomId();
|
|
1926
1781
|
this.transactions = [];
|
|
1927
1782
|
this.isOpen = false;
|
|
1928
1783
|
this.isLoaded = false;
|
|
1929
1784
|
this.isDeprecatedApi = params && params.isDeprecatedApi; // track deprecatedApi
|
|
1930
|
-
|
|
1931
1785
|
if (params && params.isEmbed) {
|
|
1932
1786
|
this.isEmbed = true;
|
|
1933
1787
|
} else if (params && params.isPaymentRequest) {
|
|
1934
1788
|
if (!(params.container && getPaymentRequestContainer(params.container))) {
|
|
1935
1789
|
handleError('A container is required to mount the payment request button');
|
|
1936
1790
|
}
|
|
1937
|
-
|
|
1938
1791
|
this.paymentRequestContainer = getPaymentRequestContainer(params.container);
|
|
1939
1792
|
this.paymentRequestTransaction = null;
|
|
1940
1793
|
}
|
|
1941
|
-
|
|
1942
1794
|
this.preCheckoutModal = null;
|
|
1943
1795
|
this.backgroundIframe = mountBackgroundIframe(this.id);
|
|
1944
1796
|
this.checkoutIframe = mountCheckoutIframe(this.id);
|
|
1945
1797
|
this.registerListeners();
|
|
1946
1798
|
}
|
|
1947
|
-
|
|
1948
|
-
_createClass(Inline, [{
|
|
1799
|
+
return _createClass(Inline, [{
|
|
1949
1800
|
key: "registerListeners",
|
|
1950
1801
|
value: function registerListeners() {
|
|
1951
1802
|
var _this = this;
|
|
1952
|
-
|
|
1953
1803
|
window.addEventListener('message', function (event) {
|
|
1954
1804
|
var isCheckoutIframe = "".concat(event.origin, "/") === config.checkoutUrl;
|
|
1955
1805
|
var isThisInline = _this.checkoutIframe && _this.checkoutIframe.contentWindow === event.source;
|
|
1956
1806
|
var isEmbed = _this.isEmbed;
|
|
1957
|
-
|
|
1958
1807
|
if (isCheckoutIframe || isThisInline) {
|
|
1959
1808
|
_this.respondToEvent(event);
|
|
1960
1809
|
} else if (isEmbed) {
|
|
@@ -1977,7 +1826,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
1977
1826
|
if (this.activeTransaction()) {
|
|
1978
1827
|
this.activeTransaction().cancel();
|
|
1979
1828
|
}
|
|
1980
|
-
|
|
1981
1829
|
inlineInstance = this;
|
|
1982
1830
|
var resumableTransaction = findResumableTransaction(this.transactions, params);
|
|
1983
1831
|
var transaction = resumableTransaction || new InlineTransaction(params);
|
|
@@ -1991,10 +1839,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
1991
1839
|
});
|
|
1992
1840
|
}).then(function (_ref) {
|
|
1993
1841
|
var response = _ref.response,
|
|
1994
|
-
|
|
1842
|
+
canPayWithApplePay = _ref.canPayWithApplePay;
|
|
1995
1843
|
var canPayWithVault = canUseVault(response);
|
|
1996
1844
|
var shouldLoadPreCheckoutModal = canPayWithVault || canPayWithApplePay;
|
|
1997
|
-
|
|
1998
1845
|
if (!shouldLoadPreCheckoutModal) {
|
|
1999
1846
|
inlineInstance.newTransaction({
|
|
2000
1847
|
inlineTransaction: transaction,
|
|
@@ -2010,11 +1857,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2010
1857
|
canPayWithVault: canPayWithVault,
|
|
2011
1858
|
canPayWithApplePay: canPayWithApplePay
|
|
2012
1859
|
});
|
|
1860
|
+
|
|
2013
1861
|
/**
|
|
2014
1862
|
* We attempt to mount the apple pay button only
|
|
2015
1863
|
* when the customer can pay with apple pay.
|
|
2016
1864
|
*/
|
|
2017
|
-
|
|
2018
1865
|
if (canPayWithApplePay) {
|
|
2019
1866
|
inlineInstance.paymentRequestContainer = getPreCheckoutModalPaymentRequestContainer(inlineInstance.preCheckoutModal);
|
|
2020
1867
|
mountPaymentRequestButtons(inlineInstance.paymentRequestContainer, {
|
|
@@ -2069,15 +1916,12 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2069
1916
|
key: "registerPreCheckoutModalEventListeners",
|
|
2070
1917
|
value: function registerPreCheckoutModalEventListeners() {
|
|
2071
1918
|
var _this2 = this;
|
|
2072
|
-
|
|
2073
1919
|
var timer;
|
|
2074
1920
|
var isShortTouch = false;
|
|
2075
1921
|
var shortTouchDurationInMs = 125;
|
|
2076
1922
|
var activeTransaction = this.activeTransaction();
|
|
2077
|
-
|
|
2078
1923
|
var handleTouchStart = function handleTouchStart(event) {
|
|
2079
1924
|
event.preventDefault();
|
|
2080
|
-
|
|
2081
1925
|
if (!isShortTouch) {
|
|
2082
1926
|
isShortTouch = true;
|
|
2083
1927
|
timer = setTimeout(function () {
|
|
@@ -2085,51 +1929,38 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2085
1929
|
}, shortTouchDurationInMs);
|
|
2086
1930
|
}
|
|
2087
1931
|
};
|
|
2088
|
-
|
|
2089
1932
|
var handleClosePreCheckoutModal = function handleClosePreCheckoutModal(event) {
|
|
2090
1933
|
if (event.target && event.target.isSameNode(inlineInstance.preCheckoutModal) && isShortTouch) {
|
|
2091
1934
|
clearTimeout(timer);
|
|
2092
1935
|
inlineInstance.closePreCheckoutModal();
|
|
2093
|
-
|
|
2094
1936
|
if (activeTransaction) {
|
|
2095
1937
|
activeTransaction.cancel();
|
|
2096
1938
|
}
|
|
2097
1939
|
}
|
|
2098
|
-
|
|
2099
1940
|
isShortTouch = false;
|
|
2100
1941
|
};
|
|
2101
|
-
|
|
2102
1942
|
document.addEventListener('touchstart', handleTouchStart, true);
|
|
2103
1943
|
document.addEventListener('touchend', handleClosePreCheckoutModal, true);
|
|
2104
1944
|
var openPaystackPopButton = getPreCheckoutModalOpenPaystackPopButton(this.preCheckoutModal);
|
|
2105
|
-
|
|
2106
1945
|
if (openPaystackPopButton) {
|
|
2107
1946
|
openPaystackPopButton.onclick = function () {
|
|
2108
1947
|
_this2.closePreCheckoutModal();
|
|
2109
|
-
|
|
2110
1948
|
_this2.animateCheckoutIn();
|
|
2111
1949
|
};
|
|
2112
1950
|
}
|
|
2113
|
-
|
|
2114
1951
|
var payWithVaultButton = getPreCheckoutModalPayWithVaultButton(this.preCheckoutModal);
|
|
2115
|
-
|
|
2116
1952
|
if (payWithVaultButton) {
|
|
2117
1953
|
payWithVaultButton.onclick = function () {
|
|
2118
1954
|
_this2.closePreCheckoutModal();
|
|
2119
|
-
|
|
2120
1955
|
_this2.animateCheckoutIn();
|
|
2121
|
-
|
|
2122
1956
|
_this2.checkoutIframe.contentWindow.postMessage({
|
|
2123
1957
|
type: 'inline:pay-with-vault'
|
|
2124
1958
|
}, '*');
|
|
2125
1959
|
};
|
|
2126
1960
|
}
|
|
2127
|
-
|
|
2128
1961
|
var preCheckoutModalCloseButton = getPreCheckoutModalCloseButton(this.preCheckoutModal);
|
|
2129
|
-
|
|
2130
1962
|
preCheckoutModalCloseButton.onclick = function () {
|
|
2131
1963
|
_this2.sendAnalyticsEventToCheckout(analyticsActions.TRACK_CHECKOUT_CLOSED);
|
|
2132
|
-
|
|
2133
1964
|
_this2.closePreCheckoutModalAndCancelTransaction();
|
|
2134
1965
|
};
|
|
2135
1966
|
}
|
|
@@ -2139,7 +1970,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2139
1970
|
if (!this.preCheckoutModal) {
|
|
2140
1971
|
return;
|
|
2141
1972
|
}
|
|
2142
|
-
|
|
2143
1973
|
if (transactionStatus === 'failed') {
|
|
2144
1974
|
showErrorInPreCheckoutModal(this.preCheckoutModal);
|
|
2145
1975
|
animatePreCheckoutModalIn(this.preCheckoutModal);
|
|
@@ -2154,11 +1984,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2154
1984
|
value: function closePreCheckoutModalAndCancelTransaction() {
|
|
2155
1985
|
if (this.preCheckoutModal) {
|
|
2156
1986
|
this.cancelTransaction();
|
|
2157
|
-
|
|
2158
1987
|
if (this.checkoutIframe && this.checkoutIframe.contentWindow) {
|
|
2159
1988
|
this.checkoutIframe.contentWindow.postMessage('close', '*');
|
|
2160
1989
|
}
|
|
2161
|
-
|
|
2162
1990
|
this.closePreCheckoutModal();
|
|
2163
1991
|
}
|
|
2164
1992
|
}
|
|
@@ -2166,19 +1994,15 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2166
1994
|
key: "newTransaction",
|
|
2167
1995
|
value: function newTransaction(_ref2) {
|
|
2168
1996
|
var preload = _ref2.preload,
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
1997
|
+
inlineTransaction = _ref2.inlineTransaction,
|
|
1998
|
+
transactionData = _ref2.transactionData,
|
|
1999
|
+
options = _objectWithoutProperties(_ref2, _excluded);
|
|
2173
2000
|
var hasPaymentRequestButtons = this.paymentRequestContainer && getApplePayButton(this.paymentRequestContainer);
|
|
2174
|
-
|
|
2175
2001
|
if (this.activeTransaction() && !hasPaymentRequestButtons) {
|
|
2176
2002
|
this.activeTransaction().cancel();
|
|
2177
2003
|
}
|
|
2178
|
-
|
|
2179
2004
|
if (inlineTransaction && transactionData) {
|
|
2180
2005
|
this.transactions.push(inlineTransaction);
|
|
2181
|
-
|
|
2182
2006
|
if (!this.isDeprecatedApi) {
|
|
2183
2007
|
// TODO: reintroduce this when we resolve checkout caching issues
|
|
2184
2008
|
// this.open({ transactionData }, preload);
|
|
@@ -2187,15 +2011,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2187
2011
|
language: inlineTransaction.urlParameters.language
|
|
2188
2012
|
}, preload);
|
|
2189
2013
|
}
|
|
2190
|
-
|
|
2191
2014
|
return inlineTransaction;
|
|
2192
2015
|
}
|
|
2193
|
-
|
|
2194
2016
|
var resumableTransaction = findResumableTransaction(this.transactions, inlineTransaction ? inlineTransaction.parameters : options);
|
|
2195
|
-
|
|
2196
2017
|
if (resumableTransaction) {
|
|
2197
2018
|
resumableTransaction.isActive = true;
|
|
2198
|
-
|
|
2199
2019
|
if (!this.isDeprecatedApi) {
|
|
2200
2020
|
// We could potentially optimize this also by checking if there is a `response` property on `resumableTransaction`
|
|
2201
2021
|
this.open({
|
|
@@ -2203,58 +2023,47 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2203
2023
|
language: resumableTransaction.urlParameters.language
|
|
2204
2024
|
}, preload);
|
|
2205
2025
|
}
|
|
2206
|
-
|
|
2207
2026
|
return resumableTransaction;
|
|
2208
2027
|
}
|
|
2209
|
-
|
|
2210
2028
|
var transaction = inlineTransaction || new InlineTransaction(options);
|
|
2211
2029
|
var params = transaction.accessCode ? {
|
|
2212
2030
|
accessCode: transaction.accessCode,
|
|
2213
2031
|
language: transaction.urlParameters.language
|
|
2214
2032
|
} : transaction.urlParameters;
|
|
2215
2033
|
this.transactions.push(transaction);
|
|
2216
|
-
|
|
2217
2034
|
if (!this.isDeprecatedApi) {
|
|
2218
2035
|
this.open(params, preload);
|
|
2219
2036
|
}
|
|
2220
|
-
|
|
2221
2037
|
return transaction;
|
|
2222
2038
|
}
|
|
2223
2039
|
}, {
|
|
2224
2040
|
key: "preloadTransaction",
|
|
2225
2041
|
value: function preloadTransaction(options) {
|
|
2226
2042
|
var _this3 = this;
|
|
2227
|
-
|
|
2228
2043
|
this.newTransaction(_objectSpread2(_objectSpread2({}, options), {}, {
|
|
2229
2044
|
preload: true
|
|
2230
2045
|
}));
|
|
2231
|
-
|
|
2232
2046
|
var loadPopup = function loadPopup() {
|
|
2233
2047
|
return _this3.animateCheckoutIn();
|
|
2234
2048
|
};
|
|
2235
|
-
|
|
2236
2049
|
return loadPopup;
|
|
2237
2050
|
}
|
|
2238
2051
|
}, {
|
|
2239
2052
|
key: "paymentRequest",
|
|
2240
2053
|
value: function paymentRequest(parameters) {
|
|
2241
2054
|
var container = parameters.container,
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2055
|
+
styles = parameters.styles,
|
|
2056
|
+
onElementsMount = parameters.onElementsMount,
|
|
2057
|
+
transactionParams = _objectWithoutProperties(parameters, _excluded2);
|
|
2246
2058
|
inlineInstance = this;
|
|
2247
2059
|
return new Promise(function (resolve, reject) {
|
|
2248
2060
|
var loadPaystackCheckoutButton = document.querySelector("#".concat(parameters.loadPaystackCheckoutButton));
|
|
2249
|
-
|
|
2250
2061
|
if (inlineInstance.activeTransaction()) {
|
|
2251
2062
|
inlineInstance.activeTransaction().cancel();
|
|
2252
2063
|
}
|
|
2253
|
-
|
|
2254
2064
|
if (!(container && getPaymentRequestContainer(container))) {
|
|
2255
2065
|
handleError('A container is required to mount the payment request button');
|
|
2256
2066
|
}
|
|
2257
|
-
|
|
2258
2067
|
inlineInstance.paymentRequestContainer = getPaymentRequestContainer(container);
|
|
2259
2068
|
var resumableTransaction = findResumableTransaction(inlineInstance.transactions, transactionParams);
|
|
2260
2069
|
var transaction = resumableTransaction || new InlineTransaction(transactionParams);
|
|
@@ -2276,9 +2085,7 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2276
2085
|
} else {
|
|
2277
2086
|
inlineInstance.transactions.push(transaction);
|
|
2278
2087
|
}
|
|
2279
|
-
|
|
2280
2088
|
inlineInstance.registerPaymentRequestEventListeners();
|
|
2281
|
-
|
|
2282
2089
|
if (loadPaystackCheckoutButton) {
|
|
2283
2090
|
var loadPopup = inlineInstance.preloadTransaction({
|
|
2284
2091
|
inlineTransaction: transaction,
|
|
@@ -2286,7 +2093,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2286
2093
|
});
|
|
2287
2094
|
loadPaystackCheckoutButton.onclick = loadPopup;
|
|
2288
2095
|
}
|
|
2289
|
-
|
|
2290
2096
|
resolve(transaction);
|
|
2291
2097
|
});
|
|
2292
2098
|
}).catch(function (error) {
|
|
@@ -2302,9 +2108,7 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2302
2108
|
key: "registerApplePayEventListener",
|
|
2303
2109
|
value: function registerApplePayEventListener() {
|
|
2304
2110
|
var _this4 = this;
|
|
2305
|
-
|
|
2306
2111
|
var applePayButton = getApplePayButton(this.paymentRequestContainer);
|
|
2307
|
-
|
|
2308
2112
|
if (applePayButton) {
|
|
2309
2113
|
applePayButton.onclick = function () {
|
|
2310
2114
|
return _this4.startApplePay();
|
|
@@ -2316,7 +2120,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2316
2120
|
value: function registerPaymentRequestEventListeners() {
|
|
2317
2121
|
var transaction = this.activeTransaction();
|
|
2318
2122
|
var applePayButton = this.paymentRequestContainer && getApplePayButton(this.paymentRequestContainer);
|
|
2319
|
-
|
|
2320
2123
|
if (transaction && applePayButton) {
|
|
2321
2124
|
this.registerApplePayEventListener();
|
|
2322
2125
|
} else if (this.paymentRequestContainer) {
|
|
@@ -2327,10 +2130,8 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2327
2130
|
key: "startApplePay",
|
|
2328
2131
|
value: function startApplePay() {
|
|
2329
2132
|
var _this5 = this;
|
|
2330
|
-
|
|
2331
2133
|
var paymentMethod = 'apple pay';
|
|
2332
2134
|
var transaction = this.activeTransaction();
|
|
2333
|
-
|
|
2334
2135
|
if (transaction) {
|
|
2335
2136
|
var paymentAttemptAnalyticsPayload = {
|
|
2336
2137
|
channel: 'apple_pay',
|
|
@@ -2345,7 +2146,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2345
2146
|
timeSpent: transaction.getTimeSpent()
|
|
2346
2147
|
};
|
|
2347
2148
|
var pendingPreCheckoutModalStatus = null;
|
|
2348
|
-
|
|
2349
2149
|
try {
|
|
2350
2150
|
transaction.logAttempt(paymentMethod);
|
|
2351
2151
|
this.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ATTEMPT, paymentAttemptAnalyticsPayload);
|
|
@@ -2356,11 +2156,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2356
2156
|
interval: transaction.response.plan_details && transaction.response.plan_details.interval
|
|
2357
2157
|
});
|
|
2358
2158
|
var applePaySession = new window.ApplePaySession(config.applePayVersion, applePayPaymentRequest);
|
|
2359
|
-
|
|
2360
2159
|
if (inlineInstance.preCheckoutModal) {
|
|
2361
2160
|
hidePreCheckoutModal(inlineInstance.preCheckoutModal);
|
|
2362
2161
|
}
|
|
2363
|
-
|
|
2364
2162
|
applePaySession.onvalidatemerchant = function (_ref3) {
|
|
2365
2163
|
var validationURL = _ref3.validationURL;
|
|
2366
2164
|
var validateSession = validateApplePaySession({
|
|
@@ -2375,14 +2173,12 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2375
2173
|
} else {
|
|
2376
2174
|
applePaySession.completeMerchantValidation(response.data);
|
|
2377
2175
|
}
|
|
2378
|
-
|
|
2379
2176
|
transaction.logValidationResponse(response.message);
|
|
2380
2177
|
}).catch(function (error) {
|
|
2381
2178
|
transaction.onSetupError(error);
|
|
2382
2179
|
pendingPreCheckoutModalStatus = 'failed';
|
|
2383
2180
|
});
|
|
2384
2181
|
};
|
|
2385
|
-
|
|
2386
2182
|
applePaySession.oncancel = function () {
|
|
2387
2183
|
if (inlineInstance.preCheckoutModal) {
|
|
2388
2184
|
if (pendingPreCheckoutModalStatus) {
|
|
@@ -2395,7 +2191,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2395
2191
|
transaction.onCancel();
|
|
2396
2192
|
}
|
|
2397
2193
|
};
|
|
2398
|
-
|
|
2399
2194
|
applePaySession.onpaymentauthorized = function (_ref4) {
|
|
2400
2195
|
var payment = _ref4.payment;
|
|
2401
2196
|
var charge = chargeApplePay({
|
|
@@ -2404,23 +2199,19 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2404
2199
|
});
|
|
2405
2200
|
charge.then(function (response) {
|
|
2406
2201
|
transaction.logAPIResponse(response, paymentMethod);
|
|
2407
|
-
|
|
2408
2202
|
if (response.status === 'success') {
|
|
2409
2203
|
applePaySession.completePayment(applePaySession.STATUS_SUCCESS);
|
|
2410
2204
|
transaction.onSuccess(response);
|
|
2411
|
-
|
|
2412
2205
|
_this5.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_COMPLETION, paymentCompleteAnalyticsPayload);
|
|
2413
2206
|
} else {
|
|
2414
2207
|
applePaySession.completePayment(applePaySession.STATUS_FAILURE);
|
|
2415
2208
|
transaction.onSetupError(response);
|
|
2416
2209
|
pendingPreCheckoutModalStatus = 'failed';
|
|
2417
|
-
|
|
2418
2210
|
_this5.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2419
2211
|
channel: 'apple_pay',
|
|
2420
2212
|
message: response && response.message || 'Transaction attempt failed'
|
|
2421
2213
|
});
|
|
2422
2214
|
}
|
|
2423
|
-
|
|
2424
2215
|
if (response.status === 'success') {
|
|
2425
2216
|
inlineInstance.closePreCheckoutModal(response.status);
|
|
2426
2217
|
}
|
|
@@ -2428,14 +2219,12 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2428
2219
|
applePaySession.completePayment(applePaySession.STATUS_FAILURE);
|
|
2429
2220
|
transaction.onSetupError(error);
|
|
2430
2221
|
pendingPreCheckoutModalStatus = 'failed';
|
|
2431
|
-
|
|
2432
2222
|
_this5.sendAnalyticsEventToCheckout(analyticsActions.TRACK_PAYMENT_ERROR, {
|
|
2433
2223
|
channel: 'apple_pay',
|
|
2434
2224
|
message: error && error.message || 'Error occurred'
|
|
2435
2225
|
});
|
|
2436
2226
|
});
|
|
2437
2227
|
};
|
|
2438
|
-
|
|
2439
2228
|
applePaySession.begin();
|
|
2440
2229
|
} catch (error) {
|
|
2441
2230
|
transaction.onSetupError(error);
|
|
@@ -2450,9 +2239,9 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2450
2239
|
value: function resumeTransaction(accessCode) {
|
|
2451
2240
|
var callbacks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2452
2241
|
var onSuccess = callbacks.onSuccess,
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2242
|
+
onCancel = callbacks.onCancel,
|
|
2243
|
+
onLoad = callbacks.onLoad,
|
|
2244
|
+
onError = callbacks.onError;
|
|
2456
2245
|
return this.newTransaction({
|
|
2457
2246
|
accessCode: accessCode,
|
|
2458
2247
|
onSuccess: onSuccess,
|
|
@@ -2476,7 +2265,6 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2476
2265
|
var transaction = this.transactions.find(function (t) {
|
|
2477
2266
|
return t.id === id;
|
|
2478
2267
|
}) || this.activeTransaction();
|
|
2479
|
-
|
|
2480
2268
|
if (transaction) {
|
|
2481
2269
|
transaction.cancel();
|
|
2482
2270
|
this.close();
|
|
@@ -2488,23 +2276,20 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2488
2276
|
if (!event) {
|
|
2489
2277
|
return;
|
|
2490
2278
|
}
|
|
2491
|
-
|
|
2492
2279
|
var activeTransaction = this.activeTransaction();
|
|
2493
|
-
|
|
2494
2280
|
try {
|
|
2495
2281
|
var actualEvent = event.data || event.message;
|
|
2496
2282
|
var eventType = actualEvent.event,
|
|
2497
|
-
|
|
2498
|
-
|
|
2283
|
+
eventData = actualEvent.data;
|
|
2499
2284
|
if (eventType) {
|
|
2500
2285
|
switch (eventType) {
|
|
2501
2286
|
case 'loaded:checkout':
|
|
2502
2287
|
this.isLoaded = true;
|
|
2503
|
-
|
|
2504
2288
|
if (activeTransaction) {
|
|
2505
2289
|
var checkoutIframe = this.checkoutIframe;
|
|
2506
2290
|
var urlParameters = activeTransaction.urlParameters,
|
|
2507
|
-
|
|
2291
|
+
response = activeTransaction.response;
|
|
2292
|
+
// TODO: reintroduce this when we resolve checkout caching issues
|
|
2508
2293
|
// const params = response
|
|
2509
2294
|
// ? { transactionData: response }
|
|
2510
2295
|
// : urlParameters;
|
|
@@ -2518,77 +2303,60 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2518
2303
|
urlParameters: params
|
|
2519
2304
|
});
|
|
2520
2305
|
}
|
|
2521
|
-
|
|
2522
2306
|
break;
|
|
2523
|
-
|
|
2524
2307
|
case 'loaded:transaction':
|
|
2525
2308
|
hideLoader(this.backgroundIframe);
|
|
2526
|
-
|
|
2527
2309
|
if (this.preCheckoutModal) {
|
|
2528
2310
|
this.openPreCheckoutModal();
|
|
2529
2311
|
}
|
|
2530
|
-
|
|
2531
2312
|
activeTransaction.onLoad(eventData);
|
|
2532
2313
|
break;
|
|
2533
|
-
|
|
2534
2314
|
case 'error':
|
|
2535
2315
|
{
|
|
2536
2316
|
var error = eventData;
|
|
2537
|
-
|
|
2538
2317
|
if (error.type === 'setup') {
|
|
2539
2318
|
activeTransaction.onSetupError(eventData);
|
|
2540
2319
|
} else {
|
|
2541
2320
|
activeTransaction.logError(eventData);
|
|
2542
2321
|
}
|
|
2543
|
-
|
|
2544
2322
|
break;
|
|
2545
2323
|
}
|
|
2546
|
-
|
|
2547
2324
|
case 'cancel':
|
|
2548
2325
|
case 'close':
|
|
2549
2326
|
{
|
|
2550
2327
|
this.close();
|
|
2551
2328
|
var status = eventData && eventData.status;
|
|
2552
|
-
|
|
2553
2329
|
if (status) {
|
|
2554
2330
|
activeTransaction.setStatus(status);
|
|
2555
2331
|
}
|
|
2556
|
-
|
|
2557
2332
|
var hasPaymentRequestButtons = this.paymentRequestContainer && getApplePayButton(this.paymentRequestContainer);
|
|
2558
2333
|
var shouldSetCurrentTransactionAsInactive = !(hasPaymentRequestButtons && !this.preCheckoutModal);
|
|
2559
|
-
|
|
2560
2334
|
if (shouldSetCurrentTransactionAsInactive) {
|
|
2561
2335
|
activeTransaction.isActive = false;
|
|
2562
2336
|
}
|
|
2563
|
-
|
|
2564
2337
|
activeTransaction.onCancel();
|
|
2565
2338
|
break;
|
|
2566
2339
|
}
|
|
2567
|
-
|
|
2568
2340
|
case 'transfer:pending':
|
|
2569
2341
|
{
|
|
2570
2342
|
this.close();
|
|
2571
|
-
|
|
2572
2343
|
var _status = eventData && eventData.status;
|
|
2573
|
-
|
|
2574
2344
|
if (_status) {
|
|
2575
2345
|
activeTransaction.setStatus(_status);
|
|
2576
2346
|
}
|
|
2577
|
-
|
|
2578
2347
|
activeTransaction.onBankTransferConfirmationPending();
|
|
2579
2348
|
break;
|
|
2580
2349
|
}
|
|
2581
|
-
|
|
2582
2350
|
case 'success':
|
|
2583
2351
|
this.close();
|
|
2584
2352
|
activeTransaction.onSuccess(eventData);
|
|
2585
2353
|
break;
|
|
2586
|
-
|
|
2587
2354
|
default:
|
|
2588
2355
|
break;
|
|
2589
2356
|
}
|
|
2590
2357
|
}
|
|
2591
|
-
} catch (error) {
|
|
2358
|
+
} catch (error) {
|
|
2359
|
+
// do nothing
|
|
2592
2360
|
}
|
|
2593
2361
|
}
|
|
2594
2362
|
}, {
|
|
@@ -2596,19 +2364,15 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2596
2364
|
value: function respondToEmbedEvents(event) {
|
|
2597
2365
|
var activeTransaction = this.activeTransaction();
|
|
2598
2366
|
var eventData = event.data || event.message;
|
|
2599
|
-
|
|
2600
2367
|
if (eventData && (typeof eventData === 'string' || eventData instanceof String)) {
|
|
2601
2368
|
var response = parseResponse(eventData);
|
|
2602
2369
|
var oldCheckoutCloseResponse = response && response.action === 'PaystackClose';
|
|
2603
|
-
|
|
2604
2370
|
if (oldCheckoutCloseResponse) {
|
|
2605
2371
|
var chargeResponse = response.data;
|
|
2606
|
-
|
|
2607
2372
|
if (chargeResponse) {
|
|
2608
2373
|
activeTransaction.onSuccess(eventData);
|
|
2609
2374
|
}
|
|
2610
2375
|
}
|
|
2611
|
-
|
|
2612
2376
|
if (response.action === 'PaystackTLSClose') {
|
|
2613
2377
|
activeTransaction.cancel();
|
|
2614
2378
|
}
|
|
@@ -2618,18 +2382,15 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2618
2382
|
key: "animateCheckoutIn",
|
|
2619
2383
|
value: function animateCheckoutIn$1() {
|
|
2620
2384
|
var _this6 = this;
|
|
2621
|
-
|
|
2622
2385
|
if (!this.isOpen) {
|
|
2623
2386
|
var checkoutIframe = this.checkoutIframe,
|
|
2624
|
-
|
|
2625
|
-
|
|
2387
|
+
backgroundIframe = this.backgroundIframe;
|
|
2626
2388
|
animateCheckoutIn({
|
|
2627
2389
|
checkoutIframe: checkoutIframe,
|
|
2628
2390
|
backgroundIframe: backgroundIframe
|
|
2629
2391
|
}).then(function () {
|
|
2630
2392
|
_this6.checkoutIframe.contentWindow.postMessage('render', '*');
|
|
2631
2393
|
});
|
|
2632
|
-
|
|
2633
2394
|
this.isOpen = true;
|
|
2634
2395
|
}
|
|
2635
2396
|
}
|
|
@@ -2639,13 +2400,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2639
2400
|
if (!urlParameters) {
|
|
2640
2401
|
return;
|
|
2641
2402
|
}
|
|
2642
|
-
|
|
2643
2403
|
var checkoutIframe = this.checkoutIframe;
|
|
2644
2404
|
notifyIframeToUpdateURL({
|
|
2645
2405
|
checkoutIframe: checkoutIframe,
|
|
2646
2406
|
urlParameters: urlParameters
|
|
2647
2407
|
});
|
|
2648
|
-
|
|
2649
2408
|
if (!preload) {
|
|
2650
2409
|
this.animateCheckoutIn();
|
|
2651
2410
|
}
|
|
@@ -2654,13 +2413,11 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2654
2413
|
key: "close",
|
|
2655
2414
|
value: function close() {
|
|
2656
2415
|
var _this7 = this;
|
|
2657
|
-
|
|
2658
2416
|
if (!this.isOpen) {
|
|
2659
2417
|
return;
|
|
2660
2418
|
}
|
|
2661
|
-
|
|
2662
2419
|
var checkoutIframe = this.checkoutIframe,
|
|
2663
|
-
|
|
2420
|
+
backgroundIframe = this.backgroundIframe;
|
|
2664
2421
|
animateCheckoutOut({
|
|
2665
2422
|
checkoutIframe: checkoutIframe,
|
|
2666
2423
|
backgroundIframe: backgroundIframe
|
|
@@ -2679,23 +2436,19 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2679
2436
|
value: function setup(parameters) {
|
|
2680
2437
|
var isDeprecatedApi = true;
|
|
2681
2438
|
var isEmbed = parameters && parameters.container;
|
|
2682
|
-
|
|
2683
2439
|
if (!inlineInstance) {
|
|
2684
2440
|
inlineInstance = new Inline({
|
|
2685
2441
|
isDeprecatedApi: isDeprecatedApi,
|
|
2686
2442
|
isEmbed: isEmbed
|
|
2687
2443
|
});
|
|
2688
2444
|
}
|
|
2689
|
-
|
|
2690
2445
|
printDeprecationNotice('PaystackPop.setup()', 'new PaystackPop()', 'Please consult our documentation at https://developers.paystack.co/docs/paystack-inline');
|
|
2691
2446
|
var transaction = inlineInstance.newTransaction(parameters, 'deprecated');
|
|
2692
2447
|
var urlParameters = transaction.urlParameters;
|
|
2693
|
-
|
|
2694
2448
|
if (isEmbed) {
|
|
2695
2449
|
var inlineUrl = "".concat(config.siteUrl, "/assets/payment/production/inline.html?").concat(serialize(urlParameters));
|
|
2696
2450
|
var iframe = mountEmbedCheckoutIframe(inlineInstance.id, inlineUrl);
|
|
2697
2451
|
appendIframeToContainer(parameters.container, iframe);
|
|
2698
|
-
|
|
2699
2452
|
iframe.onload = function onLoad() {
|
|
2700
2453
|
iframe.contentWindow.postMessage("PaystackOpen ".concat(inlineInstance.id), '*');
|
|
2701
2454
|
animateEmbedCheckoutIn(iframe);
|
|
@@ -2707,22 +2460,16 @@ var Inline = /*#__PURE__*/function () {
|
|
|
2707
2460
|
inlineInstance.open(urlParameters);
|
|
2708
2461
|
};
|
|
2709
2462
|
}
|
|
2710
|
-
|
|
2711
2463
|
return transaction;
|
|
2712
2464
|
}
|
|
2713
2465
|
}]);
|
|
2714
|
-
|
|
2715
|
-
return Inline;
|
|
2716
2466
|
}();
|
|
2717
|
-
|
|
2718
2467
|
if (scriptCanUseDataAttributes()) {
|
|
2719
2468
|
var parameters = getDataAttributesAsParameters();
|
|
2720
2469
|
var parentForm = getSourceScript().parentElement;
|
|
2721
|
-
|
|
2722
2470
|
if (!inlineInstance) {
|
|
2723
2471
|
inlineInstance = new Inline();
|
|
2724
2472
|
}
|
|
2725
|
-
|
|
2726
2473
|
var transaction;
|
|
2727
2474
|
var inlineButton = mountLazyInlineButton({
|
|
2728
2475
|
inlineId: inlineInstance.id,
|
|
@@ -2736,7 +2483,6 @@ if (scriptCanUseDataAttributes()) {
|
|
|
2736
2483
|
});
|
|
2737
2484
|
inlineButton.addEventListener('click', function (e) {
|
|
2738
2485
|
e.preventDefault();
|
|
2739
|
-
|
|
2740
2486
|
if (!transaction) {
|
|
2741
2487
|
transaction = inlineInstance.newTransaction(_objectSpread2(_objectSpread2({}, parameters), {}, {
|
|
2742
2488
|
onSuccess: function onSuccess(response) {
|