@paystack/checkout-js 1.19.0 → 1.20.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/checkout.js CHANGED
@@ -6407,14 +6407,16 @@ var devConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6407
6407
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6408
6408
  paystackApiUrl: 'https://studio-api.paystack.co/',
6409
6409
  pusherKey: '1c7b262ee18455815893',
6410
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6410
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6411
+ savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6411
6412
  });
6412
6413
  var stagingConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6413
6414
  checkoutUrl: 'https://checkout-studio.paystack.com/',
6414
6415
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6415
6416
  paystackApiUrl: 'https://studio-api.paystack.co/',
6416
6417
  pusherKey: '1c7b262ee18455815893',
6417
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6418
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6419
+ savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6418
6420
  });
6419
6421
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6420
6422
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -11645,7 +11647,7 @@ var PayattitudeAPI = {
11645
11647
  }
11646
11648
  };
11647
11649
 
11648
- var paymentMethod$6 = 'payattitude';
11650
+ var paymentMethod$7 = 'payattitude';
11649
11651
  var PayattitudeCharge = {
11650
11652
  chargePayattitude: function chargePayattitude(_ref) {
11651
11653
  var _this = this;
@@ -11656,7 +11658,7 @@ var PayattitudeCharge = {
11656
11658
  phoneNumber: phoneNumber
11657
11659
  };
11658
11660
  return PayattitudeAPI.charge(params).then(function (response) {
11659
- _this.logAPIResponse(response, paymentMethod$6);
11661
+ _this.logAPIResponse(response, paymentMethod$7);
11660
11662
 
11661
11663
  return response;
11662
11664
  });
@@ -11664,7 +11666,7 @@ var PayattitudeCharge = {
11664
11666
  listenForPayattitudeCharge: function listenForPayattitudeCharge(callback) {
11665
11667
  var pusherChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
11666
11668
  var listenerOptions = {
11667
- paymentMethod: paymentMethod$6,
11669
+ paymentMethod: paymentMethod$7,
11668
11670
  channel: pusherChannel
11669
11671
  };
11670
11672
  return this.listenForCharge(listenerOptions, callback);
@@ -11747,7 +11749,7 @@ var ApplePayAPI = {
11747
11749
  }
11748
11750
  };
11749
11751
 
11750
- var paymentMethod$5 = 'apple pay';
11752
+ var paymentMethod$6 = 'apple pay';
11751
11753
  var ApplePayCharge = {
11752
11754
  validateApplePaySession: function validateApplePaySession(_ref) {
11753
11755
  var _this = this;
@@ -11755,7 +11757,7 @@ var ApplePayCharge = {
11755
11757
  var sessionUrl = _ref.sessionUrl,
11756
11758
  displayName = _ref.displayName,
11757
11759
  domainName = _ref.domainName;
11758
- this.logAttempt(paymentMethod$5);
11760
+ this.logAttempt(paymentMethod$6);
11759
11761
  return ApplePayAPI.validateApplePaySession({
11760
11762
  sessionUrl: sessionUrl,
11761
11763
  displayName: displayName,
@@ -11776,7 +11778,7 @@ var ApplePayCharge = {
11776
11778
  device: this.deviceFingerprint,
11777
11779
  paymentObject: paymentObject
11778
11780
  }).then(function (response) {
11779
- _this2.logAPIResponse(response, paymentMethod$5);
11781
+ _this2.logAPIResponse(response, paymentMethod$6);
11780
11782
 
11781
11783
  return response;
11782
11784
  });
@@ -11832,12 +11834,12 @@ var PayPalAPI = {
11832
11834
  }
11833
11835
  };
11834
11836
 
11835
- var paymentMethod$4 = 'paypal';
11837
+ var paymentMethod$5 = 'paypal';
11836
11838
  var PayPalCharge = {
11837
11839
  createPayPalOrder: function createPayPalOrder() {
11838
11840
  var _this = this;
11839
11841
 
11840
- this.logAttempt(paymentMethod$4);
11842
+ this.logAttempt(paymentMethod$5);
11841
11843
  return PayPalAPI.createOrder(this.id).then(function (response) {
11842
11844
  _this.logAPIResponseMessage(response.message);
11843
11845
 
@@ -11848,7 +11850,7 @@ var PayPalCharge = {
11848
11850
  var _this2 = this;
11849
11851
 
11850
11852
  return PayPalAPI.captureOrder(this.id).then(function (response) {
11851
- _this2.logAPIResponse(response, paymentMethod$4);
11853
+ _this2.logAPIResponse(response, paymentMethod$5);
11852
11854
 
11853
11855
  return response;
11854
11856
  });
@@ -17236,55 +17238,7 @@ function encrypt(toEncrypt) {
17236
17238
  return jsEncrypt.encrypt(toEncrypt);
17237
17239
  }
17238
17240
 
17239
- var DESCRIPTORS = descriptors;
17240
- var uncurryThis$1 = functionUncurryThis;
17241
- var objectKeys = objectKeys$3;
17242
- var toIndexedObject = toIndexedObject$8;
17243
- var $propertyIsEnumerable = objectPropertyIsEnumerable.f;
17244
-
17245
- var propertyIsEnumerable = uncurryThis$1($propertyIsEnumerable);
17246
- var push = uncurryThis$1([].push);
17247
-
17248
- // `Object.{ entries, values }` methods implementation
17249
- var createMethod = function (TO_ENTRIES) {
17250
- return function (it) {
17251
- var O = toIndexedObject(it);
17252
- var keys = objectKeys(O);
17253
- var length = keys.length;
17254
- var i = 0;
17255
- var result = [];
17256
- var key;
17257
- while (length > i) {
17258
- key = keys[i++];
17259
- if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
17260
- push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
17261
- }
17262
- }
17263
- return result;
17264
- };
17265
- };
17266
-
17267
- var objectToArray = {
17268
- // `Object.entries` method
17269
- // https://tc39.es/ecma262/#sec-object.entries
17270
- entries: createMethod(true),
17271
- // `Object.values` method
17272
- // https://tc39.es/ecma262/#sec-object.values
17273
- values: createMethod(false)
17274
- };
17275
-
17276
17241
  var $$2 = _export;
17277
- var $values = objectToArray.values;
17278
-
17279
- // `Object.values` method
17280
- // https://tc39.es/ecma262/#sec-object.values
17281
- $$2({ target: 'Object', stat: true }, {
17282
- values: function values(O) {
17283
- return $values(O);
17284
- }
17285
- });
17286
-
17287
- var $$1 = _export;
17288
17242
  var $find = arrayIteration.find;
17289
17243
  var addToUnscopables = addToUnscopables$3;
17290
17244
 
@@ -17296,7 +17250,7 @@ if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
17296
17250
 
17297
17251
  // `Array.prototype.find` method
17298
17252
  // https://tc39.es/ecma262/#sec-array.prototype.find
17299
- $$1({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
17253
+ $$2({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
17300
17254
  find: function find(callbackfn /* , that = undefined */) {
17301
17255
  return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
17302
17256
  }
@@ -18244,56 +18198,136 @@ var cardValidator = {
18244
18198
  creditCardType: creditCardType_1
18245
18199
  };
18246
18200
 
18247
- var testCards = [{
18248
- type: 'bank_auth',
18249
- name: 'Bank authorization',
18250
- number: '4084080000000409',
18251
- cvv: '000',
18252
- month: '01',
18253
- year: '30'
18254
- }, {
18255
- type: 'success',
18256
- name: 'Success',
18257
- number: '4084084084084081',
18258
- cvv: '408',
18259
- month: '12',
18260
- year: '30'
18261
- }, {
18262
- type: 'declined',
18263
- name: 'Declined',
18264
- number: '4084080000005408',
18265
- cvv: '001',
18266
- month: '12',
18267
- year: '30'
18268
- }, {
18269
- type: 'pin',
18270
- name: 'Pin only validation',
18271
- number: '507850785078507812',
18272
- cvv: '884',
18273
- month: '01',
18274
- year: '30'
18275
- }, {
18276
- type: 'pin+otp',
18277
- name: 'Pin and OTP validation',
18278
- number: '5060666666666666666',
18279
- cvv: '123',
18280
- month: '01',
18281
- year: '30'
18282
- }, {
18283
- type: 'pin+phone+otp',
18284
- name: 'Pin, phone and OTP validation',
18285
- number: '507850785078507812',
18286
- cvv: '884',
18287
- month: '01',
18288
- year: '30'
18289
- }, {
18290
- type: 'default',
18291
- name: 'No validation',
18292
- number: '4084084084084081',
18293
- cvv: '408',
18294
- month: '01',
18295
- year: '30'
18296
- }];
18201
+ var DESCRIPTORS = descriptors;
18202
+ var uncurryThis$1 = functionUncurryThis;
18203
+ var objectKeys = objectKeys$3;
18204
+ var toIndexedObject = toIndexedObject$8;
18205
+ var $propertyIsEnumerable = objectPropertyIsEnumerable.f;
18206
+
18207
+ var propertyIsEnumerable = uncurryThis$1($propertyIsEnumerable);
18208
+ var push = uncurryThis$1([].push);
18209
+
18210
+ // `Object.{ entries, values }` methods implementation
18211
+ var createMethod = function (TO_ENTRIES) {
18212
+ return function (it) {
18213
+ var O = toIndexedObject(it);
18214
+ var keys = objectKeys(O);
18215
+ var length = keys.length;
18216
+ var i = 0;
18217
+ var result = [];
18218
+ var key;
18219
+ while (length > i) {
18220
+ key = keys[i++];
18221
+ if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
18222
+ push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
18223
+ }
18224
+ }
18225
+ return result;
18226
+ };
18227
+ };
18228
+
18229
+ var objectToArray = {
18230
+ // `Object.entries` method
18231
+ // https://tc39.es/ecma262/#sec-object.entries
18232
+ entries: createMethod(true),
18233
+ // `Object.values` method
18234
+ // https://tc39.es/ecma262/#sec-object.values
18235
+ values: createMethod(false)
18236
+ };
18237
+
18238
+ var $$1 = _export;
18239
+ var $values = objectToArray.values;
18240
+
18241
+ // `Object.values` method
18242
+ // https://tc39.es/ecma262/#sec-object.values
18243
+ $$1({ target: 'Object', stat: true }, {
18244
+ values: function values(O) {
18245
+ return $values(O);
18246
+ }
18247
+ });
18248
+
18249
+ var Card$2 = {
18250
+ getEncryptedPin: function getEncryptedPin(pin) {
18251
+ return pin ? encrypt(pin) : undefined;
18252
+ },
18253
+ getLast4: function getLast4(number) {
18254
+ return number.substring(number.length - 4);
18255
+ },
18256
+ tokenize: function tokenize(_ref) {
18257
+ var number = _ref.number,
18258
+ cvv = _ref.cvv,
18259
+ month = _ref.month,
18260
+ year = _ref.year;
18261
+ return encrypt("".concat(number, "*").concat(cvv, "*").concat(month, "*").concat(year));
18262
+ },
18263
+ getType: function getType(value) {
18264
+ var response = cardValidator.number(value);
18265
+
18266
+ if (response && response.card) {
18267
+ return {
18268
+ type: response.card.type,
18269
+ maxLength: Math.max.apply(Math, _toConsumableArray(response.card.lengths)),
18270
+ minLength: Math.min.apply(Math, _toConsumableArray(response.card.lengths))
18271
+ };
18272
+ }
18273
+
18274
+ return {
18275
+ type: null,
18276
+ maxLength: 0
18277
+ };
18278
+ },
18279
+ validate: function validate(_ref2) {
18280
+ var number = _ref2.number,
18281
+ cvv = _ref2.cvv,
18282
+ month = _ref2.month,
18283
+ year = _ref2.year;
18284
+
18285
+ var _this$getType = this.getType(number),
18286
+ cardType = _this$getType.type;
18287
+
18288
+ var result = {
18289
+ number: this.isNumberValid(number),
18290
+ expiry: this.isExpiryValid({
18291
+ month: month,
18292
+ year: year
18293
+ }),
18294
+ cvv: this.isCvvValid(cvv, cardType)
18295
+ };
18296
+ var isValid = Object.values(result).every(function (value) {
18297
+ return value === true;
18298
+ });
18299
+ return {
18300
+ isValid: isValid,
18301
+ result: result
18302
+ };
18303
+ },
18304
+ validateNumber: function validateNumber(value) {
18305
+ return cardValidator.number(value);
18306
+ },
18307
+ isNumberValid: function isNumberValid(value) {
18308
+ return Card$2.validateNumber(value).isValid;
18309
+ },
18310
+ validateCVV: function validateCVV(cvv, cardType) {
18311
+ var isAmexCard = cardType === 'american-express';
18312
+ var cvvLength = isAmexCard ? 4 : 3;
18313
+ return cardValidator.cvv(cvv, cvvLength);
18314
+ },
18315
+ isCvvValid: function isCvvValid(cvv, cardType) {
18316
+ return Card$2.validateCVV(cvv, cardType).isValid;
18317
+ },
18318
+ validateExpiry: function validateExpiry(value) {
18319
+ if (_typeof$1(value) === 'object') {
18320
+ var month = value.month,
18321
+ year = value.year;
18322
+ return cardValidator.expirationMonth(month) && cardValidator.expirationYear(year);
18323
+ }
18324
+
18325
+ return cardValidator.expirationDate(value);
18326
+ },
18327
+ isExpiryValid: function isExpiryValid(value) {
18328
+ return Card$2.validateExpiry(value).isValid;
18329
+ }
18330
+ };
18297
18331
 
18298
18332
  cardValidator.creditCardType.addCard({
18299
18333
  niceType: 'Verve',
@@ -18308,7 +18342,7 @@ cardValidator.creditCardType.addCard({
18308
18342
  });
18309
18343
  cardValidator.creditCardType.changeOrder('verve', 0);
18310
18344
 
18311
- var Card = /*#__PURE__*/function () {
18345
+ var Card$1 = /*#__PURE__*/function () {
18312
18346
  function Card(_ref) {
18313
18347
  var number = _ref.number,
18314
18348
  cvv = _ref.cvv,
@@ -18328,35 +18362,27 @@ var Card = /*#__PURE__*/function () {
18328
18362
  _createClass(Card, [{
18329
18363
  key: "getEncryptedPin",
18330
18364
  value: function getEncryptedPin() {
18331
- return this.pin ? encrypt(this.pin) : undefined;
18365
+ return Card$2.getEncryptedPin(this.pin);
18332
18366
  }
18333
18367
  }, {
18334
18368
  key: "getLast4",
18335
18369
  value: function getLast4() {
18336
- return this.number.substring(this.number.length - 4);
18370
+ return Card$2.getLast4(this.number);
18337
18371
  }
18338
18372
  }, {
18339
18373
  key: "tokenize",
18340
18374
  value: function tokenize() {
18341
- return encrypt("".concat(this.number, "*").concat(this.cvv, "*").concat(this.month, "*").concat(this.year));
18375
+ return Card$2.tokenize({
18376
+ number: this.number,
18377
+ cvv: this.cvv,
18378
+ month: this.month,
18379
+ year: this.year
18380
+ });
18342
18381
  }
18343
18382
  }], [{
18344
18383
  key: "getType",
18345
18384
  value: function getType(value) {
18346
- var response = cardValidator.number(value);
18347
-
18348
- if (response && response.card) {
18349
- return {
18350
- type: response.card.type,
18351
- maxLength: Math.max.apply(Math, _toConsumableArray(response.card.lengths)),
18352
- minLength: Math.min.apply(Math, _toConsumableArray(response.card.lengths))
18353
- };
18354
- }
18355
-
18356
- return {
18357
- type: null,
18358
- maxLength: 0
18359
- };
18385
+ return Card$2.getType(value);
18360
18386
  }
18361
18387
  }, {
18362
18388
  key: "validate",
@@ -18365,63 +18391,42 @@ var Card = /*#__PURE__*/function () {
18365
18391
  cvv = _ref2.cvv,
18366
18392
  month = _ref2.month,
18367
18393
  year = _ref2.year;
18368
-
18369
- var _Card$getType = Card.getType(number),
18370
- cardType = _Card$getType.type;
18371
-
18372
- var result = {
18373
- number: Card.isNumberValid(number),
18374
- expiry: Card.isExpiryValid({
18375
- month: month,
18376
- year: year
18377
- }),
18378
- cvv: Card.isCvvValid(cvv, cardType)
18379
- };
18380
- var isValid = Object.values(result).every(function (value) {
18381
- return value === true;
18394
+ return Card$2.validate({
18395
+ number: number,
18396
+ cvv: cvv,
18397
+ month: month,
18398
+ year: year
18382
18399
  });
18383
- return {
18384
- isValid: isValid,
18385
- result: result
18386
- };
18387
18400
  }
18388
18401
  }, {
18389
18402
  key: "validateNumber",
18390
18403
  value: function validateNumber(value) {
18391
- return cardValidator.number(value);
18404
+ return Card$2.validateNumber(value);
18392
18405
  }
18393
18406
  }, {
18394
18407
  key: "isNumberValid",
18395
18408
  value: function isNumberValid(value) {
18396
- return Card.validateNumber(value).isValid;
18409
+ return Card$2.isNumberValid(value);
18397
18410
  }
18398
18411
  }, {
18399
18412
  key: "validateCVV",
18400
18413
  value: function validateCVV(cvv, cardType) {
18401
- var isAmexCard = cardType === 'american-express';
18402
- var cvvLength = isAmexCard ? 4 : 3;
18403
- return cardValidator.cvv(cvv, cvvLength);
18414
+ return Card$2.validateCVV(cvv, cardType);
18404
18415
  }
18405
18416
  }, {
18406
18417
  key: "isCvvValid",
18407
18418
  value: function isCvvValid(cvv, cardType) {
18408
- return Card.validateCVV(cvv, cardType).isValid;
18419
+ return Card$2.isCvvValid(cvv, cardType);
18409
18420
  }
18410
18421
  }, {
18411
18422
  key: "validateExpiry",
18412
18423
  value: function validateExpiry(value) {
18413
- if (_typeof$1(value) === 'object') {
18414
- var month = value.month,
18415
- year = value.year;
18416
- return cardValidator.expirationMonth(month) && cardValidator.expirationYear(year);
18417
- }
18418
-
18419
- return cardValidator.expirationDate(value);
18424
+ return Card$2.validateExpiry(value);
18420
18425
  }
18421
18426
  }, {
18422
18427
  key: "isExpiryValid",
18423
18428
  value: function isExpiryValid(value) {
18424
- return Card.validateExpiry(value).isValid;
18429
+ return Card$2.isExpiryValid(value);
18425
18430
  }
18426
18431
  }, {
18427
18432
  key: "generateTestCard",
@@ -18437,7 +18442,7 @@ var Card = /*#__PURE__*/function () {
18437
18442
  return Card;
18438
18443
  }();
18439
18444
 
18440
- var CardAPI = {
18445
+ var CardAPI$1 = {
18441
18446
  charge: function charge(_ref) {
18442
18447
  var clientdata = _ref.clientdata,
18443
18448
  last4 = _ref.last4,
@@ -18613,14 +18618,215 @@ var CardAPI = {
18613
18618
  }).then(function (response) {
18614
18619
  return ChargeResponses.parse(response.data);
18615
18620
  });
18621
+ },
18622
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
18623
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18624
+ var url, language, headers, _yield$axiosInstance$, data;
18625
+
18626
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18627
+ while (1) {
18628
+ switch (_context.prev = _context.next) {
18629
+ case 0:
18630
+ url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18631
+ language = getLanguage();
18632
+ headers = _objectSpread2({}, language && {
18633
+ 'Accept-Language': language
18634
+ });
18635
+ _context.next = 5;
18636
+ return axiosInstance.post(url, {
18637
+ headers: headers
18638
+ });
18639
+
18640
+ case 5:
18641
+ _yield$axiosInstance$ = _context.sent;
18642
+ data = _yield$axiosInstance$.data;
18643
+ return _context.abrupt("return", data);
18644
+
18645
+ case 8:
18646
+ case "end":
18647
+ return _context.stop();
18648
+ }
18649
+ }
18650
+ }, _callee);
18651
+ }))();
18652
+ },
18653
+ addUserToSavedCards: function addUserToSavedCards(_ref6) {
18654
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18655
+ var phone, email, url, language, headers, data, response;
18656
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18657
+ while (1) {
18658
+ switch (_context2.prev = _context2.next) {
18659
+ case 0:
18660
+ phone = _ref6.phone, email = _ref6.email;
18661
+ url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18662
+ language = getLanguage();
18663
+ headers = _objectSpread2({}, language && {
18664
+ 'Accept-Language': language
18665
+ });
18666
+ data = {
18667
+ phone: phone,
18668
+ email: email
18669
+ };
18670
+ _context2.next = 7;
18671
+ return axiosInstance.post(url, data, {
18672
+ headers: headers
18673
+ });
18674
+
18675
+ case 7:
18676
+ response = _context2.sent;
18677
+ return _context2.abrupt("return", response.data);
18678
+
18679
+ case 9:
18680
+ case "end":
18681
+ return _context2.stop();
18682
+ }
18683
+ }
18684
+ }, _callee2);
18685
+ }))();
18686
+ },
18687
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18688
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18689
+ var code, phone, transaction, url, language, headers, data, response;
18690
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18691
+ while (1) {
18692
+ switch (_context3.prev = _context3.next) {
18693
+ case 0:
18694
+ code = _ref7.code, phone = _ref7.phone, transaction = _ref7.transaction;
18695
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18696
+ language = getLanguage();
18697
+ headers = _objectSpread2({}, language && {
18698
+ 'Accept-Language': language
18699
+ });
18700
+ data = {
18701
+ code: code,
18702
+ phone: phone,
18703
+ transaction: transaction
18704
+ };
18705
+ _context3.next = 7;
18706
+ return axiosInstance.post(url, data, {
18707
+ headers: headers
18708
+ });
18709
+
18710
+ case 7:
18711
+ response = _context3.sent;
18712
+ return _context3.abrupt("return", response.data);
18713
+
18714
+ case 9:
18715
+ case "end":
18716
+ return _context3.stop();
18717
+ }
18718
+ }
18719
+ }, _callee3);
18720
+ }))();
18721
+ },
18722
+ getSavedCards: function getSavedCards(_ref8) {
18723
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18724
+ var token, url, language, headers, response;
18725
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18726
+ while (1) {
18727
+ switch (_context4.prev = _context4.next) {
18728
+ case 0:
18729
+ token = _ref8.token;
18730
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18731
+ language = getLanguage();
18732
+ headers = _objectSpread2({
18733
+ Authorization: "Bearer ".concat(token),
18734
+ 'jwt-auth': true
18735
+ }, language && {
18736
+ 'Accept-Language': language
18737
+ });
18738
+ _context4.next = 6;
18739
+ return axiosInstance.get(url, {
18740
+ headers: headers
18741
+ });
18742
+
18743
+ case 6:
18744
+ response = _context4.sent;
18745
+ return _context4.abrupt("return", response.data);
18746
+
18747
+ case 8:
18748
+ case "end":
18749
+ return _context4.stop();
18750
+ }
18751
+ }
18752
+ }, _callee4);
18753
+ }))();
18754
+ },
18755
+ deleteSavedCard: function deleteSavedCard(_ref9) {
18756
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18757
+ var cardCode, token, url, language, headers, response;
18758
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18759
+ while (1) {
18760
+ switch (_context5.prev = _context5.next) {
18761
+ case 0:
18762
+ cardCode = _ref9.cardCode, token = _ref9.token;
18763
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18764
+ language = getLanguage();
18765
+ headers = _objectSpread2({
18766
+ Authorization: "Bearer ".concat(token),
18767
+ 'jwt-auth': true
18768
+ }, language && {
18769
+ 'Accept-Language': language
18770
+ });
18771
+ _context5.next = 6;
18772
+ return axiosInstance.delete(url, {
18773
+ headers: headers
18774
+ });
18775
+
18776
+ case 6:
18777
+ response = _context5.sent;
18778
+ return _context5.abrupt("return", response.data);
18779
+
18780
+ case 8:
18781
+ case "end":
18782
+ return _context5.stop();
18783
+ }
18784
+ }
18785
+ }, _callee5);
18786
+ }))();
18787
+ },
18788
+ chargeSavedCard: function chargeSavedCard(_ref10) {
18789
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18790
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18791
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
18792
+ while (1) {
18793
+ switch (_context6.prev = _context6.next) {
18794
+ case 0:
18795
+ token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18796
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18797
+ language = getLanguage();
18798
+ headers = _objectSpread2({
18799
+ Authorization: "Bearer ".concat(token),
18800
+ 'jwt-auth': true
18801
+ }, language && {
18802
+ 'Accept-Language': language
18803
+ });
18804
+ data = {
18805
+ device: device,
18806
+ transaction: transaction,
18807
+ selectedCurrency: selectedCurrency
18808
+ };
18809
+ return _context6.abrupt("return", axiosInstance.post(url, data, {
18810
+ headers: headers
18811
+ }).then(function (response) {
18812
+ return ChargeResponses.parse(response.data);
18813
+ }));
18814
+
18815
+ case 6:
18816
+ case "end":
18817
+ return _context6.stop();
18818
+ }
18819
+ }
18820
+ }, _callee6);
18821
+ }))();
18616
18822
  }
18617
18823
  };
18618
18824
 
18619
- var paymentMethod$3 = 'card';
18825
+ var paymentMethod$4 = 'card';
18620
18826
 
18621
- function validate$3(card, isSetter) {
18827
+ function validate$4(card, isSetter) {
18622
18828
  return new Promise(function (resolve, reject) {
18623
- var validation = Card.validate(card);
18829
+ var validation = Card$1.validate(card);
18624
18830
 
18625
18831
  if (!validation.isValid) {
18626
18832
  var throwValidation = isSetter || card.number;
@@ -18639,8 +18845,8 @@ var CardCharge = {
18639
18845
  setCard: function setCard(params) {
18640
18846
  var _this = this;
18641
18847
 
18642
- return validate$3(params, true).then(function () {
18643
- _this.card = new Card(params);
18848
+ return validate$4(params, true).then(function () {
18849
+ _this.card = new Card$1(params);
18644
18850
  });
18645
18851
  },
18646
18852
  rememberCard: function rememberCard() {
@@ -18655,8 +18861,8 @@ var CardCharge = {
18655
18861
  return this.chargeCardWithPin(customFields);
18656
18862
  }
18657
18863
 
18658
- return validate$3(this.card).then(function () {
18659
- _this2.logAttempt(paymentMethod$3);
18864
+ return validate$4(this.card).then(function () {
18865
+ _this2.logAttempt(paymentMethod$4);
18660
18866
 
18661
18867
  var chargeParams = {
18662
18868
  clientdata: _this2.card.tokenize(),
@@ -18669,8 +18875,8 @@ var CardCharge = {
18669
18875
  subscription: _this2.subscription,
18670
18876
  customFields: customFields
18671
18877
  };
18672
- return CardAPI.charge(chargeParams).then(function (response) {
18673
- _this2.logAPIResponse(response, paymentMethod$3);
18878
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18879
+ _this2.logAPIResponse(response, paymentMethod$4);
18674
18880
 
18675
18881
  return response;
18676
18882
  });
@@ -18685,7 +18891,7 @@ var CardCharge = {
18685
18891
  var _this3 = this;
18686
18892
 
18687
18893
  var customFields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18688
- this.logAttempt(paymentMethod$3);
18894
+ this.logAttempt(paymentMethod$4);
18689
18895
  var chargeParams = {
18690
18896
  pin: encrypt(this.card.pin),
18691
18897
  trans: this.id,
@@ -18695,8 +18901,8 @@ var CardCharge = {
18695
18901
  subscription: this.subscription,
18696
18902
  customFields: customFields
18697
18903
  };
18698
- return CardAPI.charge(chargeParams).then(function (response) {
18699
- _this3.logAPIResponse(response, paymentMethod$3);
18904
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18905
+ _this3.logAPIResponse(response, paymentMethod$4);
18700
18906
 
18701
18907
  return response;
18702
18908
  });
@@ -18708,7 +18914,7 @@ var CardCharge = {
18708
18914
  authorizationCode = _ref.authorizationCode,
18709
18915
  cardLast4 = _ref.cardLast4,
18710
18916
  pin = _ref.pin;
18711
- this.logAttempt(paymentMethod$3);
18917
+ this.logAttempt(paymentMethod$4);
18712
18918
  var encryptedPin = encrypt(pin);
18713
18919
  var chargeParams = {
18714
18920
  authorizationCode: authorizationCode,
@@ -18720,8 +18926,8 @@ var CardCharge = {
18720
18926
  transactionType: this.transactionType,
18721
18927
  subscription: this.subscription
18722
18928
  };
18723
- return CardAPI.chargeRememberedCard(chargeParams).then(function (response) {
18724
- _this4.logAPIResponse(response, paymentMethod$3);
18929
+ return CardAPI$1.chargeRememberedCard(chargeParams).then(function (response) {
18930
+ _this4.logAPIResponse(response, paymentMethod$4);
18725
18931
 
18726
18932
  return response;
18727
18933
  });
@@ -18739,8 +18945,8 @@ var CardCharge = {
18739
18945
  device: this.deviceFingerprint
18740
18946
  });
18741
18947
 
18742
- return CardAPI.resumeCardCharge(params).then(function (response) {
18743
- _this5.logAPIResponse(response, paymentMethod$3);
18948
+ return CardAPI$1.resumeCardCharge(params).then(function (response) {
18949
+ _this5.logAPIResponse(response, paymentMethod$4);
18744
18950
 
18745
18951
  return response;
18746
18952
  });
@@ -18752,8 +18958,8 @@ var CardCharge = {
18752
18958
  authorizationId: authorizationId,
18753
18959
  publicKey: this.merchant.key
18754
18960
  };
18755
- return CardAPI.forgetRememberedCard(params).then(function (response) {
18756
- _this6.logAPIResponse(response, paymentMethod$3);
18961
+ return CardAPI$1.forgetRememberedCard(params).then(function (response) {
18962
+ _this6.logAPIResponse(response, paymentMethod$4);
18757
18963
 
18758
18964
  return response;
18759
18965
  });
@@ -18761,8 +18967,8 @@ var CardCharge = {
18761
18967
  authenticateCard: function authenticateCard(token) {
18762
18968
  var _this7 = this;
18763
18969
 
18764
- return CardAPI.authenticate(this.id, token).then(function (response) {
18765
- _this7.logAPIResponse(response, paymentMethod$3);
18970
+ return CardAPI$1.authenticate(this.id, token).then(function (response) {
18971
+ _this7.logAPIResponse(response, paymentMethod$4);
18766
18972
 
18767
18973
  return response;
18768
18974
  });
@@ -18781,8 +18987,8 @@ var CardCharge = {
18781
18987
  zipCode: zipCode,
18782
18988
  transactionId: this.id
18783
18989
  };
18784
- return CardAPI.verifyAddress(payload).then(function (response) {
18785
- _this8.logAPIResponse(response, paymentMethod$3);
18990
+ return CardAPI$1.verifyAddress(payload).then(function (response) {
18991
+ _this8.logAPIResponse(response, paymentMethod$4);
18786
18992
 
18787
18993
  return response;
18788
18994
  });
@@ -18790,9 +18996,78 @@ var CardCharge = {
18790
18996
  listenFor3DSCharge: function listenFor3DSCharge(callback) {
18791
18997
  var listenerOptions = {
18792
18998
  channel: "3DS_".concat(this.id),
18793
- paymentMethod: paymentMethod$3
18999
+ paymentMethod: paymentMethod$4
18794
19000
  };
18795
19001
  return this.listenForCharge(listenerOptions, callback);
19002
+ },
19003
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
19004
+ return CardAPI$1.requestSavedCardsOTP(phoneNumber);
19005
+ },
19006
+ addUserToSavedCards: function addUserToSavedCards(_ref4) {
19007
+ var phone = _ref4.phone;
19008
+ return CardAPI$1.addUserToSavedCards({
19009
+ phone: phone,
19010
+ email: this.email
19011
+ });
19012
+ },
19013
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19014
+ var _this9 = this;
19015
+
19016
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19017
+ var code, phone, payload, response;
19018
+ return regeneratorRuntime.wrap(function _callee$(_context) {
19019
+ while (1) {
19020
+ switch (_context.prev = _context.next) {
19021
+ case 0:
19022
+ code = _ref5.code, phone = _ref5.phone;
19023
+ payload = {
19024
+ code: code,
19025
+ phone: phone,
19026
+ transaction: _this9.id
19027
+ };
19028
+ _context.prev = 2;
19029
+ _context.next = 5;
19030
+ return CardAPI$1.verifySavedCardsOtp(payload);
19031
+
19032
+ case 5:
19033
+ response = _context.sent;
19034
+ _this9.savedCardsToken = response.data.token;
19035
+ return _context.abrupt("return", response);
19036
+
19037
+ case 10:
19038
+ _context.prev = 10;
19039
+ _context.t0 = _context["catch"](2);
19040
+ _this9.savedCardsToken = null;
19041
+ throw _context.t0;
19042
+
19043
+ case 14:
19044
+ case "end":
19045
+ return _context.stop();
19046
+ }
19047
+ }
19048
+ }, _callee, null, [[2, 10]]);
19049
+ }))();
19050
+ },
19051
+ getSavedCards: function getSavedCards() {
19052
+ return CardAPI$1.getSavedCards({
19053
+ token: this.savedCardsToken
19054
+ });
19055
+ },
19056
+ deleteSavedCard: function deleteSavedCard(cardCode) {
19057
+ return CardAPI$1.deleteSavedCard({
19058
+ cardCode: cardCode,
19059
+ token: this.savedCardsToken
19060
+ });
19061
+ },
19062
+ chargeSavedCard: function chargeSavedCard(_ref6) {
19063
+ var cardCode = _ref6.cardCode;
19064
+ return CardAPI$1.chargeSavedCard({
19065
+ cardCode: cardCode,
19066
+ transaction: this.id,
19067
+ token: this.savedCardsToken,
19068
+ device: this.deviceFingerprint,
19069
+ selectedCurrency: this.currency
19070
+ });
18796
19071
  }
18797
19072
  };
18798
19073
 
@@ -18945,9 +19220,9 @@ var EMandateAPI = {
18945
19220
  }
18946
19221
  };
18947
19222
 
18948
- var paymentMethod$2 = 'bank account';
19223
+ var paymentMethod$3 = 'bank account';
18949
19224
 
18950
- function validate$2(bankAccount, isSetter) {
19225
+ function validate$3(bankAccount, isSetter) {
18951
19226
  return new Promise(function (resolve, reject) {
18952
19227
  var validation = BankAccount.validate(bankAccount);
18953
19228
 
@@ -18965,15 +19240,15 @@ var EMandate = {
18965
19240
  setBankAccount: function setBankAccount(params) {
18966
19241
  var _this = this;
18967
19242
 
18968
- return validate$2(params, true).then(function () {
19243
+ return validate$3(params, true).then(function () {
18969
19244
  _this.bankAccount = new BankAccount(params);
18970
19245
  });
18971
19246
  },
18972
19247
  chargeBankAccount: function chargeBankAccount() {
18973
19248
  var _this2 = this;
18974
19249
 
18975
- return validate$2(this.bankAccount).then(function () {
18976
- _this2.logAttempt(paymentMethod$2);
19250
+ return validate$3(this.bankAccount).then(function () {
19251
+ _this2.logAttempt(paymentMethod$3);
18977
19252
 
18978
19253
  var verifyParams = {
18979
19254
  bankId: _this2.bankAccount.bankId,
@@ -18982,7 +19257,7 @@ var EMandate = {
18982
19257
  device: _this2.deviceFingerprint
18983
19258
  };
18984
19259
  return EMandateAPI.verify(verifyParams).then(function (response) {
18985
- _this2.logAPIResponse(response, paymentMethod$2);
19260
+ _this2.logAPIResponse(response, paymentMethod$3);
18986
19261
 
18987
19262
  return response;
18988
19263
  });
@@ -18991,7 +19266,7 @@ var EMandate = {
18991
19266
  registerBankAccount: function registerBankAccount(birthday) {
18992
19267
  var _this3 = this;
18993
19268
 
18994
- return validate$2(this.bankAccount).then(function () {
19269
+ return validate$3(this.bankAccount).then(function () {
18995
19270
  var registerParams = {
18996
19271
  bankId: _this3.bankAccount.bankId,
18997
19272
  transactionId: _this3.id,
@@ -18999,7 +19274,7 @@ var EMandate = {
18999
19274
  birthday: birthday
19000
19275
  };
19001
19276
  return EMandateAPI.register(registerParams).then(function (response) {
19002
- _this3.logAPIResponse(response, paymentMethod$2);
19277
+ _this3.logAPIResponse(response, paymentMethod$3);
19003
19278
 
19004
19279
  return response;
19005
19280
  });
@@ -19008,7 +19283,7 @@ var EMandate = {
19008
19283
  authenticateBankAccount: function authenticateBankAccount(token) {
19009
19284
  var _this4 = this;
19010
19285
 
19011
- return validate$2(this.bankAccount).then(function () {
19286
+ return validate$3(this.bankAccount).then(function () {
19012
19287
  var chargeParams = {
19013
19288
  bankId: _this4.bankAccount.bankId,
19014
19289
  transactionId: _this4.id,
@@ -19016,7 +19291,7 @@ var EMandate = {
19016
19291
  device: _this4.deviceFingerprint
19017
19292
  };
19018
19293
  return EMandateAPI.authenticate(chargeParams).then(function (response) {
19019
- _this4.logAPIResponse(response, paymentMethod$2);
19294
+ _this4.logAPIResponse(response, paymentMethod$3);
19020
19295
 
19021
19296
  return response;
19022
19297
  });
@@ -19077,7 +19352,7 @@ var DigitalBankMandateAPI = {
19077
19352
  }
19078
19353
  };
19079
19354
 
19080
- var paymentMethod$1 = 'bank';
19355
+ var paymentMethod$2 = 'bank';
19081
19356
  var DigitalBankMandate = {
19082
19357
  chargeDigitalBankMandate: function chargeDigitalBankMandate(_ref) {
19083
19358
  var _this = this;
@@ -19092,7 +19367,7 @@ var DigitalBankMandate = {
19092
19367
  bankId: bankId
19093
19368
  };
19094
19369
  return DigitalBankMandateAPI.charge(params).then(function (response) {
19095
- _this.logAPIResponse(response, paymentMethod$1);
19370
+ _this.logAPIResponse(response, paymentMethod$2);
19096
19371
 
19097
19372
  return response;
19098
19373
  });
@@ -19100,7 +19375,7 @@ var DigitalBankMandate = {
19100
19375
  listenForDigitalBankMandateCharge: function listenForDigitalBankMandateCharge(callback) {
19101
19376
  var pusherChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
19102
19377
  var listenerOptions = {
19103
- paymentMethod: paymentMethod$1,
19378
+ paymentMethod: paymentMethod$2,
19104
19379
  channel: pusherChannel
19105
19380
  };
19106
19381
  return this.listenForCharge(listenerOptions, callback);
@@ -19233,7 +19508,7 @@ var QrAPI = {
19233
19508
  }
19234
19509
  };
19235
19510
 
19236
- function validate$1(channel) {
19511
+ function validate$2(channel) {
19237
19512
  return new Promise(function (resolve, reject) {
19238
19513
  var allowedChannels = ['visa', 'MPASS_OLTI'];
19239
19514
 
@@ -19251,7 +19526,7 @@ var QRCharge = {
19251
19526
  var _this = this;
19252
19527
 
19253
19528
  var channel = _ref.channel;
19254
- return validate$1(channel).then(function () {
19529
+ return validate$2(channel).then(function () {
19255
19530
  if (_this.qr[channel]) {
19256
19531
  return _this.qr[channel];
19257
19532
  }
@@ -19273,7 +19548,7 @@ var QRCharge = {
19273
19548
  var _this2 = this;
19274
19549
 
19275
19550
  var channel = _ref2.channel;
19276
- return validate$1(channel).then(function () {
19551
+ return validate$2(channel).then(function () {
19277
19552
  if (!_this2.qr[channel]) {
19278
19553
  return Promise.reject(Error('Please generate qr code with Transaction.getQRCode()'));
19279
19554
  }
@@ -19394,7 +19669,7 @@ var MobileMoneyAPI = {
19394
19669
  }
19395
19670
  };
19396
19671
 
19397
- function validate(phoneNumber) {
19672
+ function validate$1(phoneNumber) {
19398
19673
  return new Promise(function (resolve, reject) {
19399
19674
  var validation = PhoneNumber.validate(phoneNumber);
19400
19675
 
@@ -19415,7 +19690,7 @@ var MobileMoneyCharge = {
19415
19690
  provider = _ref.provider,
19416
19691
  voucher = _ref.voucher,
19417
19692
  registrationToken = _ref.registrationToken;
19418
- return validate(phoneNumber).then(function () {
19693
+ return validate$1(phoneNumber).then(function () {
19419
19694
  _this.logAttempt('mobile money');
19420
19695
 
19421
19696
  var params = {
@@ -19446,7 +19721,7 @@ var MobileMoneyCharge = {
19446
19721
  var phoneNumber = payload.phoneNumber,
19447
19722
  provider = payload.provider,
19448
19723
  registrationToken = payload.registrationToken;
19449
- return validate(phoneNumber).then(function () {
19724
+ return validate$1(phoneNumber).then(function () {
19450
19725
  _this2.logMobileMoneyActions(payload);
19451
19726
 
19452
19727
  var params = {
@@ -19586,7 +19861,7 @@ var DirectDebitAPI = {
19586
19861
  }
19587
19862
  };
19588
19863
 
19589
- var paymentMethod = 'direct debit';
19864
+ var paymentMethod$1 = 'direct debit';
19590
19865
  var DirectDebitCharge = {
19591
19866
  loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
19592
19867
  var _this = this;
@@ -19632,14 +19907,14 @@ var DirectDebitCharge = {
19632
19907
  return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
19633
19908
  }
19634
19909
 
19635
- this.logAttempt(paymentMethod);
19910
+ this.logAttempt(paymentMethod$1);
19636
19911
  var params = {
19637
19912
  account_code: accountCode,
19638
19913
  transaction: this.id,
19639
19914
  token: this.directDebit.token
19640
19915
  };
19641
19916
  return DirectDebitAPI.charge(params).then(function (response) {
19642
- _this2.logAPIResponse(response, paymentMethod);
19917
+ _this2.logAPIResponse(response, paymentMethod$1);
19643
19918
 
19644
19919
  if (response.status) {
19645
19920
  _this2.directDebit.chargeResponse = response;
@@ -19652,7 +19927,7 @@ var DirectDebitCharge = {
19652
19927
  var _this3 = this;
19653
19928
 
19654
19929
  return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
19655
- _this3.logAPIResponse(response, paymentMethod);
19930
+ _this3.logAPIResponse(response, paymentMethod$1);
19656
19931
 
19657
19932
  var status = response.status,
19658
19933
  data = response.data;
@@ -19677,7 +19952,7 @@ var DirectDebitCharge = {
19677
19952
  token: this.directDebit.token
19678
19953
  };
19679
19954
  return DirectDebitAPI.authenticate(params).then(function (response) {
19680
- _this4.logAPIResponse(response, paymentMethod);
19955
+ _this4.logAPIResponse(response, paymentMethod$1);
19681
19956
 
19682
19957
  return response;
19683
19958
  });
@@ -20121,6 +20396,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20121
20396
  this.subscription = data.subscription || null;
20122
20397
  this.planDetails = data.plan_details || null;
20123
20398
  this.exchangeRate = data.exchange_rate || null;
20399
+ this.savedCardsConfig = data.saved_cards || {};
20400
+ this.savedCardsToken = null;
20124
20401
  /**
20125
20402
  * We initialize parameters we send to the API as empty strings
20126
20403
  * when we don't have them instead of null because the API expects
@@ -20461,6 +20738,417 @@ var Toolkit = /*#__PURE__*/function () {
20461
20738
  return Toolkit;
20462
20739
  }();
20463
20740
 
20741
+ cardValidator.creditCardType.addCard({
20742
+ niceType: 'Verve',
20743
+ type: 'verve',
20744
+ patterns: [[506000, 507999], [650000, 650009]],
20745
+ gaps: [4, 8, 12, 16],
20746
+ lengths: [16, 18, 19],
20747
+ code: {
20748
+ name: 'CVV',
20749
+ size: 3
20750
+ }
20751
+ });
20752
+ cardValidator.creditCardType.changeOrder('verve', 0);
20753
+
20754
+ var Card = /*#__PURE__*/function () {
20755
+ function Card(_ref) {
20756
+ var number = _ref.number,
20757
+ cvv = _ref.cvv,
20758
+ month = _ref.month,
20759
+ year = _ref.year,
20760
+ pin = _ref.pin;
20761
+
20762
+ _classCallCheck(this, Card);
20763
+
20764
+ this.number = number;
20765
+ this.cvv = cvv;
20766
+ this.month = month;
20767
+ this.year = year;
20768
+ this.pin = pin;
20769
+ }
20770
+
20771
+ _createClass(Card, [{
20772
+ key: "getEncryptedPin",
20773
+ value: function getEncryptedPin() {
20774
+ return Card$2.getEncryptedPin(this.pin);
20775
+ }
20776
+ }, {
20777
+ key: "getLast4",
20778
+ value: function getLast4() {
20779
+ return Card$2.getLast4(this.number);
20780
+ }
20781
+ }, {
20782
+ key: "tokenize",
20783
+ value: function tokenize() {
20784
+ return Card$2.tokenize({
20785
+ number: this.number,
20786
+ cvv: this.cvv,
20787
+ month: this.month,
20788
+ year: this.year
20789
+ });
20790
+ }
20791
+ }], [{
20792
+ key: "getType",
20793
+ value: function getType(value) {
20794
+ return Card$2.getType(value);
20795
+ }
20796
+ }, {
20797
+ key: "validate",
20798
+ value: function validate(_ref2) {
20799
+ var number = _ref2.number,
20800
+ cvv = _ref2.cvv,
20801
+ month = _ref2.month,
20802
+ year = _ref2.year;
20803
+ return Card$2.validate({
20804
+ number: number,
20805
+ cvv: cvv,
20806
+ month: month,
20807
+ year: year
20808
+ });
20809
+ }
20810
+ }, {
20811
+ key: "validateNumber",
20812
+ value: function validateNumber(value) {
20813
+ return Card$2.validateNumber(value);
20814
+ }
20815
+ }, {
20816
+ key: "isNumberValid",
20817
+ value: function isNumberValid(value) {
20818
+ return Card$2.isNumberValid(value);
20819
+ }
20820
+ }, {
20821
+ key: "validateCVV",
20822
+ value: function validateCVV(cvv, cardType) {
20823
+ return Card$2.validateCVV(cvv, cardType);
20824
+ }
20825
+ }, {
20826
+ key: "isCvvValid",
20827
+ value: function isCvvValid(cvv, cardType) {
20828
+ return Card$2.isCvvValid(cvv, cardType);
20829
+ }
20830
+ }, {
20831
+ key: "validateExpiry",
20832
+ value: function validateExpiry(value) {
20833
+ return Card$2.validateExpiry(value);
20834
+ }
20835
+ }, {
20836
+ key: "isExpiryValid",
20837
+ value: function isExpiryValid(value) {
20838
+ return Card$2.isExpiryValid(value);
20839
+ }
20840
+ }, {
20841
+ key: "generateTestCard",
20842
+ value: function generateTestCard(cardType) {
20843
+ var type = cardType || 'default';
20844
+ var cardParams = testCards.find(function (card) {
20845
+ return card.type === type;
20846
+ });
20847
+ return new Card(cardParams);
20848
+ }
20849
+ }]);
20850
+
20851
+ return Card;
20852
+ }();
20853
+
20854
+ var CardAPI = {
20855
+ reserve: function reserve(_ref) {
20856
+ var clientdata = _ref.clientdata,
20857
+ last4 = _ref.last4,
20858
+ preauthorizationId = _ref.preauthorizationId;
20859
+ var url = "".concat(configToUse.paystackApiUrl, "preauthorization/reserve");
20860
+ var language = getLanguage();
20861
+
20862
+ var headers = _objectSpread2({}, language && {
20863
+ 'Accept-Language': language
20864
+ });
20865
+
20866
+ return axiosInstance.post(url, {
20867
+ clientdata: clientdata,
20868
+ last4: last4,
20869
+ preauthorization: preauthorizationId
20870
+ }, {
20871
+ headers: headers
20872
+ }).then(function (response) {
20873
+ return ChargeResponses.parse(response.data);
20874
+ });
20875
+ } // charge({
20876
+ // clientdata,
20877
+ // last4,
20878
+ // pin,
20879
+ // trans,
20880
+ // device,
20881
+ // rememberCard,
20882
+ // transactionType,
20883
+ // subscription,
20884
+ // customFields,
20885
+ // }) {
20886
+ // const url = `${config.paymentBaseUrl}charge/`;
20887
+ // const language = getLanguage();
20888
+ // const headers = {
20889
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20890
+ // ...(language && { 'Accept-Language': language }),
20891
+ // };
20892
+ // const chargeParams = {
20893
+ // clientdata,
20894
+ // last4,
20895
+ // trans,
20896
+ // device,
20897
+ // offset: new Date().getTimezoneOffset(),
20898
+ // remember_card: rememberCard,
20899
+ // ...(transactionType && { transaction_type: transactionType }),
20900
+ // ...(subscription && { subscription }),
20901
+ // ...(customFields && customFields),
20902
+ // };
20903
+ // if (pin) {
20904
+ // chargeParams.handle = pin;
20905
+ // }
20906
+ // const urlEncodedParams = formurlencoded(chargeParams);
20907
+ // return axiosInstance
20908
+ // .post(url, urlEncodedParams, { headers })
20909
+ // .then((response) => ChargeResponses.parse(response.data));
20910
+ // },
20911
+ // resumeCardCharge({ device, accessCode, pin }) {
20912
+ // const url = `${config.paymentBaseUrl}charge/resume/${accessCode}`;
20913
+ // const language = getLanguage();
20914
+ // const headers = {
20915
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20916
+ // ...(language && { 'Accept-Language': language }),
20917
+ // };
20918
+ // const data = { device, ...(pin && { handle: pin }) };
20919
+ // const urlEncodedData = formurlencoded(data);
20920
+ // return axiosInstance
20921
+ // .post(url, urlEncodedData, { headers })
20922
+ // .then((response) => ChargeResponses.parse(response.data));
20923
+ // },
20924
+ // chargeRememberedCard({
20925
+ // last4,
20926
+ // trans,
20927
+ // device,
20928
+ // authorizationCode,
20929
+ // cvv,
20930
+ // pin,
20931
+ // transactionType,
20932
+ // subscription,
20933
+ // }) {
20934
+ // const url = `${config.paymentBaseUrl}charge/`;
20935
+ // const language = getLanguage();
20936
+ // const headers = {
20937
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20938
+ // ...(language && { 'Accept-Language': language }),
20939
+ // };
20940
+ // const chargeParams = {
20941
+ // last4,
20942
+ // trans,
20943
+ // device,
20944
+ // cvv,
20945
+ // handle: pin,
20946
+ // authorization_code: authorizationCode,
20947
+ // ...(transactionType && { transaction_type: transactionType }),
20948
+ // ...(subscription && { subscription }),
20949
+ // };
20950
+ // const urlEncodedParams = formurlencoded(chargeParams);
20951
+ // return axiosInstance
20952
+ // .post(url, urlEncodedParams, { headers })
20953
+ // .then((response) => ChargeResponses.parse(response.data));
20954
+ // },
20955
+ // verifyAddress({ address, city, state, zipCode, transactionId }) {
20956
+ // const url = `${config.paymentBaseUrl}charge/avs`;
20957
+ // const language = getLanguage();
20958
+ // const headers = {
20959
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20960
+ // ...(language && { 'Accept-Language': language }),
20961
+ // };
20962
+ // const data = {
20963
+ // city,
20964
+ // state,
20965
+ // address,
20966
+ // zip_code: zipCode,
20967
+ // trans: transactionId,
20968
+ // };
20969
+ // const urlEncodedData = formurlencoded(data);
20970
+ // return axiosInstance
20971
+ // .post(url, urlEncodedData, { headers })
20972
+ // .then((response) => ChargeResponses.parse(response.data));
20973
+ // },
20974
+ // forgetRememberedCard({ authorizationId, publicKey }) {
20975
+ // const language = getLanguage();
20976
+ // const headers = {
20977
+ // Authorization: `Bearer ${publicKey}`,
20978
+ // ...(language && { 'Accept-Language': language }),
20979
+ // };
20980
+ // const params = {
20981
+ // authorization_id: authorizationId,
20982
+ // };
20983
+ // const url = `${config.paystackApiUrl}rememberme/forget_card`;
20984
+ // return axiosInstance
20985
+ // .post(url, params, { headers })
20986
+ // .then((response) => ChargeResponses.parse(response.data));
20987
+ // },
20988
+
20989
+ };
20990
+
20991
+ var paymentMethod = 'card';
20992
+
20993
+ function validate(card, isSetter) {
20994
+ return new Promise(function (resolve, reject) {
20995
+ var validation = Card.validate(card);
20996
+
20997
+ if (!validation.isValid) {
20998
+ var throwValidation = isSetter || card.number;
20999
+ var errors = Object.keys(validation.result).filter(function (value) {
21000
+ return validation.result[value] === false;
21001
+ });
21002
+ var errorMessage = "Invalid card details: ".concat(errors.join(', '));
21003
+ reject(Error(throwValidation ? errorMessage : 'Please set a valid card with setCard()'));
21004
+ }
21005
+
21006
+ resolve();
21007
+ });
21008
+ }
21009
+
21010
+ var ReserveCardFunds = {
21011
+ setCard: function setCard(params) {
21012
+ var _this = this;
21013
+
21014
+ return validate(params, true).then(function () {
21015
+ _this.card = new Card(params);
21016
+ });
21017
+ },
21018
+ reserve: function reserve(preauthorizationId) {
21019
+ var _this2 = this;
21020
+
21021
+ var customFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21022
+ // TODO: Log payment method
21023
+ // https://paystack.atlassian.net/browse/RAILS-3070
21024
+ return validate(this.card).then(function () {
21025
+ var chargeParams = {
21026
+ clientdata: _this2.card.tokenize(),
21027
+ last4: _this2.card.getLast4(),
21028
+ preauthorization: preauthorizationId,
21029
+ customFields: customFields
21030
+ };
21031
+ return CardAPI.charge(chargeParams).then(function (response) {
21032
+ // TODO: Log API Response
21033
+ // https://paystack.atlassian.net/browse/RAILS-3070
21034
+ return response;
21035
+ });
21036
+ });
21037
+ },
21038
+ listenFor3DSCharge: function listenFor3DSCharge(callback) {
21039
+ var listenerOptions = {
21040
+ channel: "3DS_".concat(this.id),
21041
+ paymentMethod: paymentMethod
21042
+ };
21043
+ return this.listenForCharge(listenerOptions, callback);
21044
+ } // rememberCard() {
21045
+ // this.remember_card = true;
21046
+ // },
21047
+ // chargeCard(customFields = {}) {
21048
+ // if (!this.card.number && this.card.pin) {
21049
+ // return this.chargeCardWithPin(customFields);
21050
+ // }
21051
+ // return validate(this.card).then(() => {
21052
+ // this.logAttempt(paymentMethod);
21053
+ // const chargeParams = {
21054
+ // clientdata: this.card.tokenize(),
21055
+ // last4: this.card.getLast4(),
21056
+ // pin: this.card.getEncryptedPin(),
21057
+ // trans: this.id,
21058
+ // device: this.deviceFingerprint,
21059
+ // rememberCard: this.remember_card,
21060
+ // transactionType: this.transactionType,
21061
+ // subscription: this.subscription,
21062
+ // customFields,
21063
+ // };
21064
+ // return CardAPI.charge(chargeParams).then((response) => {
21065
+ // this.logAPIResponse(response, paymentMethod);
21066
+ // return response;
21067
+ // });
21068
+ // });
21069
+ // },
21070
+
21071
+ /**
21072
+ * Handles submitting a card pin after
21073
+ * other card details have been previously submitted.
21074
+ */
21075
+ // chargeCardWithPin(customFields = {}) {
21076
+ // this.logAttempt(paymentMethod);
21077
+ // const chargeParams = {
21078
+ // pin: encrypt(this.card.pin),
21079
+ // trans: this.id,
21080
+ // device: this.deviceFingerprint,
21081
+ // rememberCard: this.remember_card,
21082
+ // transactionType: this.transactionType,
21083
+ // subscription: this.subscription,
21084
+ // customFields,
21085
+ // };
21086
+ // return CardAPI.charge(chargeParams).then((response) => {
21087
+ // this.logAPIResponse(response, paymentMethod);
21088
+ // return response;
21089
+ // });
21090
+ // },
21091
+ // chargeRememberedCard({ cvv, authorizationCode, cardLast4, pin }) {
21092
+ // this.logAttempt(paymentMethod);
21093
+ // const encryptedPin = encrypt(pin);
21094
+ // const chargeParams = {
21095
+ // authorizationCode,
21096
+ // cvv,
21097
+ // last4: cardLast4,
21098
+ // trans: this.id,
21099
+ // device: this.deviceFingerprint,
21100
+ // pin: encryptedPin,
21101
+ // transactionType: this.transactionType,
21102
+ // subscription: this.subscription,
21103
+ // };
21104
+ // return CardAPI.chargeRememberedCard(chargeParams).then((response) => {
21105
+ // this.logAPIResponse(response, paymentMethod);
21106
+ // return response;
21107
+ // });
21108
+ // },
21109
+ // resumeCardCharge({ accessCode, pin }) {
21110
+ // const params = {
21111
+ // ...(pin && { pin: encrypt(pin) }),
21112
+ // accessCode,
21113
+ // device: this.deviceFingerprint,
21114
+ // };
21115
+ // return CardAPI.resumeCardCharge(params).then((response) => {
21116
+ // this.logAPIResponse(response, paymentMethod);
21117
+ // return response;
21118
+ // });
21119
+ // },
21120
+ // forgetRememberedCard(authorizationId) {
21121
+ // const params = {
21122
+ // authorizationId,
21123
+ // publicKey: this.merchant.key,
21124
+ // };
21125
+ // return CardAPI.forgetRememberedCard(params).then((response) => {
21126
+ // this.logAPIResponse(response, paymentMethod);
21127
+ // return response;
21128
+ // });
21129
+ // },
21130
+ // authenticateCard(token) {
21131
+ // return CardAPI.authenticate(this.id, token).then((response) => {
21132
+ // this.logAPIResponse(response, paymentMethod);
21133
+ // return response;
21134
+ // });
21135
+ // },
21136
+ // verifyAddress({ address, city, state, zipCode }) {
21137
+ // const payload = {
21138
+ // city,
21139
+ // state,
21140
+ // address,
21141
+ // zipCode,
21142
+ // transactionId: this.id,
21143
+ // };
21144
+ // return CardAPI.verifyAddress(payload).then((response) => {
21145
+ // this.logAPIResponse(response, paymentMethod);
21146
+ // return response;
21147
+ // });
21148
+ // },
21149
+
21150
+ };
21151
+
20464
21152
  var PreauthorizationInstance = /*#__PURE__*/function () {
20465
21153
  function PreauthorizationInstance(data) {
20466
21154
  _classCallCheck(this, PreauthorizationInstance);
@@ -20480,8 +21168,10 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20480
21168
  name: data.merchant_name,
20481
21169
  key: data.merchant_key
20482
21170
  };
20483
- loadPusher(); // TODO: Bind charge function to card channel
20484
- // https://paystack.atlassian.net/browse/RAILS-2887
21171
+ loadPusher(); // TODO: Analytics
21172
+ // https://paystack.atlassian.net/browse/RAILS-3070
21173
+
21174
+ Object.assign(this, ReserveCardFunds);
20485
21175
  }
20486
21176
 
20487
21177
  _createClass(PreauthorizationInstance, [{
@@ -20563,7 +21253,7 @@ var Preauthorization = {
20563
21253
  };
20564
21254
 
20565
21255
  exports.BankAccount = BankAccount;
20566
- exports.Card = Card;
21256
+ exports.Card = Card$1;
20567
21257
  exports.Preauthorization = Preauthorization;
20568
21258
  exports.Toolkit = Toolkit;
20569
21259
  exports.Transaction = Transaction;