@paystack/inline-js 2.23.0-dev.1 → 2.23.0-dev.3

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