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