@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/es/checkout.js CHANGED
@@ -6403,14 +6403,16 @@ var devConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6403
6403
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6404
6404
  paystackApiUrl: 'https://studio-api.paystack.co/',
6405
6405
  pusherKey: '1c7b262ee18455815893',
6406
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6406
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6407
+ savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6407
6408
  });
6408
6409
  var stagingConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6409
6410
  checkoutUrl: 'https://checkout-studio.paystack.com/',
6410
6411
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6411
6412
  paystackApiUrl: 'https://studio-api.paystack.co/',
6412
6413
  pusherKey: '1c7b262ee18455815893',
6413
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6414
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6415
+ savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6414
6416
  });
6415
6417
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6416
6418
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -11641,7 +11643,7 @@ var PayattitudeAPI = {
11641
11643
  }
11642
11644
  };
11643
11645
 
11644
- var paymentMethod$6 = 'payattitude';
11646
+ var paymentMethod$7 = 'payattitude';
11645
11647
  var PayattitudeCharge = {
11646
11648
  chargePayattitude: function chargePayattitude(_ref) {
11647
11649
  var _this = this;
@@ -11652,7 +11654,7 @@ var PayattitudeCharge = {
11652
11654
  phoneNumber: phoneNumber
11653
11655
  };
11654
11656
  return PayattitudeAPI.charge(params).then(function (response) {
11655
- _this.logAPIResponse(response, paymentMethod$6);
11657
+ _this.logAPIResponse(response, paymentMethod$7);
11656
11658
 
11657
11659
  return response;
11658
11660
  });
@@ -11660,7 +11662,7 @@ var PayattitudeCharge = {
11660
11662
  listenForPayattitudeCharge: function listenForPayattitudeCharge(callback) {
11661
11663
  var pusherChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
11662
11664
  var listenerOptions = {
11663
- paymentMethod: paymentMethod$6,
11665
+ paymentMethod: paymentMethod$7,
11664
11666
  channel: pusherChannel
11665
11667
  };
11666
11668
  return this.listenForCharge(listenerOptions, callback);
@@ -11743,7 +11745,7 @@ var ApplePayAPI = {
11743
11745
  }
11744
11746
  };
11745
11747
 
11746
- var paymentMethod$5 = 'apple pay';
11748
+ var paymentMethod$6 = 'apple pay';
11747
11749
  var ApplePayCharge = {
11748
11750
  validateApplePaySession: function validateApplePaySession(_ref) {
11749
11751
  var _this = this;
@@ -11751,7 +11753,7 @@ var ApplePayCharge = {
11751
11753
  var sessionUrl = _ref.sessionUrl,
11752
11754
  displayName = _ref.displayName,
11753
11755
  domainName = _ref.domainName;
11754
- this.logAttempt(paymentMethod$5);
11756
+ this.logAttempt(paymentMethod$6);
11755
11757
  return ApplePayAPI.validateApplePaySession({
11756
11758
  sessionUrl: sessionUrl,
11757
11759
  displayName: displayName,
@@ -11772,7 +11774,7 @@ var ApplePayCharge = {
11772
11774
  device: this.deviceFingerprint,
11773
11775
  paymentObject: paymentObject
11774
11776
  }).then(function (response) {
11775
- _this2.logAPIResponse(response, paymentMethod$5);
11777
+ _this2.logAPIResponse(response, paymentMethod$6);
11776
11778
 
11777
11779
  return response;
11778
11780
  });
@@ -11828,12 +11830,12 @@ var PayPalAPI = {
11828
11830
  }
11829
11831
  };
11830
11832
 
11831
- var paymentMethod$4 = 'paypal';
11833
+ var paymentMethod$5 = 'paypal';
11832
11834
  var PayPalCharge = {
11833
11835
  createPayPalOrder: function createPayPalOrder() {
11834
11836
  var _this = this;
11835
11837
 
11836
- this.logAttempt(paymentMethod$4);
11838
+ this.logAttempt(paymentMethod$5);
11837
11839
  return PayPalAPI.createOrder(this.id).then(function (response) {
11838
11840
  _this.logAPIResponseMessage(response.message);
11839
11841
 
@@ -11844,7 +11846,7 @@ var PayPalCharge = {
11844
11846
  var _this2 = this;
11845
11847
 
11846
11848
  return PayPalAPI.captureOrder(this.id).then(function (response) {
11847
- _this2.logAPIResponse(response, paymentMethod$4);
11849
+ _this2.logAPIResponse(response, paymentMethod$5);
11848
11850
 
11849
11851
  return response;
11850
11852
  });
@@ -17232,55 +17234,7 @@ function encrypt(toEncrypt) {
17232
17234
  return jsEncrypt.encrypt(toEncrypt);
17233
17235
  }
17234
17236
 
17235
- var DESCRIPTORS = descriptors;
17236
- var uncurryThis$1 = functionUncurryThis;
17237
- var objectKeys = objectKeys$3;
17238
- var toIndexedObject = toIndexedObject$8;
17239
- var $propertyIsEnumerable = objectPropertyIsEnumerable.f;
17240
-
17241
- var propertyIsEnumerable = uncurryThis$1($propertyIsEnumerable);
17242
- var push = uncurryThis$1([].push);
17243
-
17244
- // `Object.{ entries, values }` methods implementation
17245
- var createMethod = function (TO_ENTRIES) {
17246
- return function (it) {
17247
- var O = toIndexedObject(it);
17248
- var keys = objectKeys(O);
17249
- var length = keys.length;
17250
- var i = 0;
17251
- var result = [];
17252
- var key;
17253
- while (length > i) {
17254
- key = keys[i++];
17255
- if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
17256
- push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
17257
- }
17258
- }
17259
- return result;
17260
- };
17261
- };
17262
-
17263
- var objectToArray = {
17264
- // `Object.entries` method
17265
- // https://tc39.es/ecma262/#sec-object.entries
17266
- entries: createMethod(true),
17267
- // `Object.values` method
17268
- // https://tc39.es/ecma262/#sec-object.values
17269
- values: createMethod(false)
17270
- };
17271
-
17272
17237
  var $$2 = _export;
17273
- var $values = objectToArray.values;
17274
-
17275
- // `Object.values` method
17276
- // https://tc39.es/ecma262/#sec-object.values
17277
- $$2({ target: 'Object', stat: true }, {
17278
- values: function values(O) {
17279
- return $values(O);
17280
- }
17281
- });
17282
-
17283
- var $$1 = _export;
17284
17238
  var $find = arrayIteration.find;
17285
17239
  var addToUnscopables = addToUnscopables$3;
17286
17240
 
@@ -17292,7 +17246,7 @@ if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
17292
17246
 
17293
17247
  // `Array.prototype.find` method
17294
17248
  // https://tc39.es/ecma262/#sec-array.prototype.find
17295
- $$1({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
17249
+ $$2({ target: 'Array', proto: true, forced: SKIPS_HOLES }, {
17296
17250
  find: function find(callbackfn /* , that = undefined */) {
17297
17251
  return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
17298
17252
  }
@@ -18240,6 +18194,137 @@ var cardValidator = {
18240
18194
  creditCardType: creditCardType_1
18241
18195
  };
18242
18196
 
18197
+ var DESCRIPTORS = descriptors;
18198
+ var uncurryThis$1 = functionUncurryThis;
18199
+ var objectKeys = objectKeys$3;
18200
+ var toIndexedObject = toIndexedObject$8;
18201
+ var $propertyIsEnumerable = objectPropertyIsEnumerable.f;
18202
+
18203
+ var propertyIsEnumerable = uncurryThis$1($propertyIsEnumerable);
18204
+ var push = uncurryThis$1([].push);
18205
+
18206
+ // `Object.{ entries, values }` methods implementation
18207
+ var createMethod = function (TO_ENTRIES) {
18208
+ return function (it) {
18209
+ var O = toIndexedObject(it);
18210
+ var keys = objectKeys(O);
18211
+ var length = keys.length;
18212
+ var i = 0;
18213
+ var result = [];
18214
+ var key;
18215
+ while (length > i) {
18216
+ key = keys[i++];
18217
+ if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
18218
+ push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
18219
+ }
18220
+ }
18221
+ return result;
18222
+ };
18223
+ };
18224
+
18225
+ var objectToArray = {
18226
+ // `Object.entries` method
18227
+ // https://tc39.es/ecma262/#sec-object.entries
18228
+ entries: createMethod(true),
18229
+ // `Object.values` method
18230
+ // https://tc39.es/ecma262/#sec-object.values
18231
+ values: createMethod(false)
18232
+ };
18233
+
18234
+ var $$1 = _export;
18235
+ var $values = objectToArray.values;
18236
+
18237
+ // `Object.values` method
18238
+ // https://tc39.es/ecma262/#sec-object.values
18239
+ $$1({ target: 'Object', stat: true }, {
18240
+ values: function values(O) {
18241
+ return $values(O);
18242
+ }
18243
+ });
18244
+
18245
+ var Card$2 = {
18246
+ getEncryptedPin: function getEncryptedPin(pin) {
18247
+ return pin ? encrypt(pin) : undefined;
18248
+ },
18249
+ getLast4: function getLast4(number) {
18250
+ return number.substring(number.length - 4);
18251
+ },
18252
+ tokenize: function tokenize(_ref) {
18253
+ var number = _ref.number,
18254
+ cvv = _ref.cvv,
18255
+ month = _ref.month,
18256
+ year = _ref.year;
18257
+ return encrypt("".concat(number, "*").concat(cvv, "*").concat(month, "*").concat(year));
18258
+ },
18259
+ getType: function getType(value) {
18260
+ var response = cardValidator.number(value);
18261
+
18262
+ if (response && response.card) {
18263
+ return {
18264
+ type: response.card.type,
18265
+ maxLength: Math.max.apply(Math, _toConsumableArray(response.card.lengths)),
18266
+ minLength: Math.min.apply(Math, _toConsumableArray(response.card.lengths))
18267
+ };
18268
+ }
18269
+
18270
+ return {
18271
+ type: null,
18272
+ maxLength: 0
18273
+ };
18274
+ },
18275
+ validate: function validate(_ref2) {
18276
+ var number = _ref2.number,
18277
+ cvv = _ref2.cvv,
18278
+ month = _ref2.month,
18279
+ year = _ref2.year;
18280
+
18281
+ var _this$getType = this.getType(number),
18282
+ cardType = _this$getType.type;
18283
+
18284
+ var result = {
18285
+ number: this.isNumberValid(number),
18286
+ expiry: this.isExpiryValid({
18287
+ month: month,
18288
+ year: year
18289
+ }),
18290
+ cvv: this.isCvvValid(cvv, cardType)
18291
+ };
18292
+ var isValid = Object.values(result).every(function (value) {
18293
+ return value === true;
18294
+ });
18295
+ return {
18296
+ isValid: isValid,
18297
+ result: result
18298
+ };
18299
+ },
18300
+ validateNumber: function validateNumber(value) {
18301
+ return cardValidator.number(value);
18302
+ },
18303
+ isNumberValid: function isNumberValid(value) {
18304
+ return Card$2.validateNumber(value).isValid;
18305
+ },
18306
+ validateCVV: function validateCVV(cvv, cardType) {
18307
+ var isAmexCard = cardType === 'american-express';
18308
+ var cvvLength = isAmexCard ? 4 : 3;
18309
+ return cardValidator.cvv(cvv, cvvLength);
18310
+ },
18311
+ isCvvValid: function isCvvValid(cvv, cardType) {
18312
+ return Card$2.validateCVV(cvv, cardType).isValid;
18313
+ },
18314
+ validateExpiry: function validateExpiry(value) {
18315
+ if (_typeof$1(value) === 'object') {
18316
+ var month = value.month,
18317
+ year = value.year;
18318
+ return cardValidator.expirationMonth(month) && cardValidator.expirationYear(year);
18319
+ }
18320
+
18321
+ return cardValidator.expirationDate(value);
18322
+ },
18323
+ isExpiryValid: function isExpiryValid(value) {
18324
+ return Card$2.validateExpiry(value).isValid;
18325
+ }
18326
+ };
18327
+
18243
18328
  var testCards = [{
18244
18329
  type: 'bank_auth',
18245
18330
  name: 'Bank authorization',
@@ -18304,7 +18389,7 @@ cardValidator.creditCardType.addCard({
18304
18389
  });
18305
18390
  cardValidator.creditCardType.changeOrder('verve', 0);
18306
18391
 
18307
- var Card = /*#__PURE__*/function () {
18392
+ var Card$1 = /*#__PURE__*/function () {
18308
18393
  function Card(_ref) {
18309
18394
  var number = _ref.number,
18310
18395
  cvv = _ref.cvv,
@@ -18324,35 +18409,27 @@ var Card = /*#__PURE__*/function () {
18324
18409
  _createClass(Card, [{
18325
18410
  key: "getEncryptedPin",
18326
18411
  value: function getEncryptedPin() {
18327
- return this.pin ? encrypt(this.pin) : undefined;
18412
+ return Card$2.getEncryptedPin(this.pin);
18328
18413
  }
18329
18414
  }, {
18330
18415
  key: "getLast4",
18331
18416
  value: function getLast4() {
18332
- return this.number.substring(this.number.length - 4);
18417
+ return Card$2.getLast4(this.number);
18333
18418
  }
18334
18419
  }, {
18335
18420
  key: "tokenize",
18336
18421
  value: function tokenize() {
18337
- return encrypt("".concat(this.number, "*").concat(this.cvv, "*").concat(this.month, "*").concat(this.year));
18422
+ return Card$2.tokenize({
18423
+ number: this.number,
18424
+ cvv: this.cvv,
18425
+ month: this.month,
18426
+ year: this.year
18427
+ });
18338
18428
  }
18339
18429
  }], [{
18340
18430
  key: "getType",
18341
18431
  value: function getType(value) {
18342
- var response = cardValidator.number(value);
18343
-
18344
- if (response && response.card) {
18345
- return {
18346
- type: response.card.type,
18347
- maxLength: Math.max.apply(Math, _toConsumableArray(response.card.lengths)),
18348
- minLength: Math.min.apply(Math, _toConsumableArray(response.card.lengths))
18349
- };
18350
- }
18351
-
18352
- return {
18353
- type: null,
18354
- maxLength: 0
18355
- };
18432
+ return Card$2.getType(value);
18356
18433
  }
18357
18434
  }, {
18358
18435
  key: "validate",
@@ -18361,63 +18438,42 @@ var Card = /*#__PURE__*/function () {
18361
18438
  cvv = _ref2.cvv,
18362
18439
  month = _ref2.month,
18363
18440
  year = _ref2.year;
18364
-
18365
- var _Card$getType = Card.getType(number),
18366
- cardType = _Card$getType.type;
18367
-
18368
- var result = {
18369
- number: Card.isNumberValid(number),
18370
- expiry: Card.isExpiryValid({
18371
- month: month,
18372
- year: year
18373
- }),
18374
- cvv: Card.isCvvValid(cvv, cardType)
18375
- };
18376
- var isValid = Object.values(result).every(function (value) {
18377
- return value === true;
18441
+ return Card$2.validate({
18442
+ number: number,
18443
+ cvv: cvv,
18444
+ month: month,
18445
+ year: year
18378
18446
  });
18379
- return {
18380
- isValid: isValid,
18381
- result: result
18382
- };
18383
18447
  }
18384
18448
  }, {
18385
18449
  key: "validateNumber",
18386
18450
  value: function validateNumber(value) {
18387
- return cardValidator.number(value);
18451
+ return Card$2.validateNumber(value);
18388
18452
  }
18389
18453
  }, {
18390
18454
  key: "isNumberValid",
18391
18455
  value: function isNumberValid(value) {
18392
- return Card.validateNumber(value).isValid;
18456
+ return Card$2.isNumberValid(value);
18393
18457
  }
18394
18458
  }, {
18395
18459
  key: "validateCVV",
18396
18460
  value: function validateCVV(cvv, cardType) {
18397
- var isAmexCard = cardType === 'american-express';
18398
- var cvvLength = isAmexCard ? 4 : 3;
18399
- return cardValidator.cvv(cvv, cvvLength);
18461
+ return Card$2.validateCVV(cvv, cardType);
18400
18462
  }
18401
18463
  }, {
18402
18464
  key: "isCvvValid",
18403
18465
  value: function isCvvValid(cvv, cardType) {
18404
- return Card.validateCVV(cvv, cardType).isValid;
18466
+ return Card$2.isCvvValid(cvv, cardType);
18405
18467
  }
18406
18468
  }, {
18407
18469
  key: "validateExpiry",
18408
18470
  value: function validateExpiry(value) {
18409
- if (_typeof$1(value) === 'object') {
18410
- var month = value.month,
18411
- year = value.year;
18412
- return cardValidator.expirationMonth(month) && cardValidator.expirationYear(year);
18413
- }
18414
-
18415
- return cardValidator.expirationDate(value);
18471
+ return Card$2.validateExpiry(value);
18416
18472
  }
18417
18473
  }, {
18418
18474
  key: "isExpiryValid",
18419
18475
  value: function isExpiryValid(value) {
18420
- return Card.validateExpiry(value).isValid;
18476
+ return Card$2.isExpiryValid(value);
18421
18477
  }
18422
18478
  }, {
18423
18479
  key: "generateTestCard",
@@ -18433,7 +18489,7 @@ var Card = /*#__PURE__*/function () {
18433
18489
  return Card;
18434
18490
  }();
18435
18491
 
18436
- var CardAPI = {
18492
+ var CardAPI$1 = {
18437
18493
  charge: function charge(_ref) {
18438
18494
  var clientdata = _ref.clientdata,
18439
18495
  last4 = _ref.last4,
@@ -18609,14 +18665,215 @@ var CardAPI = {
18609
18665
  }).then(function (response) {
18610
18666
  return ChargeResponses.parse(response.data);
18611
18667
  });
18668
+ },
18669
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
18670
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18671
+ var url, language, headers, _yield$axiosInstance$, data;
18672
+
18673
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18674
+ while (1) {
18675
+ switch (_context.prev = _context.next) {
18676
+ case 0:
18677
+ url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18678
+ language = getLanguage();
18679
+ headers = _objectSpread2({}, language && {
18680
+ 'Accept-Language': language
18681
+ });
18682
+ _context.next = 5;
18683
+ return axiosInstance.post(url, {
18684
+ headers: headers
18685
+ });
18686
+
18687
+ case 5:
18688
+ _yield$axiosInstance$ = _context.sent;
18689
+ data = _yield$axiosInstance$.data;
18690
+ return _context.abrupt("return", data);
18691
+
18692
+ case 8:
18693
+ case "end":
18694
+ return _context.stop();
18695
+ }
18696
+ }
18697
+ }, _callee);
18698
+ }))();
18699
+ },
18700
+ addUserToSavedCards: function addUserToSavedCards(_ref6) {
18701
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18702
+ var phone, email, url, language, headers, data, response;
18703
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18704
+ while (1) {
18705
+ switch (_context2.prev = _context2.next) {
18706
+ case 0:
18707
+ phone = _ref6.phone, email = _ref6.email;
18708
+ url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18709
+ language = getLanguage();
18710
+ headers = _objectSpread2({}, language && {
18711
+ 'Accept-Language': language
18712
+ });
18713
+ data = {
18714
+ phone: phone,
18715
+ email: email
18716
+ };
18717
+ _context2.next = 7;
18718
+ return axiosInstance.post(url, data, {
18719
+ headers: headers
18720
+ });
18721
+
18722
+ case 7:
18723
+ response = _context2.sent;
18724
+ return _context2.abrupt("return", response.data);
18725
+
18726
+ case 9:
18727
+ case "end":
18728
+ return _context2.stop();
18729
+ }
18730
+ }
18731
+ }, _callee2);
18732
+ }))();
18733
+ },
18734
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18735
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18736
+ var code, phone, transaction, url, language, headers, data, response;
18737
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18738
+ while (1) {
18739
+ switch (_context3.prev = _context3.next) {
18740
+ case 0:
18741
+ code = _ref7.code, phone = _ref7.phone, transaction = _ref7.transaction;
18742
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18743
+ language = getLanguage();
18744
+ headers = _objectSpread2({}, language && {
18745
+ 'Accept-Language': language
18746
+ });
18747
+ data = {
18748
+ code: code,
18749
+ phone: phone,
18750
+ transaction: transaction
18751
+ };
18752
+ _context3.next = 7;
18753
+ return axiosInstance.post(url, data, {
18754
+ headers: headers
18755
+ });
18756
+
18757
+ case 7:
18758
+ response = _context3.sent;
18759
+ return _context3.abrupt("return", response.data);
18760
+
18761
+ case 9:
18762
+ case "end":
18763
+ return _context3.stop();
18764
+ }
18765
+ }
18766
+ }, _callee3);
18767
+ }))();
18768
+ },
18769
+ getSavedCards: function getSavedCards(_ref8) {
18770
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18771
+ var token, url, language, headers, response;
18772
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18773
+ while (1) {
18774
+ switch (_context4.prev = _context4.next) {
18775
+ case 0:
18776
+ token = _ref8.token;
18777
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18778
+ language = getLanguage();
18779
+ headers = _objectSpread2({
18780
+ Authorization: "Bearer ".concat(token),
18781
+ 'jwt-auth': true
18782
+ }, language && {
18783
+ 'Accept-Language': language
18784
+ });
18785
+ _context4.next = 6;
18786
+ return axiosInstance.get(url, {
18787
+ headers: headers
18788
+ });
18789
+
18790
+ case 6:
18791
+ response = _context4.sent;
18792
+ return _context4.abrupt("return", response.data);
18793
+
18794
+ case 8:
18795
+ case "end":
18796
+ return _context4.stop();
18797
+ }
18798
+ }
18799
+ }, _callee4);
18800
+ }))();
18801
+ },
18802
+ deleteSavedCard: function deleteSavedCard(_ref9) {
18803
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18804
+ var cardCode, token, url, language, headers, response;
18805
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18806
+ while (1) {
18807
+ switch (_context5.prev = _context5.next) {
18808
+ case 0:
18809
+ cardCode = _ref9.cardCode, token = _ref9.token;
18810
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18811
+ language = getLanguage();
18812
+ headers = _objectSpread2({
18813
+ Authorization: "Bearer ".concat(token),
18814
+ 'jwt-auth': true
18815
+ }, language && {
18816
+ 'Accept-Language': language
18817
+ });
18818
+ _context5.next = 6;
18819
+ return axiosInstance.delete(url, {
18820
+ headers: headers
18821
+ });
18822
+
18823
+ case 6:
18824
+ response = _context5.sent;
18825
+ return _context5.abrupt("return", response.data);
18826
+
18827
+ case 8:
18828
+ case "end":
18829
+ return _context5.stop();
18830
+ }
18831
+ }
18832
+ }, _callee5);
18833
+ }))();
18834
+ },
18835
+ chargeSavedCard: function chargeSavedCard(_ref10) {
18836
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18837
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18838
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
18839
+ while (1) {
18840
+ switch (_context6.prev = _context6.next) {
18841
+ case 0:
18842
+ token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18843
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18844
+ language = getLanguage();
18845
+ headers = _objectSpread2({
18846
+ Authorization: "Bearer ".concat(token),
18847
+ 'jwt-auth': true
18848
+ }, language && {
18849
+ 'Accept-Language': language
18850
+ });
18851
+ data = {
18852
+ device: device,
18853
+ transaction: transaction,
18854
+ selectedCurrency: selectedCurrency
18855
+ };
18856
+ return _context6.abrupt("return", axiosInstance.post(url, data, {
18857
+ headers: headers
18858
+ }).then(function (response) {
18859
+ return ChargeResponses.parse(response.data);
18860
+ }));
18861
+
18862
+ case 6:
18863
+ case "end":
18864
+ return _context6.stop();
18865
+ }
18866
+ }
18867
+ }, _callee6);
18868
+ }))();
18612
18869
  }
18613
18870
  };
18614
18871
 
18615
- var paymentMethod$3 = 'card';
18872
+ var paymentMethod$4 = 'card';
18616
18873
 
18617
- function validate$3(card, isSetter) {
18874
+ function validate$4(card, isSetter) {
18618
18875
  return new Promise(function (resolve, reject) {
18619
- var validation = Card.validate(card);
18876
+ var validation = Card$1.validate(card);
18620
18877
 
18621
18878
  if (!validation.isValid) {
18622
18879
  var throwValidation = isSetter || card.number;
@@ -18635,8 +18892,8 @@ var CardCharge = {
18635
18892
  setCard: function setCard(params) {
18636
18893
  var _this = this;
18637
18894
 
18638
- return validate$3(params, true).then(function () {
18639
- _this.card = new Card(params);
18895
+ return validate$4(params, true).then(function () {
18896
+ _this.card = new Card$1(params);
18640
18897
  });
18641
18898
  },
18642
18899
  rememberCard: function rememberCard() {
@@ -18651,8 +18908,8 @@ var CardCharge = {
18651
18908
  return this.chargeCardWithPin(customFields);
18652
18909
  }
18653
18910
 
18654
- return validate$3(this.card).then(function () {
18655
- _this2.logAttempt(paymentMethod$3);
18911
+ return validate$4(this.card).then(function () {
18912
+ _this2.logAttempt(paymentMethod$4);
18656
18913
 
18657
18914
  var chargeParams = {
18658
18915
  clientdata: _this2.card.tokenize(),
@@ -18665,8 +18922,8 @@ var CardCharge = {
18665
18922
  subscription: _this2.subscription,
18666
18923
  customFields: customFields
18667
18924
  };
18668
- return CardAPI.charge(chargeParams).then(function (response) {
18669
- _this2.logAPIResponse(response, paymentMethod$3);
18925
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18926
+ _this2.logAPIResponse(response, paymentMethod$4);
18670
18927
 
18671
18928
  return response;
18672
18929
  });
@@ -18681,7 +18938,7 @@ var CardCharge = {
18681
18938
  var _this3 = this;
18682
18939
 
18683
18940
  var customFields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18684
- this.logAttempt(paymentMethod$3);
18941
+ this.logAttempt(paymentMethod$4);
18685
18942
  var chargeParams = {
18686
18943
  pin: encrypt(this.card.pin),
18687
18944
  trans: this.id,
@@ -18691,8 +18948,8 @@ var CardCharge = {
18691
18948
  subscription: this.subscription,
18692
18949
  customFields: customFields
18693
18950
  };
18694
- return CardAPI.charge(chargeParams).then(function (response) {
18695
- _this3.logAPIResponse(response, paymentMethod$3);
18951
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18952
+ _this3.logAPIResponse(response, paymentMethod$4);
18696
18953
 
18697
18954
  return response;
18698
18955
  });
@@ -18704,7 +18961,7 @@ var CardCharge = {
18704
18961
  authorizationCode = _ref.authorizationCode,
18705
18962
  cardLast4 = _ref.cardLast4,
18706
18963
  pin = _ref.pin;
18707
- this.logAttempt(paymentMethod$3);
18964
+ this.logAttempt(paymentMethod$4);
18708
18965
  var encryptedPin = encrypt(pin);
18709
18966
  var chargeParams = {
18710
18967
  authorizationCode: authorizationCode,
@@ -18716,8 +18973,8 @@ var CardCharge = {
18716
18973
  transactionType: this.transactionType,
18717
18974
  subscription: this.subscription
18718
18975
  };
18719
- return CardAPI.chargeRememberedCard(chargeParams).then(function (response) {
18720
- _this4.logAPIResponse(response, paymentMethod$3);
18976
+ return CardAPI$1.chargeRememberedCard(chargeParams).then(function (response) {
18977
+ _this4.logAPIResponse(response, paymentMethod$4);
18721
18978
 
18722
18979
  return response;
18723
18980
  });
@@ -18735,8 +18992,8 @@ var CardCharge = {
18735
18992
  device: this.deviceFingerprint
18736
18993
  });
18737
18994
 
18738
- return CardAPI.resumeCardCharge(params).then(function (response) {
18739
- _this5.logAPIResponse(response, paymentMethod$3);
18995
+ return CardAPI$1.resumeCardCharge(params).then(function (response) {
18996
+ _this5.logAPIResponse(response, paymentMethod$4);
18740
18997
 
18741
18998
  return response;
18742
18999
  });
@@ -18748,8 +19005,8 @@ var CardCharge = {
18748
19005
  authorizationId: authorizationId,
18749
19006
  publicKey: this.merchant.key
18750
19007
  };
18751
- return CardAPI.forgetRememberedCard(params).then(function (response) {
18752
- _this6.logAPIResponse(response, paymentMethod$3);
19008
+ return CardAPI$1.forgetRememberedCard(params).then(function (response) {
19009
+ _this6.logAPIResponse(response, paymentMethod$4);
18753
19010
 
18754
19011
  return response;
18755
19012
  });
@@ -18757,8 +19014,8 @@ var CardCharge = {
18757
19014
  authenticateCard: function authenticateCard(token) {
18758
19015
  var _this7 = this;
18759
19016
 
18760
- return CardAPI.authenticate(this.id, token).then(function (response) {
18761
- _this7.logAPIResponse(response, paymentMethod$3);
19017
+ return CardAPI$1.authenticate(this.id, token).then(function (response) {
19018
+ _this7.logAPIResponse(response, paymentMethod$4);
18762
19019
 
18763
19020
  return response;
18764
19021
  });
@@ -18777,8 +19034,8 @@ var CardCharge = {
18777
19034
  zipCode: zipCode,
18778
19035
  transactionId: this.id
18779
19036
  };
18780
- return CardAPI.verifyAddress(payload).then(function (response) {
18781
- _this8.logAPIResponse(response, paymentMethod$3);
19037
+ return CardAPI$1.verifyAddress(payload).then(function (response) {
19038
+ _this8.logAPIResponse(response, paymentMethod$4);
18782
19039
 
18783
19040
  return response;
18784
19041
  });
@@ -18786,9 +19043,78 @@ var CardCharge = {
18786
19043
  listenFor3DSCharge: function listenFor3DSCharge(callback) {
18787
19044
  var listenerOptions = {
18788
19045
  channel: "3DS_".concat(this.id),
18789
- paymentMethod: paymentMethod$3
19046
+ paymentMethod: paymentMethod$4
18790
19047
  };
18791
19048
  return this.listenForCharge(listenerOptions, callback);
19049
+ },
19050
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
19051
+ return CardAPI$1.requestSavedCardsOTP(phoneNumber);
19052
+ },
19053
+ addUserToSavedCards: function addUserToSavedCards(_ref4) {
19054
+ var phone = _ref4.phone;
19055
+ return CardAPI$1.addUserToSavedCards({
19056
+ phone: phone,
19057
+ email: this.email
19058
+ });
19059
+ },
19060
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19061
+ var _this9 = this;
19062
+
19063
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19064
+ var code, phone, payload, response;
19065
+ return regeneratorRuntime.wrap(function _callee$(_context) {
19066
+ while (1) {
19067
+ switch (_context.prev = _context.next) {
19068
+ case 0:
19069
+ code = _ref5.code, phone = _ref5.phone;
19070
+ payload = {
19071
+ code: code,
19072
+ phone: phone,
19073
+ transaction: _this9.id
19074
+ };
19075
+ _context.prev = 2;
19076
+ _context.next = 5;
19077
+ return CardAPI$1.verifySavedCardsOtp(payload);
19078
+
19079
+ case 5:
19080
+ response = _context.sent;
19081
+ _this9.savedCardsToken = response.data.token;
19082
+ return _context.abrupt("return", response);
19083
+
19084
+ case 10:
19085
+ _context.prev = 10;
19086
+ _context.t0 = _context["catch"](2);
19087
+ _this9.savedCardsToken = null;
19088
+ throw _context.t0;
19089
+
19090
+ case 14:
19091
+ case "end":
19092
+ return _context.stop();
19093
+ }
19094
+ }
19095
+ }, _callee, null, [[2, 10]]);
19096
+ }))();
19097
+ },
19098
+ getSavedCards: function getSavedCards() {
19099
+ return CardAPI$1.getSavedCards({
19100
+ token: this.savedCardsToken
19101
+ });
19102
+ },
19103
+ deleteSavedCard: function deleteSavedCard(cardCode) {
19104
+ return CardAPI$1.deleteSavedCard({
19105
+ cardCode: cardCode,
19106
+ token: this.savedCardsToken
19107
+ });
19108
+ },
19109
+ chargeSavedCard: function chargeSavedCard(_ref6) {
19110
+ var cardCode = _ref6.cardCode;
19111
+ return CardAPI$1.chargeSavedCard({
19112
+ cardCode: cardCode,
19113
+ transaction: this.id,
19114
+ token: this.savedCardsToken,
19115
+ device: this.deviceFingerprint,
19116
+ selectedCurrency: this.currency
19117
+ });
18792
19118
  }
18793
19119
  };
18794
19120
 
@@ -18941,9 +19267,9 @@ var EMandateAPI = {
18941
19267
  }
18942
19268
  };
18943
19269
 
18944
- var paymentMethod$2 = 'bank account';
19270
+ var paymentMethod$3 = 'bank account';
18945
19271
 
18946
- function validate$2(bankAccount, isSetter) {
19272
+ function validate$3(bankAccount, isSetter) {
18947
19273
  return new Promise(function (resolve, reject) {
18948
19274
  var validation = BankAccount.validate(bankAccount);
18949
19275
 
@@ -18961,15 +19287,15 @@ var EMandate = {
18961
19287
  setBankAccount: function setBankAccount(params) {
18962
19288
  var _this = this;
18963
19289
 
18964
- return validate$2(params, true).then(function () {
19290
+ return validate$3(params, true).then(function () {
18965
19291
  _this.bankAccount = new BankAccount(params);
18966
19292
  });
18967
19293
  },
18968
19294
  chargeBankAccount: function chargeBankAccount() {
18969
19295
  var _this2 = this;
18970
19296
 
18971
- return validate$2(this.bankAccount).then(function () {
18972
- _this2.logAttempt(paymentMethod$2);
19297
+ return validate$3(this.bankAccount).then(function () {
19298
+ _this2.logAttempt(paymentMethod$3);
18973
19299
 
18974
19300
  var verifyParams = {
18975
19301
  bankId: _this2.bankAccount.bankId,
@@ -18978,7 +19304,7 @@ var EMandate = {
18978
19304
  device: _this2.deviceFingerprint
18979
19305
  };
18980
19306
  return EMandateAPI.verify(verifyParams).then(function (response) {
18981
- _this2.logAPIResponse(response, paymentMethod$2);
19307
+ _this2.logAPIResponse(response, paymentMethod$3);
18982
19308
 
18983
19309
  return response;
18984
19310
  });
@@ -18987,7 +19313,7 @@ var EMandate = {
18987
19313
  registerBankAccount: function registerBankAccount(birthday) {
18988
19314
  var _this3 = this;
18989
19315
 
18990
- return validate$2(this.bankAccount).then(function () {
19316
+ return validate$3(this.bankAccount).then(function () {
18991
19317
  var registerParams = {
18992
19318
  bankId: _this3.bankAccount.bankId,
18993
19319
  transactionId: _this3.id,
@@ -18995,7 +19321,7 @@ var EMandate = {
18995
19321
  birthday: birthday
18996
19322
  };
18997
19323
  return EMandateAPI.register(registerParams).then(function (response) {
18998
- _this3.logAPIResponse(response, paymentMethod$2);
19324
+ _this3.logAPIResponse(response, paymentMethod$3);
18999
19325
 
19000
19326
  return response;
19001
19327
  });
@@ -19004,7 +19330,7 @@ var EMandate = {
19004
19330
  authenticateBankAccount: function authenticateBankAccount(token) {
19005
19331
  var _this4 = this;
19006
19332
 
19007
- return validate$2(this.bankAccount).then(function () {
19333
+ return validate$3(this.bankAccount).then(function () {
19008
19334
  var chargeParams = {
19009
19335
  bankId: _this4.bankAccount.bankId,
19010
19336
  transactionId: _this4.id,
@@ -19012,7 +19338,7 @@ var EMandate = {
19012
19338
  device: _this4.deviceFingerprint
19013
19339
  };
19014
19340
  return EMandateAPI.authenticate(chargeParams).then(function (response) {
19015
- _this4.logAPIResponse(response, paymentMethod$2);
19341
+ _this4.logAPIResponse(response, paymentMethod$3);
19016
19342
 
19017
19343
  return response;
19018
19344
  });
@@ -19073,7 +19399,7 @@ var DigitalBankMandateAPI = {
19073
19399
  }
19074
19400
  };
19075
19401
 
19076
- var paymentMethod$1 = 'bank';
19402
+ var paymentMethod$2 = 'bank';
19077
19403
  var DigitalBankMandate = {
19078
19404
  chargeDigitalBankMandate: function chargeDigitalBankMandate(_ref) {
19079
19405
  var _this = this;
@@ -19088,7 +19414,7 @@ var DigitalBankMandate = {
19088
19414
  bankId: bankId
19089
19415
  };
19090
19416
  return DigitalBankMandateAPI.charge(params).then(function (response) {
19091
- _this.logAPIResponse(response, paymentMethod$1);
19417
+ _this.logAPIResponse(response, paymentMethod$2);
19092
19418
 
19093
19419
  return response;
19094
19420
  });
@@ -19096,7 +19422,7 @@ var DigitalBankMandate = {
19096
19422
  listenForDigitalBankMandateCharge: function listenForDigitalBankMandateCharge(callback) {
19097
19423
  var pusherChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
19098
19424
  var listenerOptions = {
19099
- paymentMethod: paymentMethod$1,
19425
+ paymentMethod: paymentMethod$2,
19100
19426
  channel: pusherChannel
19101
19427
  };
19102
19428
  return this.listenForCharge(listenerOptions, callback);
@@ -19229,7 +19555,7 @@ var QrAPI = {
19229
19555
  }
19230
19556
  };
19231
19557
 
19232
- function validate$1(channel) {
19558
+ function validate$2(channel) {
19233
19559
  return new Promise(function (resolve, reject) {
19234
19560
  var allowedChannels = ['visa', 'MPASS_OLTI'];
19235
19561
 
@@ -19247,7 +19573,7 @@ var QRCharge = {
19247
19573
  var _this = this;
19248
19574
 
19249
19575
  var channel = _ref.channel;
19250
- return validate$1(channel).then(function () {
19576
+ return validate$2(channel).then(function () {
19251
19577
  if (_this.qr[channel]) {
19252
19578
  return _this.qr[channel];
19253
19579
  }
@@ -19269,7 +19595,7 @@ var QRCharge = {
19269
19595
  var _this2 = this;
19270
19596
 
19271
19597
  var channel = _ref2.channel;
19272
- return validate$1(channel).then(function () {
19598
+ return validate$2(channel).then(function () {
19273
19599
  if (!_this2.qr[channel]) {
19274
19600
  return Promise.reject(Error('Please generate qr code with Transaction.getQRCode()'));
19275
19601
  }
@@ -19390,7 +19716,7 @@ var MobileMoneyAPI = {
19390
19716
  }
19391
19717
  };
19392
19718
 
19393
- function validate(phoneNumber) {
19719
+ function validate$1(phoneNumber) {
19394
19720
  return new Promise(function (resolve, reject) {
19395
19721
  var validation = PhoneNumber.validate(phoneNumber);
19396
19722
 
@@ -19411,7 +19737,7 @@ var MobileMoneyCharge = {
19411
19737
  provider = _ref.provider,
19412
19738
  voucher = _ref.voucher,
19413
19739
  registrationToken = _ref.registrationToken;
19414
- return validate(phoneNumber).then(function () {
19740
+ return validate$1(phoneNumber).then(function () {
19415
19741
  _this.logAttempt('mobile money');
19416
19742
 
19417
19743
  var params = {
@@ -19442,7 +19768,7 @@ var MobileMoneyCharge = {
19442
19768
  var phoneNumber = payload.phoneNumber,
19443
19769
  provider = payload.provider,
19444
19770
  registrationToken = payload.registrationToken;
19445
- return validate(phoneNumber).then(function () {
19771
+ return validate$1(phoneNumber).then(function () {
19446
19772
  _this2.logMobileMoneyActions(payload);
19447
19773
 
19448
19774
  var params = {
@@ -19582,7 +19908,7 @@ var DirectDebitAPI = {
19582
19908
  }
19583
19909
  };
19584
19910
 
19585
- var paymentMethod = 'direct debit';
19911
+ var paymentMethod$1 = 'direct debit';
19586
19912
  var DirectDebitCharge = {
19587
19913
  loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
19588
19914
  var _this = this;
@@ -19628,14 +19954,14 @@ var DirectDebitCharge = {
19628
19954
  return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
19629
19955
  }
19630
19956
 
19631
- this.logAttempt(paymentMethod);
19957
+ this.logAttempt(paymentMethod$1);
19632
19958
  var params = {
19633
19959
  account_code: accountCode,
19634
19960
  transaction: this.id,
19635
19961
  token: this.directDebit.token
19636
19962
  };
19637
19963
  return DirectDebitAPI.charge(params).then(function (response) {
19638
- _this2.logAPIResponse(response, paymentMethod);
19964
+ _this2.logAPIResponse(response, paymentMethod$1);
19639
19965
 
19640
19966
  if (response.status) {
19641
19967
  _this2.directDebit.chargeResponse = response;
@@ -19648,7 +19974,7 @@ var DirectDebitCharge = {
19648
19974
  var _this3 = this;
19649
19975
 
19650
19976
  return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
19651
- _this3.logAPIResponse(response, paymentMethod);
19977
+ _this3.logAPIResponse(response, paymentMethod$1);
19652
19978
 
19653
19979
  var status = response.status,
19654
19980
  data = response.data;
@@ -19673,7 +19999,7 @@ var DirectDebitCharge = {
19673
19999
  token: this.directDebit.token
19674
20000
  };
19675
20001
  return DirectDebitAPI.authenticate(params).then(function (response) {
19676
- _this4.logAPIResponse(response, paymentMethod);
20002
+ _this4.logAPIResponse(response, paymentMethod$1);
19677
20003
 
19678
20004
  return response;
19679
20005
  });
@@ -20117,6 +20443,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20117
20443
  this.subscription = data.subscription || null;
20118
20444
  this.planDetails = data.plan_details || null;
20119
20445
  this.exchangeRate = data.exchange_rate || null;
20446
+ this.savedCardsConfig = data.saved_cards || {};
20447
+ this.savedCardsToken = null;
20120
20448
  /**
20121
20449
  * We initialize parameters we send to the API as empty strings
20122
20450
  * when we don't have them instead of null because the API expects
@@ -20457,6 +20785,417 @@ var Toolkit = /*#__PURE__*/function () {
20457
20785
  return Toolkit;
20458
20786
  }();
20459
20787
 
20788
+ cardValidator.creditCardType.addCard({
20789
+ niceType: 'Verve',
20790
+ type: 'verve',
20791
+ patterns: [[506000, 507999], [650000, 650009]],
20792
+ gaps: [4, 8, 12, 16],
20793
+ lengths: [16, 18, 19],
20794
+ code: {
20795
+ name: 'CVV',
20796
+ size: 3
20797
+ }
20798
+ });
20799
+ cardValidator.creditCardType.changeOrder('verve', 0);
20800
+
20801
+ var Card = /*#__PURE__*/function () {
20802
+ function Card(_ref) {
20803
+ var number = _ref.number,
20804
+ cvv = _ref.cvv,
20805
+ month = _ref.month,
20806
+ year = _ref.year,
20807
+ pin = _ref.pin;
20808
+
20809
+ _classCallCheck(this, Card);
20810
+
20811
+ this.number = number;
20812
+ this.cvv = cvv;
20813
+ this.month = month;
20814
+ this.year = year;
20815
+ this.pin = pin;
20816
+ }
20817
+
20818
+ _createClass(Card, [{
20819
+ key: "getEncryptedPin",
20820
+ value: function getEncryptedPin() {
20821
+ return Card$2.getEncryptedPin(this.pin);
20822
+ }
20823
+ }, {
20824
+ key: "getLast4",
20825
+ value: function getLast4() {
20826
+ return Card$2.getLast4(this.number);
20827
+ }
20828
+ }, {
20829
+ key: "tokenize",
20830
+ value: function tokenize() {
20831
+ return Card$2.tokenize({
20832
+ number: this.number,
20833
+ cvv: this.cvv,
20834
+ month: this.month,
20835
+ year: this.year
20836
+ });
20837
+ }
20838
+ }], [{
20839
+ key: "getType",
20840
+ value: function getType(value) {
20841
+ return Card$2.getType(value);
20842
+ }
20843
+ }, {
20844
+ key: "validate",
20845
+ value: function validate(_ref2) {
20846
+ var number = _ref2.number,
20847
+ cvv = _ref2.cvv,
20848
+ month = _ref2.month,
20849
+ year = _ref2.year;
20850
+ return Card$2.validate({
20851
+ number: number,
20852
+ cvv: cvv,
20853
+ month: month,
20854
+ year: year
20855
+ });
20856
+ }
20857
+ }, {
20858
+ key: "validateNumber",
20859
+ value: function validateNumber(value) {
20860
+ return Card$2.validateNumber(value);
20861
+ }
20862
+ }, {
20863
+ key: "isNumberValid",
20864
+ value: function isNumberValid(value) {
20865
+ return Card$2.isNumberValid(value);
20866
+ }
20867
+ }, {
20868
+ key: "validateCVV",
20869
+ value: function validateCVV(cvv, cardType) {
20870
+ return Card$2.validateCVV(cvv, cardType);
20871
+ }
20872
+ }, {
20873
+ key: "isCvvValid",
20874
+ value: function isCvvValid(cvv, cardType) {
20875
+ return Card$2.isCvvValid(cvv, cardType);
20876
+ }
20877
+ }, {
20878
+ key: "validateExpiry",
20879
+ value: function validateExpiry(value) {
20880
+ return Card$2.validateExpiry(value);
20881
+ }
20882
+ }, {
20883
+ key: "isExpiryValid",
20884
+ value: function isExpiryValid(value) {
20885
+ return Card$2.isExpiryValid(value);
20886
+ }
20887
+ }, {
20888
+ key: "generateTestCard",
20889
+ value: function generateTestCard(cardType) {
20890
+ var type = cardType || 'default';
20891
+ var cardParams = testCards.find(function (card) {
20892
+ return card.type === type;
20893
+ });
20894
+ return new Card(cardParams);
20895
+ }
20896
+ }]);
20897
+
20898
+ return Card;
20899
+ }();
20900
+
20901
+ var CardAPI = {
20902
+ reserve: function reserve(_ref) {
20903
+ var clientdata = _ref.clientdata,
20904
+ last4 = _ref.last4,
20905
+ preauthorizationId = _ref.preauthorizationId;
20906
+ var url = "".concat(configToUse.paystackApiUrl, "preauthorization/reserve");
20907
+ var language = getLanguage();
20908
+
20909
+ var headers = _objectSpread2({}, language && {
20910
+ 'Accept-Language': language
20911
+ });
20912
+
20913
+ return axiosInstance.post(url, {
20914
+ clientdata: clientdata,
20915
+ last4: last4,
20916
+ preauthorization: preauthorizationId
20917
+ }, {
20918
+ headers: headers
20919
+ }).then(function (response) {
20920
+ return ChargeResponses.parse(response.data);
20921
+ });
20922
+ } // charge({
20923
+ // clientdata,
20924
+ // last4,
20925
+ // pin,
20926
+ // trans,
20927
+ // device,
20928
+ // rememberCard,
20929
+ // transactionType,
20930
+ // subscription,
20931
+ // customFields,
20932
+ // }) {
20933
+ // const url = `${config.paymentBaseUrl}charge/`;
20934
+ // const language = getLanguage();
20935
+ // const headers = {
20936
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20937
+ // ...(language && { 'Accept-Language': language }),
20938
+ // };
20939
+ // const chargeParams = {
20940
+ // clientdata,
20941
+ // last4,
20942
+ // trans,
20943
+ // device,
20944
+ // offset: new Date().getTimezoneOffset(),
20945
+ // remember_card: rememberCard,
20946
+ // ...(transactionType && { transaction_type: transactionType }),
20947
+ // ...(subscription && { subscription }),
20948
+ // ...(customFields && customFields),
20949
+ // };
20950
+ // if (pin) {
20951
+ // chargeParams.handle = pin;
20952
+ // }
20953
+ // const urlEncodedParams = formurlencoded(chargeParams);
20954
+ // return axiosInstance
20955
+ // .post(url, urlEncodedParams, { headers })
20956
+ // .then((response) => ChargeResponses.parse(response.data));
20957
+ // },
20958
+ // resumeCardCharge({ device, accessCode, pin }) {
20959
+ // const url = `${config.paymentBaseUrl}charge/resume/${accessCode}`;
20960
+ // const language = getLanguage();
20961
+ // const headers = {
20962
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20963
+ // ...(language && { 'Accept-Language': language }),
20964
+ // };
20965
+ // const data = { device, ...(pin && { handle: pin }) };
20966
+ // const urlEncodedData = formurlencoded(data);
20967
+ // return axiosInstance
20968
+ // .post(url, urlEncodedData, { headers })
20969
+ // .then((response) => ChargeResponses.parse(response.data));
20970
+ // },
20971
+ // chargeRememberedCard({
20972
+ // last4,
20973
+ // trans,
20974
+ // device,
20975
+ // authorizationCode,
20976
+ // cvv,
20977
+ // pin,
20978
+ // transactionType,
20979
+ // subscription,
20980
+ // }) {
20981
+ // const url = `${config.paymentBaseUrl}charge/`;
20982
+ // const language = getLanguage();
20983
+ // const headers = {
20984
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20985
+ // ...(language && { 'Accept-Language': language }),
20986
+ // };
20987
+ // const chargeParams = {
20988
+ // last4,
20989
+ // trans,
20990
+ // device,
20991
+ // cvv,
20992
+ // handle: pin,
20993
+ // authorization_code: authorizationCode,
20994
+ // ...(transactionType && { transaction_type: transactionType }),
20995
+ // ...(subscription && { subscription }),
20996
+ // };
20997
+ // const urlEncodedParams = formurlencoded(chargeParams);
20998
+ // return axiosInstance
20999
+ // .post(url, urlEncodedParams, { headers })
21000
+ // .then((response) => ChargeResponses.parse(response.data));
21001
+ // },
21002
+ // verifyAddress({ address, city, state, zipCode, transactionId }) {
21003
+ // const url = `${config.paymentBaseUrl}charge/avs`;
21004
+ // const language = getLanguage();
21005
+ // const headers = {
21006
+ // 'Content-Type': 'application/x-www-form-urlencoded',
21007
+ // ...(language && { 'Accept-Language': language }),
21008
+ // };
21009
+ // const data = {
21010
+ // city,
21011
+ // state,
21012
+ // address,
21013
+ // zip_code: zipCode,
21014
+ // trans: transactionId,
21015
+ // };
21016
+ // const urlEncodedData = formurlencoded(data);
21017
+ // return axiosInstance
21018
+ // .post(url, urlEncodedData, { headers })
21019
+ // .then((response) => ChargeResponses.parse(response.data));
21020
+ // },
21021
+ // forgetRememberedCard({ authorizationId, publicKey }) {
21022
+ // const language = getLanguage();
21023
+ // const headers = {
21024
+ // Authorization: `Bearer ${publicKey}`,
21025
+ // ...(language && { 'Accept-Language': language }),
21026
+ // };
21027
+ // const params = {
21028
+ // authorization_id: authorizationId,
21029
+ // };
21030
+ // const url = `${config.paystackApiUrl}rememberme/forget_card`;
21031
+ // return axiosInstance
21032
+ // .post(url, params, { headers })
21033
+ // .then((response) => ChargeResponses.parse(response.data));
21034
+ // },
21035
+
21036
+ };
21037
+
21038
+ var paymentMethod = 'card';
21039
+
21040
+ function validate(card, isSetter) {
21041
+ return new Promise(function (resolve, reject) {
21042
+ var validation = Card.validate(card);
21043
+
21044
+ if (!validation.isValid) {
21045
+ var throwValidation = isSetter || card.number;
21046
+ var errors = Object.keys(validation.result).filter(function (value) {
21047
+ return validation.result[value] === false;
21048
+ });
21049
+ var errorMessage = "Invalid card details: ".concat(errors.join(', '));
21050
+ reject(Error(throwValidation ? errorMessage : 'Please set a valid card with setCard()'));
21051
+ }
21052
+
21053
+ resolve();
21054
+ });
21055
+ }
21056
+
21057
+ var ReserveCardFunds = {
21058
+ setCard: function setCard(params) {
21059
+ var _this = this;
21060
+
21061
+ return validate(params, true).then(function () {
21062
+ _this.card = new Card(params);
21063
+ });
21064
+ },
21065
+ reserve: function reserve(preauthorizationId) {
21066
+ var _this2 = this;
21067
+
21068
+ var customFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21069
+ // TODO: Log payment method
21070
+ // https://paystack.atlassian.net/browse/RAILS-3070
21071
+ return validate(this.card).then(function () {
21072
+ var chargeParams = {
21073
+ clientdata: _this2.card.tokenize(),
21074
+ last4: _this2.card.getLast4(),
21075
+ preauthorization: preauthorizationId,
21076
+ customFields: customFields
21077
+ };
21078
+ return CardAPI.charge(chargeParams).then(function (response) {
21079
+ // TODO: Log API Response
21080
+ // https://paystack.atlassian.net/browse/RAILS-3070
21081
+ return response;
21082
+ });
21083
+ });
21084
+ },
21085
+ listenFor3DSCharge: function listenFor3DSCharge(callback) {
21086
+ var listenerOptions = {
21087
+ channel: "3DS_".concat(this.id),
21088
+ paymentMethod: paymentMethod
21089
+ };
21090
+ return this.listenForCharge(listenerOptions, callback);
21091
+ } // rememberCard() {
21092
+ // this.remember_card = true;
21093
+ // },
21094
+ // chargeCard(customFields = {}) {
21095
+ // if (!this.card.number && this.card.pin) {
21096
+ // return this.chargeCardWithPin(customFields);
21097
+ // }
21098
+ // return validate(this.card).then(() => {
21099
+ // this.logAttempt(paymentMethod);
21100
+ // const chargeParams = {
21101
+ // clientdata: this.card.tokenize(),
21102
+ // last4: this.card.getLast4(),
21103
+ // pin: this.card.getEncryptedPin(),
21104
+ // trans: this.id,
21105
+ // device: this.deviceFingerprint,
21106
+ // rememberCard: this.remember_card,
21107
+ // transactionType: this.transactionType,
21108
+ // subscription: this.subscription,
21109
+ // customFields,
21110
+ // };
21111
+ // return CardAPI.charge(chargeParams).then((response) => {
21112
+ // this.logAPIResponse(response, paymentMethod);
21113
+ // return response;
21114
+ // });
21115
+ // });
21116
+ // },
21117
+
21118
+ /**
21119
+ * Handles submitting a card pin after
21120
+ * other card details have been previously submitted.
21121
+ */
21122
+ // chargeCardWithPin(customFields = {}) {
21123
+ // this.logAttempt(paymentMethod);
21124
+ // const chargeParams = {
21125
+ // pin: encrypt(this.card.pin),
21126
+ // trans: this.id,
21127
+ // device: this.deviceFingerprint,
21128
+ // rememberCard: this.remember_card,
21129
+ // transactionType: this.transactionType,
21130
+ // subscription: this.subscription,
21131
+ // customFields,
21132
+ // };
21133
+ // return CardAPI.charge(chargeParams).then((response) => {
21134
+ // this.logAPIResponse(response, paymentMethod);
21135
+ // return response;
21136
+ // });
21137
+ // },
21138
+ // chargeRememberedCard({ cvv, authorizationCode, cardLast4, pin }) {
21139
+ // this.logAttempt(paymentMethod);
21140
+ // const encryptedPin = encrypt(pin);
21141
+ // const chargeParams = {
21142
+ // authorizationCode,
21143
+ // cvv,
21144
+ // last4: cardLast4,
21145
+ // trans: this.id,
21146
+ // device: this.deviceFingerprint,
21147
+ // pin: encryptedPin,
21148
+ // transactionType: this.transactionType,
21149
+ // subscription: this.subscription,
21150
+ // };
21151
+ // return CardAPI.chargeRememberedCard(chargeParams).then((response) => {
21152
+ // this.logAPIResponse(response, paymentMethod);
21153
+ // return response;
21154
+ // });
21155
+ // },
21156
+ // resumeCardCharge({ accessCode, pin }) {
21157
+ // const params = {
21158
+ // ...(pin && { pin: encrypt(pin) }),
21159
+ // accessCode,
21160
+ // device: this.deviceFingerprint,
21161
+ // };
21162
+ // return CardAPI.resumeCardCharge(params).then((response) => {
21163
+ // this.logAPIResponse(response, paymentMethod);
21164
+ // return response;
21165
+ // });
21166
+ // },
21167
+ // forgetRememberedCard(authorizationId) {
21168
+ // const params = {
21169
+ // authorizationId,
21170
+ // publicKey: this.merchant.key,
21171
+ // };
21172
+ // return CardAPI.forgetRememberedCard(params).then((response) => {
21173
+ // this.logAPIResponse(response, paymentMethod);
21174
+ // return response;
21175
+ // });
21176
+ // },
21177
+ // authenticateCard(token) {
21178
+ // return CardAPI.authenticate(this.id, token).then((response) => {
21179
+ // this.logAPIResponse(response, paymentMethod);
21180
+ // return response;
21181
+ // });
21182
+ // },
21183
+ // verifyAddress({ address, city, state, zipCode }) {
21184
+ // const payload = {
21185
+ // city,
21186
+ // state,
21187
+ // address,
21188
+ // zipCode,
21189
+ // transactionId: this.id,
21190
+ // };
21191
+ // return CardAPI.verifyAddress(payload).then((response) => {
21192
+ // this.logAPIResponse(response, paymentMethod);
21193
+ // return response;
21194
+ // });
21195
+ // },
21196
+
21197
+ };
21198
+
20460
21199
  var PreauthorizationInstance = /*#__PURE__*/function () {
20461
21200
  function PreauthorizationInstance(data) {
20462
21201
  _classCallCheck(this, PreauthorizationInstance);
@@ -20476,8 +21215,10 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20476
21215
  name: data.merchant_name,
20477
21216
  key: data.merchant_key
20478
21217
  };
20479
- loadPusher(); // TODO: Bind charge function to card channel
20480
- // https://paystack.atlassian.net/browse/RAILS-2887
21218
+ loadPusher(); // TODO: Analytics
21219
+ // https://paystack.atlassian.net/browse/RAILS-3070
21220
+
21221
+ Object.assign(this, ReserveCardFunds);
20481
21222
  }
20482
21223
 
20483
21224
  _createClass(PreauthorizationInstance, [{
@@ -20558,4 +21299,4 @@ var Preauthorization = {
20558
21299
  }
20559
21300
  };
20560
21301
 
20561
- export { BankAccount, Card, Preauthorization, Toolkit, Transaction };
21302
+ export { BankAccount, Card$1 as Card, Preauthorization, Toolkit, Transaction };