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

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,6 +18198,137 @@ var cardValidator = {
18244
18198
  creditCardType: creditCardType_1
18245
18199
  };
18246
18200
 
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
+ };
18331
+
18247
18332
  var testCards = [{
18248
18333
  type: 'bank_auth',
18249
18334
  name: 'Bank authorization',
@@ -18308,7 +18393,7 @@ cardValidator.creditCardType.addCard({
18308
18393
  });
18309
18394
  cardValidator.creditCardType.changeOrder('verve', 0);
18310
18395
 
18311
- var Card = /*#__PURE__*/function () {
18396
+ var Card$1 = /*#__PURE__*/function () {
18312
18397
  function Card(_ref) {
18313
18398
  var number = _ref.number,
18314
18399
  cvv = _ref.cvv,
@@ -18328,35 +18413,27 @@ var Card = /*#__PURE__*/function () {
18328
18413
  _createClass(Card, [{
18329
18414
  key: "getEncryptedPin",
18330
18415
  value: function getEncryptedPin() {
18331
- return this.pin ? encrypt(this.pin) : undefined;
18416
+ return Card$2.getEncryptedPin(this.pin);
18332
18417
  }
18333
18418
  }, {
18334
18419
  key: "getLast4",
18335
18420
  value: function getLast4() {
18336
- return this.number.substring(this.number.length - 4);
18421
+ return Card$2.getLast4(this.number);
18337
18422
  }
18338
18423
  }, {
18339
18424
  key: "tokenize",
18340
18425
  value: function tokenize() {
18341
- return encrypt("".concat(this.number, "*").concat(this.cvv, "*").concat(this.month, "*").concat(this.year));
18426
+ return Card$2.tokenize({
18427
+ number: this.number,
18428
+ cvv: this.cvv,
18429
+ month: this.month,
18430
+ year: this.year
18431
+ });
18342
18432
  }
18343
18433
  }], [{
18344
18434
  key: "getType",
18345
18435
  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
- };
18436
+ return Card$2.getType(value);
18360
18437
  }
18361
18438
  }, {
18362
18439
  key: "validate",
@@ -18365,63 +18442,42 @@ var Card = /*#__PURE__*/function () {
18365
18442
  cvv = _ref2.cvv,
18366
18443
  month = _ref2.month,
18367
18444
  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;
18445
+ return Card$2.validate({
18446
+ number: number,
18447
+ cvv: cvv,
18448
+ month: month,
18449
+ year: year
18382
18450
  });
18383
- return {
18384
- isValid: isValid,
18385
- result: result
18386
- };
18387
18451
  }
18388
18452
  }, {
18389
18453
  key: "validateNumber",
18390
18454
  value: function validateNumber(value) {
18391
- return cardValidator.number(value);
18455
+ return Card$2.validateNumber(value);
18392
18456
  }
18393
18457
  }, {
18394
18458
  key: "isNumberValid",
18395
18459
  value: function isNumberValid(value) {
18396
- return Card.validateNumber(value).isValid;
18460
+ return Card$2.isNumberValid(value);
18397
18461
  }
18398
18462
  }, {
18399
18463
  key: "validateCVV",
18400
18464
  value: function validateCVV(cvv, cardType) {
18401
- var isAmexCard = cardType === 'american-express';
18402
- var cvvLength = isAmexCard ? 4 : 3;
18403
- return cardValidator.cvv(cvv, cvvLength);
18465
+ return Card$2.validateCVV(cvv, cardType);
18404
18466
  }
18405
18467
  }, {
18406
18468
  key: "isCvvValid",
18407
18469
  value: function isCvvValid(cvv, cardType) {
18408
- return Card.validateCVV(cvv, cardType).isValid;
18470
+ return Card$2.isCvvValid(cvv, cardType);
18409
18471
  }
18410
18472
  }, {
18411
18473
  key: "validateExpiry",
18412
18474
  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);
18475
+ return Card$2.validateExpiry(value);
18420
18476
  }
18421
18477
  }, {
18422
18478
  key: "isExpiryValid",
18423
18479
  value: function isExpiryValid(value) {
18424
- return Card.validateExpiry(value).isValid;
18480
+ return Card$2.isExpiryValid(value);
18425
18481
  }
18426
18482
  }, {
18427
18483
  key: "generateTestCard",
@@ -18437,7 +18493,7 @@ var Card = /*#__PURE__*/function () {
18437
18493
  return Card;
18438
18494
  }();
18439
18495
 
18440
- var CardAPI = {
18496
+ var CardAPI$1 = {
18441
18497
  charge: function charge(_ref) {
18442
18498
  var clientdata = _ref.clientdata,
18443
18499
  last4 = _ref.last4,
@@ -18613,14 +18669,215 @@ var CardAPI = {
18613
18669
  }).then(function (response) {
18614
18670
  return ChargeResponses.parse(response.data);
18615
18671
  });
18672
+ },
18673
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
18674
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18675
+ var url, language, headers, _yield$axiosInstance$, data;
18676
+
18677
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18678
+ while (1) {
18679
+ switch (_context.prev = _context.next) {
18680
+ case 0:
18681
+ url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18682
+ language = getLanguage();
18683
+ headers = _objectSpread2({}, language && {
18684
+ 'Accept-Language': language
18685
+ });
18686
+ _context.next = 5;
18687
+ return axiosInstance.post(url, {
18688
+ headers: headers
18689
+ });
18690
+
18691
+ case 5:
18692
+ _yield$axiosInstance$ = _context.sent;
18693
+ data = _yield$axiosInstance$.data;
18694
+ return _context.abrupt("return", data);
18695
+
18696
+ case 8:
18697
+ case "end":
18698
+ return _context.stop();
18699
+ }
18700
+ }
18701
+ }, _callee);
18702
+ }))();
18703
+ },
18704
+ addUserToSavedCards: function addUserToSavedCards(_ref6) {
18705
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18706
+ var phone, email, url, language, headers, data, response;
18707
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18708
+ while (1) {
18709
+ switch (_context2.prev = _context2.next) {
18710
+ case 0:
18711
+ phone = _ref6.phone, email = _ref6.email;
18712
+ url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18713
+ language = getLanguage();
18714
+ headers = _objectSpread2({}, language && {
18715
+ 'Accept-Language': language
18716
+ });
18717
+ data = {
18718
+ phone: phone,
18719
+ email: email
18720
+ };
18721
+ _context2.next = 7;
18722
+ return axiosInstance.post(url, data, {
18723
+ headers: headers
18724
+ });
18725
+
18726
+ case 7:
18727
+ response = _context2.sent;
18728
+ return _context2.abrupt("return", response.data);
18729
+
18730
+ case 9:
18731
+ case "end":
18732
+ return _context2.stop();
18733
+ }
18734
+ }
18735
+ }, _callee2);
18736
+ }))();
18737
+ },
18738
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18739
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18740
+ var code, phone, transaction, url, language, headers, data, response;
18741
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18742
+ while (1) {
18743
+ switch (_context3.prev = _context3.next) {
18744
+ case 0:
18745
+ code = _ref7.code, phone = _ref7.phone, transaction = _ref7.transaction;
18746
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18747
+ language = getLanguage();
18748
+ headers = _objectSpread2({}, language && {
18749
+ 'Accept-Language': language
18750
+ });
18751
+ data = {
18752
+ code: code,
18753
+ phone: phone,
18754
+ transaction: transaction
18755
+ };
18756
+ _context3.next = 7;
18757
+ return axiosInstance.post(url, data, {
18758
+ headers: headers
18759
+ });
18760
+
18761
+ case 7:
18762
+ response = _context3.sent;
18763
+ return _context3.abrupt("return", response.data);
18764
+
18765
+ case 9:
18766
+ case "end":
18767
+ return _context3.stop();
18768
+ }
18769
+ }
18770
+ }, _callee3);
18771
+ }))();
18772
+ },
18773
+ getSavedCards: function getSavedCards(_ref8) {
18774
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18775
+ var token, url, language, headers, response;
18776
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18777
+ while (1) {
18778
+ switch (_context4.prev = _context4.next) {
18779
+ case 0:
18780
+ token = _ref8.token;
18781
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18782
+ language = getLanguage();
18783
+ headers = _objectSpread2({
18784
+ Authorization: "Bearer ".concat(token),
18785
+ 'jwt-auth': true
18786
+ }, language && {
18787
+ 'Accept-Language': language
18788
+ });
18789
+ _context4.next = 6;
18790
+ return axiosInstance.get(url, {
18791
+ headers: headers
18792
+ });
18793
+
18794
+ case 6:
18795
+ response = _context4.sent;
18796
+ return _context4.abrupt("return", response.data);
18797
+
18798
+ case 8:
18799
+ case "end":
18800
+ return _context4.stop();
18801
+ }
18802
+ }
18803
+ }, _callee4);
18804
+ }))();
18805
+ },
18806
+ deleteSavedCard: function deleteSavedCard(_ref9) {
18807
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18808
+ var cardCode, token, url, language, headers, response;
18809
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18810
+ while (1) {
18811
+ switch (_context5.prev = _context5.next) {
18812
+ case 0:
18813
+ cardCode = _ref9.cardCode, token = _ref9.token;
18814
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18815
+ language = getLanguage();
18816
+ headers = _objectSpread2({
18817
+ Authorization: "Bearer ".concat(token),
18818
+ 'jwt-auth': true
18819
+ }, language && {
18820
+ 'Accept-Language': language
18821
+ });
18822
+ _context5.next = 6;
18823
+ return axiosInstance.delete(url, {
18824
+ headers: headers
18825
+ });
18826
+
18827
+ case 6:
18828
+ response = _context5.sent;
18829
+ return _context5.abrupt("return", response.data);
18830
+
18831
+ case 8:
18832
+ case "end":
18833
+ return _context5.stop();
18834
+ }
18835
+ }
18836
+ }, _callee5);
18837
+ }))();
18838
+ },
18839
+ chargeSavedCard: function chargeSavedCard(_ref10) {
18840
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18841
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18842
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
18843
+ while (1) {
18844
+ switch (_context6.prev = _context6.next) {
18845
+ case 0:
18846
+ token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18847
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18848
+ language = getLanguage();
18849
+ headers = _objectSpread2({
18850
+ Authorization: "Bearer ".concat(token),
18851
+ 'jwt-auth': true
18852
+ }, language && {
18853
+ 'Accept-Language': language
18854
+ });
18855
+ data = {
18856
+ device: device,
18857
+ transaction: transaction,
18858
+ selectedCurrency: selectedCurrency
18859
+ };
18860
+ return _context6.abrupt("return", axiosInstance.post(url, data, {
18861
+ headers: headers
18862
+ }).then(function (response) {
18863
+ return ChargeResponses.parse(response.data);
18864
+ }));
18865
+
18866
+ case 6:
18867
+ case "end":
18868
+ return _context6.stop();
18869
+ }
18870
+ }
18871
+ }, _callee6);
18872
+ }))();
18616
18873
  }
18617
18874
  };
18618
18875
 
18619
- var paymentMethod$3 = 'card';
18876
+ var paymentMethod$4 = 'card';
18620
18877
 
18621
- function validate$3(card, isSetter) {
18878
+ function validate$4(card, isSetter) {
18622
18879
  return new Promise(function (resolve, reject) {
18623
- var validation = Card.validate(card);
18880
+ var validation = Card$1.validate(card);
18624
18881
 
18625
18882
  if (!validation.isValid) {
18626
18883
  var throwValidation = isSetter || card.number;
@@ -18639,8 +18896,8 @@ var CardCharge = {
18639
18896
  setCard: function setCard(params) {
18640
18897
  var _this = this;
18641
18898
 
18642
- return validate$3(params, true).then(function () {
18643
- _this.card = new Card(params);
18899
+ return validate$4(params, true).then(function () {
18900
+ _this.card = new Card$1(params);
18644
18901
  });
18645
18902
  },
18646
18903
  rememberCard: function rememberCard() {
@@ -18655,8 +18912,8 @@ var CardCharge = {
18655
18912
  return this.chargeCardWithPin(customFields);
18656
18913
  }
18657
18914
 
18658
- return validate$3(this.card).then(function () {
18659
- _this2.logAttempt(paymentMethod$3);
18915
+ return validate$4(this.card).then(function () {
18916
+ _this2.logAttempt(paymentMethod$4);
18660
18917
 
18661
18918
  var chargeParams = {
18662
18919
  clientdata: _this2.card.tokenize(),
@@ -18669,8 +18926,8 @@ var CardCharge = {
18669
18926
  subscription: _this2.subscription,
18670
18927
  customFields: customFields
18671
18928
  };
18672
- return CardAPI.charge(chargeParams).then(function (response) {
18673
- _this2.logAPIResponse(response, paymentMethod$3);
18929
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18930
+ _this2.logAPIResponse(response, paymentMethod$4);
18674
18931
 
18675
18932
  return response;
18676
18933
  });
@@ -18685,7 +18942,7 @@ var CardCharge = {
18685
18942
  var _this3 = this;
18686
18943
 
18687
18944
  var customFields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18688
- this.logAttempt(paymentMethod$3);
18945
+ this.logAttempt(paymentMethod$4);
18689
18946
  var chargeParams = {
18690
18947
  pin: encrypt(this.card.pin),
18691
18948
  trans: this.id,
@@ -18695,8 +18952,8 @@ var CardCharge = {
18695
18952
  subscription: this.subscription,
18696
18953
  customFields: customFields
18697
18954
  };
18698
- return CardAPI.charge(chargeParams).then(function (response) {
18699
- _this3.logAPIResponse(response, paymentMethod$3);
18955
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18956
+ _this3.logAPIResponse(response, paymentMethod$4);
18700
18957
 
18701
18958
  return response;
18702
18959
  });
@@ -18708,7 +18965,7 @@ var CardCharge = {
18708
18965
  authorizationCode = _ref.authorizationCode,
18709
18966
  cardLast4 = _ref.cardLast4,
18710
18967
  pin = _ref.pin;
18711
- this.logAttempt(paymentMethod$3);
18968
+ this.logAttempt(paymentMethod$4);
18712
18969
  var encryptedPin = encrypt(pin);
18713
18970
  var chargeParams = {
18714
18971
  authorizationCode: authorizationCode,
@@ -18720,8 +18977,8 @@ var CardCharge = {
18720
18977
  transactionType: this.transactionType,
18721
18978
  subscription: this.subscription
18722
18979
  };
18723
- return CardAPI.chargeRememberedCard(chargeParams).then(function (response) {
18724
- _this4.logAPIResponse(response, paymentMethod$3);
18980
+ return CardAPI$1.chargeRememberedCard(chargeParams).then(function (response) {
18981
+ _this4.logAPIResponse(response, paymentMethod$4);
18725
18982
 
18726
18983
  return response;
18727
18984
  });
@@ -18739,8 +18996,8 @@ var CardCharge = {
18739
18996
  device: this.deviceFingerprint
18740
18997
  });
18741
18998
 
18742
- return CardAPI.resumeCardCharge(params).then(function (response) {
18743
- _this5.logAPIResponse(response, paymentMethod$3);
18999
+ return CardAPI$1.resumeCardCharge(params).then(function (response) {
19000
+ _this5.logAPIResponse(response, paymentMethod$4);
18744
19001
 
18745
19002
  return response;
18746
19003
  });
@@ -18752,8 +19009,8 @@ var CardCharge = {
18752
19009
  authorizationId: authorizationId,
18753
19010
  publicKey: this.merchant.key
18754
19011
  };
18755
- return CardAPI.forgetRememberedCard(params).then(function (response) {
18756
- _this6.logAPIResponse(response, paymentMethod$3);
19012
+ return CardAPI$1.forgetRememberedCard(params).then(function (response) {
19013
+ _this6.logAPIResponse(response, paymentMethod$4);
18757
19014
 
18758
19015
  return response;
18759
19016
  });
@@ -18761,8 +19018,8 @@ var CardCharge = {
18761
19018
  authenticateCard: function authenticateCard(token) {
18762
19019
  var _this7 = this;
18763
19020
 
18764
- return CardAPI.authenticate(this.id, token).then(function (response) {
18765
- _this7.logAPIResponse(response, paymentMethod$3);
19021
+ return CardAPI$1.authenticate(this.id, token).then(function (response) {
19022
+ _this7.logAPIResponse(response, paymentMethod$4);
18766
19023
 
18767
19024
  return response;
18768
19025
  });
@@ -18781,8 +19038,8 @@ var CardCharge = {
18781
19038
  zipCode: zipCode,
18782
19039
  transactionId: this.id
18783
19040
  };
18784
- return CardAPI.verifyAddress(payload).then(function (response) {
18785
- _this8.logAPIResponse(response, paymentMethod$3);
19041
+ return CardAPI$1.verifyAddress(payload).then(function (response) {
19042
+ _this8.logAPIResponse(response, paymentMethod$4);
18786
19043
 
18787
19044
  return response;
18788
19045
  });
@@ -18790,9 +19047,78 @@ var CardCharge = {
18790
19047
  listenFor3DSCharge: function listenFor3DSCharge(callback) {
18791
19048
  var listenerOptions = {
18792
19049
  channel: "3DS_".concat(this.id),
18793
- paymentMethod: paymentMethod$3
19050
+ paymentMethod: paymentMethod$4
18794
19051
  };
18795
19052
  return this.listenForCharge(listenerOptions, callback);
19053
+ },
19054
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
19055
+ return CardAPI$1.requestSavedCardsOTP(phoneNumber);
19056
+ },
19057
+ addUserToSavedCards: function addUserToSavedCards(_ref4) {
19058
+ var phone = _ref4.phone;
19059
+ return CardAPI$1.addUserToSavedCards({
19060
+ phone: phone,
19061
+ email: this.email
19062
+ });
19063
+ },
19064
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19065
+ var _this9 = this;
19066
+
19067
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19068
+ var code, phone, payload, response;
19069
+ return regeneratorRuntime.wrap(function _callee$(_context) {
19070
+ while (1) {
19071
+ switch (_context.prev = _context.next) {
19072
+ case 0:
19073
+ code = _ref5.code, phone = _ref5.phone;
19074
+ payload = {
19075
+ code: code,
19076
+ phone: phone,
19077
+ transaction: _this9.id
19078
+ };
19079
+ _context.prev = 2;
19080
+ _context.next = 5;
19081
+ return CardAPI$1.verifySavedCardsOtp(payload);
19082
+
19083
+ case 5:
19084
+ response = _context.sent;
19085
+ _this9.savedCardsToken = response.data.token;
19086
+ return _context.abrupt("return", response);
19087
+
19088
+ case 10:
19089
+ _context.prev = 10;
19090
+ _context.t0 = _context["catch"](2);
19091
+ _this9.savedCardsToken = null;
19092
+ throw _context.t0;
19093
+
19094
+ case 14:
19095
+ case "end":
19096
+ return _context.stop();
19097
+ }
19098
+ }
19099
+ }, _callee, null, [[2, 10]]);
19100
+ }))();
19101
+ },
19102
+ getSavedCards: function getSavedCards() {
19103
+ return CardAPI$1.getSavedCards({
19104
+ token: this.savedCardsToken
19105
+ });
19106
+ },
19107
+ deleteSavedCard: function deleteSavedCard(cardCode) {
19108
+ return CardAPI$1.deleteSavedCard({
19109
+ cardCode: cardCode,
19110
+ token: this.savedCardsToken
19111
+ });
19112
+ },
19113
+ chargeSavedCard: function chargeSavedCard(_ref6) {
19114
+ var cardCode = _ref6.cardCode;
19115
+ return CardAPI$1.chargeSavedCard({
19116
+ cardCode: cardCode,
19117
+ transaction: this.id,
19118
+ token: this.savedCardsToken,
19119
+ device: this.deviceFingerprint,
19120
+ selectedCurrency: this.currency
19121
+ });
18796
19122
  }
18797
19123
  };
18798
19124
 
@@ -18945,9 +19271,9 @@ var EMandateAPI = {
18945
19271
  }
18946
19272
  };
18947
19273
 
18948
- var paymentMethod$2 = 'bank account';
19274
+ var paymentMethod$3 = 'bank account';
18949
19275
 
18950
- function validate$2(bankAccount, isSetter) {
19276
+ function validate$3(bankAccount, isSetter) {
18951
19277
  return new Promise(function (resolve, reject) {
18952
19278
  var validation = BankAccount.validate(bankAccount);
18953
19279
 
@@ -18965,15 +19291,15 @@ var EMandate = {
18965
19291
  setBankAccount: function setBankAccount(params) {
18966
19292
  var _this = this;
18967
19293
 
18968
- return validate$2(params, true).then(function () {
19294
+ return validate$3(params, true).then(function () {
18969
19295
  _this.bankAccount = new BankAccount(params);
18970
19296
  });
18971
19297
  },
18972
19298
  chargeBankAccount: function chargeBankAccount() {
18973
19299
  var _this2 = this;
18974
19300
 
18975
- return validate$2(this.bankAccount).then(function () {
18976
- _this2.logAttempt(paymentMethod$2);
19301
+ return validate$3(this.bankAccount).then(function () {
19302
+ _this2.logAttempt(paymentMethod$3);
18977
19303
 
18978
19304
  var verifyParams = {
18979
19305
  bankId: _this2.bankAccount.bankId,
@@ -18982,7 +19308,7 @@ var EMandate = {
18982
19308
  device: _this2.deviceFingerprint
18983
19309
  };
18984
19310
  return EMandateAPI.verify(verifyParams).then(function (response) {
18985
- _this2.logAPIResponse(response, paymentMethod$2);
19311
+ _this2.logAPIResponse(response, paymentMethod$3);
18986
19312
 
18987
19313
  return response;
18988
19314
  });
@@ -18991,7 +19317,7 @@ var EMandate = {
18991
19317
  registerBankAccount: function registerBankAccount(birthday) {
18992
19318
  var _this3 = this;
18993
19319
 
18994
- return validate$2(this.bankAccount).then(function () {
19320
+ return validate$3(this.bankAccount).then(function () {
18995
19321
  var registerParams = {
18996
19322
  bankId: _this3.bankAccount.bankId,
18997
19323
  transactionId: _this3.id,
@@ -18999,7 +19325,7 @@ var EMandate = {
18999
19325
  birthday: birthday
19000
19326
  };
19001
19327
  return EMandateAPI.register(registerParams).then(function (response) {
19002
- _this3.logAPIResponse(response, paymentMethod$2);
19328
+ _this3.logAPIResponse(response, paymentMethod$3);
19003
19329
 
19004
19330
  return response;
19005
19331
  });
@@ -19008,7 +19334,7 @@ var EMandate = {
19008
19334
  authenticateBankAccount: function authenticateBankAccount(token) {
19009
19335
  var _this4 = this;
19010
19336
 
19011
- return validate$2(this.bankAccount).then(function () {
19337
+ return validate$3(this.bankAccount).then(function () {
19012
19338
  var chargeParams = {
19013
19339
  bankId: _this4.bankAccount.bankId,
19014
19340
  transactionId: _this4.id,
@@ -19016,7 +19342,7 @@ var EMandate = {
19016
19342
  device: _this4.deviceFingerprint
19017
19343
  };
19018
19344
  return EMandateAPI.authenticate(chargeParams).then(function (response) {
19019
- _this4.logAPIResponse(response, paymentMethod$2);
19345
+ _this4.logAPIResponse(response, paymentMethod$3);
19020
19346
 
19021
19347
  return response;
19022
19348
  });
@@ -19077,7 +19403,7 @@ var DigitalBankMandateAPI = {
19077
19403
  }
19078
19404
  };
19079
19405
 
19080
- var paymentMethod$1 = 'bank';
19406
+ var paymentMethod$2 = 'bank';
19081
19407
  var DigitalBankMandate = {
19082
19408
  chargeDigitalBankMandate: function chargeDigitalBankMandate(_ref) {
19083
19409
  var _this = this;
@@ -19092,7 +19418,7 @@ var DigitalBankMandate = {
19092
19418
  bankId: bankId
19093
19419
  };
19094
19420
  return DigitalBankMandateAPI.charge(params).then(function (response) {
19095
- _this.logAPIResponse(response, paymentMethod$1);
19421
+ _this.logAPIResponse(response, paymentMethod$2);
19096
19422
 
19097
19423
  return response;
19098
19424
  });
@@ -19100,7 +19426,7 @@ var DigitalBankMandate = {
19100
19426
  listenForDigitalBankMandateCharge: function listenForDigitalBankMandateCharge(callback) {
19101
19427
  var pusherChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
19102
19428
  var listenerOptions = {
19103
- paymentMethod: paymentMethod$1,
19429
+ paymentMethod: paymentMethod$2,
19104
19430
  channel: pusherChannel
19105
19431
  };
19106
19432
  return this.listenForCharge(listenerOptions, callback);
@@ -19233,7 +19559,7 @@ var QrAPI = {
19233
19559
  }
19234
19560
  };
19235
19561
 
19236
- function validate$1(channel) {
19562
+ function validate$2(channel) {
19237
19563
  return new Promise(function (resolve, reject) {
19238
19564
  var allowedChannels = ['visa', 'MPASS_OLTI'];
19239
19565
 
@@ -19251,7 +19577,7 @@ var QRCharge = {
19251
19577
  var _this = this;
19252
19578
 
19253
19579
  var channel = _ref.channel;
19254
- return validate$1(channel).then(function () {
19580
+ return validate$2(channel).then(function () {
19255
19581
  if (_this.qr[channel]) {
19256
19582
  return _this.qr[channel];
19257
19583
  }
@@ -19273,7 +19599,7 @@ var QRCharge = {
19273
19599
  var _this2 = this;
19274
19600
 
19275
19601
  var channel = _ref2.channel;
19276
- return validate$1(channel).then(function () {
19602
+ return validate$2(channel).then(function () {
19277
19603
  if (!_this2.qr[channel]) {
19278
19604
  return Promise.reject(Error('Please generate qr code with Transaction.getQRCode()'));
19279
19605
  }
@@ -19394,7 +19720,7 @@ var MobileMoneyAPI = {
19394
19720
  }
19395
19721
  };
19396
19722
 
19397
- function validate(phoneNumber) {
19723
+ function validate$1(phoneNumber) {
19398
19724
  return new Promise(function (resolve, reject) {
19399
19725
  var validation = PhoneNumber.validate(phoneNumber);
19400
19726
 
@@ -19415,7 +19741,7 @@ var MobileMoneyCharge = {
19415
19741
  provider = _ref.provider,
19416
19742
  voucher = _ref.voucher,
19417
19743
  registrationToken = _ref.registrationToken;
19418
- return validate(phoneNumber).then(function () {
19744
+ return validate$1(phoneNumber).then(function () {
19419
19745
  _this.logAttempt('mobile money');
19420
19746
 
19421
19747
  var params = {
@@ -19446,7 +19772,7 @@ var MobileMoneyCharge = {
19446
19772
  var phoneNumber = payload.phoneNumber,
19447
19773
  provider = payload.provider,
19448
19774
  registrationToken = payload.registrationToken;
19449
- return validate(phoneNumber).then(function () {
19775
+ return validate$1(phoneNumber).then(function () {
19450
19776
  _this2.logMobileMoneyActions(payload);
19451
19777
 
19452
19778
  var params = {
@@ -19586,7 +19912,7 @@ var DirectDebitAPI = {
19586
19912
  }
19587
19913
  };
19588
19914
 
19589
- var paymentMethod = 'direct debit';
19915
+ var paymentMethod$1 = 'direct debit';
19590
19916
  var DirectDebitCharge = {
19591
19917
  loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
19592
19918
  var _this = this;
@@ -19632,14 +19958,14 @@ var DirectDebitCharge = {
19632
19958
  return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
19633
19959
  }
19634
19960
 
19635
- this.logAttempt(paymentMethod);
19961
+ this.logAttempt(paymentMethod$1);
19636
19962
  var params = {
19637
19963
  account_code: accountCode,
19638
19964
  transaction: this.id,
19639
19965
  token: this.directDebit.token
19640
19966
  };
19641
19967
  return DirectDebitAPI.charge(params).then(function (response) {
19642
- _this2.logAPIResponse(response, paymentMethod);
19968
+ _this2.logAPIResponse(response, paymentMethod$1);
19643
19969
 
19644
19970
  if (response.status) {
19645
19971
  _this2.directDebit.chargeResponse = response;
@@ -19652,7 +19978,7 @@ var DirectDebitCharge = {
19652
19978
  var _this3 = this;
19653
19979
 
19654
19980
  return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
19655
- _this3.logAPIResponse(response, paymentMethod);
19981
+ _this3.logAPIResponse(response, paymentMethod$1);
19656
19982
 
19657
19983
  var status = response.status,
19658
19984
  data = response.data;
@@ -19677,7 +20003,7 @@ var DirectDebitCharge = {
19677
20003
  token: this.directDebit.token
19678
20004
  };
19679
20005
  return DirectDebitAPI.authenticate(params).then(function (response) {
19680
- _this4.logAPIResponse(response, paymentMethod);
20006
+ _this4.logAPIResponse(response, paymentMethod$1);
19681
20007
 
19682
20008
  return response;
19683
20009
  });
@@ -20121,6 +20447,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20121
20447
  this.subscription = data.subscription || null;
20122
20448
  this.planDetails = data.plan_details || null;
20123
20449
  this.exchangeRate = data.exchange_rate || null;
20450
+ this.savedCardsConfig = data.saved_cards || {};
20451
+ this.savedCardsToken = null;
20124
20452
  /**
20125
20453
  * We initialize parameters we send to the API as empty strings
20126
20454
  * when we don't have them instead of null because the API expects
@@ -20461,6 +20789,417 @@ var Toolkit = /*#__PURE__*/function () {
20461
20789
  return Toolkit;
20462
20790
  }();
20463
20791
 
20792
+ cardValidator.creditCardType.addCard({
20793
+ niceType: 'Verve',
20794
+ type: 'verve',
20795
+ patterns: [[506000, 507999], [650000, 650009]],
20796
+ gaps: [4, 8, 12, 16],
20797
+ lengths: [16, 18, 19],
20798
+ code: {
20799
+ name: 'CVV',
20800
+ size: 3
20801
+ }
20802
+ });
20803
+ cardValidator.creditCardType.changeOrder('verve', 0);
20804
+
20805
+ var Card = /*#__PURE__*/function () {
20806
+ function Card(_ref) {
20807
+ var number = _ref.number,
20808
+ cvv = _ref.cvv,
20809
+ month = _ref.month,
20810
+ year = _ref.year,
20811
+ pin = _ref.pin;
20812
+
20813
+ _classCallCheck(this, Card);
20814
+
20815
+ this.number = number;
20816
+ this.cvv = cvv;
20817
+ this.month = month;
20818
+ this.year = year;
20819
+ this.pin = pin;
20820
+ }
20821
+
20822
+ _createClass(Card, [{
20823
+ key: "getEncryptedPin",
20824
+ value: function getEncryptedPin() {
20825
+ return Card$2.getEncryptedPin(this.pin);
20826
+ }
20827
+ }, {
20828
+ key: "getLast4",
20829
+ value: function getLast4() {
20830
+ return Card$2.getLast4(this.number);
20831
+ }
20832
+ }, {
20833
+ key: "tokenize",
20834
+ value: function tokenize() {
20835
+ return Card$2.tokenize({
20836
+ number: this.number,
20837
+ cvv: this.cvv,
20838
+ month: this.month,
20839
+ year: this.year
20840
+ });
20841
+ }
20842
+ }], [{
20843
+ key: "getType",
20844
+ value: function getType(value) {
20845
+ return Card$2.getType(value);
20846
+ }
20847
+ }, {
20848
+ key: "validate",
20849
+ value: function validate(_ref2) {
20850
+ var number = _ref2.number,
20851
+ cvv = _ref2.cvv,
20852
+ month = _ref2.month,
20853
+ year = _ref2.year;
20854
+ return Card$2.validate({
20855
+ number: number,
20856
+ cvv: cvv,
20857
+ month: month,
20858
+ year: year
20859
+ });
20860
+ }
20861
+ }, {
20862
+ key: "validateNumber",
20863
+ value: function validateNumber(value) {
20864
+ return Card$2.validateNumber(value);
20865
+ }
20866
+ }, {
20867
+ key: "isNumberValid",
20868
+ value: function isNumberValid(value) {
20869
+ return Card$2.isNumberValid(value);
20870
+ }
20871
+ }, {
20872
+ key: "validateCVV",
20873
+ value: function validateCVV(cvv, cardType) {
20874
+ return Card$2.validateCVV(cvv, cardType);
20875
+ }
20876
+ }, {
20877
+ key: "isCvvValid",
20878
+ value: function isCvvValid(cvv, cardType) {
20879
+ return Card$2.isCvvValid(cvv, cardType);
20880
+ }
20881
+ }, {
20882
+ key: "validateExpiry",
20883
+ value: function validateExpiry(value) {
20884
+ return Card$2.validateExpiry(value);
20885
+ }
20886
+ }, {
20887
+ key: "isExpiryValid",
20888
+ value: function isExpiryValid(value) {
20889
+ return Card$2.isExpiryValid(value);
20890
+ }
20891
+ }, {
20892
+ key: "generateTestCard",
20893
+ value: function generateTestCard(cardType) {
20894
+ var type = cardType || 'default';
20895
+ var cardParams = testCards.find(function (card) {
20896
+ return card.type === type;
20897
+ });
20898
+ return new Card(cardParams);
20899
+ }
20900
+ }]);
20901
+
20902
+ return Card;
20903
+ }();
20904
+
20905
+ var CardAPI = {
20906
+ reserve: function reserve(_ref) {
20907
+ var clientdata = _ref.clientdata,
20908
+ last4 = _ref.last4,
20909
+ preauthorizationId = _ref.preauthorizationId;
20910
+ var url = "".concat(configToUse.paystackApiUrl, "preauthorization/reserve");
20911
+ var language = getLanguage();
20912
+
20913
+ var headers = _objectSpread2({}, language && {
20914
+ 'Accept-Language': language
20915
+ });
20916
+
20917
+ return axiosInstance.post(url, {
20918
+ clientdata: clientdata,
20919
+ last4: last4,
20920
+ preauthorization: preauthorizationId
20921
+ }, {
20922
+ headers: headers
20923
+ }).then(function (response) {
20924
+ return ChargeResponses.parse(response.data);
20925
+ });
20926
+ } // charge({
20927
+ // clientdata,
20928
+ // last4,
20929
+ // pin,
20930
+ // trans,
20931
+ // device,
20932
+ // rememberCard,
20933
+ // transactionType,
20934
+ // subscription,
20935
+ // customFields,
20936
+ // }) {
20937
+ // const url = `${config.paymentBaseUrl}charge/`;
20938
+ // const language = getLanguage();
20939
+ // const headers = {
20940
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20941
+ // ...(language && { 'Accept-Language': language }),
20942
+ // };
20943
+ // const chargeParams = {
20944
+ // clientdata,
20945
+ // last4,
20946
+ // trans,
20947
+ // device,
20948
+ // offset: new Date().getTimezoneOffset(),
20949
+ // remember_card: rememberCard,
20950
+ // ...(transactionType && { transaction_type: transactionType }),
20951
+ // ...(subscription && { subscription }),
20952
+ // ...(customFields && customFields),
20953
+ // };
20954
+ // if (pin) {
20955
+ // chargeParams.handle = pin;
20956
+ // }
20957
+ // const urlEncodedParams = formurlencoded(chargeParams);
20958
+ // return axiosInstance
20959
+ // .post(url, urlEncodedParams, { headers })
20960
+ // .then((response) => ChargeResponses.parse(response.data));
20961
+ // },
20962
+ // resumeCardCharge({ device, accessCode, pin }) {
20963
+ // const url = `${config.paymentBaseUrl}charge/resume/${accessCode}`;
20964
+ // const language = getLanguage();
20965
+ // const headers = {
20966
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20967
+ // ...(language && { 'Accept-Language': language }),
20968
+ // };
20969
+ // const data = { device, ...(pin && { handle: pin }) };
20970
+ // const urlEncodedData = formurlencoded(data);
20971
+ // return axiosInstance
20972
+ // .post(url, urlEncodedData, { headers })
20973
+ // .then((response) => ChargeResponses.parse(response.data));
20974
+ // },
20975
+ // chargeRememberedCard({
20976
+ // last4,
20977
+ // trans,
20978
+ // device,
20979
+ // authorizationCode,
20980
+ // cvv,
20981
+ // pin,
20982
+ // transactionType,
20983
+ // subscription,
20984
+ // }) {
20985
+ // const url = `${config.paymentBaseUrl}charge/`;
20986
+ // const language = getLanguage();
20987
+ // const headers = {
20988
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20989
+ // ...(language && { 'Accept-Language': language }),
20990
+ // };
20991
+ // const chargeParams = {
20992
+ // last4,
20993
+ // trans,
20994
+ // device,
20995
+ // cvv,
20996
+ // handle: pin,
20997
+ // authorization_code: authorizationCode,
20998
+ // ...(transactionType && { transaction_type: transactionType }),
20999
+ // ...(subscription && { subscription }),
21000
+ // };
21001
+ // const urlEncodedParams = formurlencoded(chargeParams);
21002
+ // return axiosInstance
21003
+ // .post(url, urlEncodedParams, { headers })
21004
+ // .then((response) => ChargeResponses.parse(response.data));
21005
+ // },
21006
+ // verifyAddress({ address, city, state, zipCode, transactionId }) {
21007
+ // const url = `${config.paymentBaseUrl}charge/avs`;
21008
+ // const language = getLanguage();
21009
+ // const headers = {
21010
+ // 'Content-Type': 'application/x-www-form-urlencoded',
21011
+ // ...(language && { 'Accept-Language': language }),
21012
+ // };
21013
+ // const data = {
21014
+ // city,
21015
+ // state,
21016
+ // address,
21017
+ // zip_code: zipCode,
21018
+ // trans: transactionId,
21019
+ // };
21020
+ // const urlEncodedData = formurlencoded(data);
21021
+ // return axiosInstance
21022
+ // .post(url, urlEncodedData, { headers })
21023
+ // .then((response) => ChargeResponses.parse(response.data));
21024
+ // },
21025
+ // forgetRememberedCard({ authorizationId, publicKey }) {
21026
+ // const language = getLanguage();
21027
+ // const headers = {
21028
+ // Authorization: `Bearer ${publicKey}`,
21029
+ // ...(language && { 'Accept-Language': language }),
21030
+ // };
21031
+ // const params = {
21032
+ // authorization_id: authorizationId,
21033
+ // };
21034
+ // const url = `${config.paystackApiUrl}rememberme/forget_card`;
21035
+ // return axiosInstance
21036
+ // .post(url, params, { headers })
21037
+ // .then((response) => ChargeResponses.parse(response.data));
21038
+ // },
21039
+
21040
+ };
21041
+
21042
+ var paymentMethod = 'card';
21043
+
21044
+ function validate(card, isSetter) {
21045
+ return new Promise(function (resolve, reject) {
21046
+ var validation = Card.validate(card);
21047
+
21048
+ if (!validation.isValid) {
21049
+ var throwValidation = isSetter || card.number;
21050
+ var errors = Object.keys(validation.result).filter(function (value) {
21051
+ return validation.result[value] === false;
21052
+ });
21053
+ var errorMessage = "Invalid card details: ".concat(errors.join(', '));
21054
+ reject(Error(throwValidation ? errorMessage : 'Please set a valid card with setCard()'));
21055
+ }
21056
+
21057
+ resolve();
21058
+ });
21059
+ }
21060
+
21061
+ var ReserveCardFunds = {
21062
+ setCard: function setCard(params) {
21063
+ var _this = this;
21064
+
21065
+ return validate(params, true).then(function () {
21066
+ _this.card = new Card(params);
21067
+ });
21068
+ },
21069
+ reserve: function reserve(preauthorizationId) {
21070
+ var _this2 = this;
21071
+
21072
+ var customFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21073
+ // TODO: Log payment method
21074
+ // https://paystack.atlassian.net/browse/RAILS-3070
21075
+ return validate(this.card).then(function () {
21076
+ var chargeParams = {
21077
+ clientdata: _this2.card.tokenize(),
21078
+ last4: _this2.card.getLast4(),
21079
+ preauthorization: preauthorizationId,
21080
+ customFields: customFields
21081
+ };
21082
+ return CardAPI.charge(chargeParams).then(function (response) {
21083
+ // TODO: Log API Response
21084
+ // https://paystack.atlassian.net/browse/RAILS-3070
21085
+ return response;
21086
+ });
21087
+ });
21088
+ },
21089
+ listenFor3DSCharge: function listenFor3DSCharge(callback) {
21090
+ var listenerOptions = {
21091
+ channel: "3DS_".concat(this.id),
21092
+ paymentMethod: paymentMethod
21093
+ };
21094
+ return this.listenForCharge(listenerOptions, callback);
21095
+ } // rememberCard() {
21096
+ // this.remember_card = true;
21097
+ // },
21098
+ // chargeCard(customFields = {}) {
21099
+ // if (!this.card.number && this.card.pin) {
21100
+ // return this.chargeCardWithPin(customFields);
21101
+ // }
21102
+ // return validate(this.card).then(() => {
21103
+ // this.logAttempt(paymentMethod);
21104
+ // const chargeParams = {
21105
+ // clientdata: this.card.tokenize(),
21106
+ // last4: this.card.getLast4(),
21107
+ // pin: this.card.getEncryptedPin(),
21108
+ // trans: this.id,
21109
+ // device: this.deviceFingerprint,
21110
+ // rememberCard: this.remember_card,
21111
+ // transactionType: this.transactionType,
21112
+ // subscription: this.subscription,
21113
+ // customFields,
21114
+ // };
21115
+ // return CardAPI.charge(chargeParams).then((response) => {
21116
+ // this.logAPIResponse(response, paymentMethod);
21117
+ // return response;
21118
+ // });
21119
+ // });
21120
+ // },
21121
+
21122
+ /**
21123
+ * Handles submitting a card pin after
21124
+ * other card details have been previously submitted.
21125
+ */
21126
+ // chargeCardWithPin(customFields = {}) {
21127
+ // this.logAttempt(paymentMethod);
21128
+ // const chargeParams = {
21129
+ // pin: encrypt(this.card.pin),
21130
+ // trans: this.id,
21131
+ // device: this.deviceFingerprint,
21132
+ // rememberCard: this.remember_card,
21133
+ // transactionType: this.transactionType,
21134
+ // subscription: this.subscription,
21135
+ // customFields,
21136
+ // };
21137
+ // return CardAPI.charge(chargeParams).then((response) => {
21138
+ // this.logAPIResponse(response, paymentMethod);
21139
+ // return response;
21140
+ // });
21141
+ // },
21142
+ // chargeRememberedCard({ cvv, authorizationCode, cardLast4, pin }) {
21143
+ // this.logAttempt(paymentMethod);
21144
+ // const encryptedPin = encrypt(pin);
21145
+ // const chargeParams = {
21146
+ // authorizationCode,
21147
+ // cvv,
21148
+ // last4: cardLast4,
21149
+ // trans: this.id,
21150
+ // device: this.deviceFingerprint,
21151
+ // pin: encryptedPin,
21152
+ // transactionType: this.transactionType,
21153
+ // subscription: this.subscription,
21154
+ // };
21155
+ // return CardAPI.chargeRememberedCard(chargeParams).then((response) => {
21156
+ // this.logAPIResponse(response, paymentMethod);
21157
+ // return response;
21158
+ // });
21159
+ // },
21160
+ // resumeCardCharge({ accessCode, pin }) {
21161
+ // const params = {
21162
+ // ...(pin && { pin: encrypt(pin) }),
21163
+ // accessCode,
21164
+ // device: this.deviceFingerprint,
21165
+ // };
21166
+ // return CardAPI.resumeCardCharge(params).then((response) => {
21167
+ // this.logAPIResponse(response, paymentMethod);
21168
+ // return response;
21169
+ // });
21170
+ // },
21171
+ // forgetRememberedCard(authorizationId) {
21172
+ // const params = {
21173
+ // authorizationId,
21174
+ // publicKey: this.merchant.key,
21175
+ // };
21176
+ // return CardAPI.forgetRememberedCard(params).then((response) => {
21177
+ // this.logAPIResponse(response, paymentMethod);
21178
+ // return response;
21179
+ // });
21180
+ // },
21181
+ // authenticateCard(token) {
21182
+ // return CardAPI.authenticate(this.id, token).then((response) => {
21183
+ // this.logAPIResponse(response, paymentMethod);
21184
+ // return response;
21185
+ // });
21186
+ // },
21187
+ // verifyAddress({ address, city, state, zipCode }) {
21188
+ // const payload = {
21189
+ // city,
21190
+ // state,
21191
+ // address,
21192
+ // zipCode,
21193
+ // transactionId: this.id,
21194
+ // };
21195
+ // return CardAPI.verifyAddress(payload).then((response) => {
21196
+ // this.logAPIResponse(response, paymentMethod);
21197
+ // return response;
21198
+ // });
21199
+ // },
21200
+
21201
+ };
21202
+
20464
21203
  var PreauthorizationInstance = /*#__PURE__*/function () {
20465
21204
  function PreauthorizationInstance(data) {
20466
21205
  _classCallCheck(this, PreauthorizationInstance);
@@ -20480,8 +21219,10 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20480
21219
  name: data.merchant_name,
20481
21220
  key: data.merchant_key
20482
21221
  };
20483
- loadPusher(); // TODO: Bind charge function to card channel
20484
- // https://paystack.atlassian.net/browse/RAILS-2887
21222
+ loadPusher(); // TODO: Analytics
21223
+ // https://paystack.atlassian.net/browse/RAILS-3070
21224
+
21225
+ Object.assign(this, ReserveCardFunds);
20485
21226
  }
20486
21227
 
20487
21228
  _createClass(PreauthorizationInstance, [{
@@ -20563,7 +21304,7 @@ var Preauthorization = {
20563
21304
  };
20564
21305
 
20565
21306
  exports.BankAccount = BankAccount;
20566
- exports.Card = Card;
21307
+ exports.Card = Card$1;
20567
21308
  exports.Preauthorization = Preauthorization;
20568
21309
  exports.Toolkit = Toolkit;
20569
21310
  exports.Transaction = Transaction;