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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,56 +18194,136 @@ var cardValidator = {
18240
18194
  creditCardType: creditCardType_1
18241
18195
  };
18242
18196
 
18243
- var testCards = [{
18244
- type: 'bank_auth',
18245
- name: 'Bank authorization',
18246
- number: '4084080000000409',
18247
- cvv: '000',
18248
- month: '01',
18249
- year: '30'
18250
- }, {
18251
- type: 'success',
18252
- name: 'Success',
18253
- number: '4084084084084081',
18254
- cvv: '408',
18255
- month: '12',
18256
- year: '30'
18257
- }, {
18258
- type: 'declined',
18259
- name: 'Declined',
18260
- number: '4084080000005408',
18261
- cvv: '001',
18262
- month: '12',
18263
- year: '30'
18264
- }, {
18265
- type: 'pin',
18266
- name: 'Pin only validation',
18267
- number: '507850785078507812',
18268
- cvv: '884',
18269
- month: '01',
18270
- year: '30'
18271
- }, {
18272
- type: 'pin+otp',
18273
- name: 'Pin and OTP validation',
18274
- number: '5060666666666666666',
18275
- cvv: '123',
18276
- month: '01',
18277
- year: '30'
18278
- }, {
18279
- type: 'pin+phone+otp',
18280
- name: 'Pin, phone and OTP validation',
18281
- number: '507850785078507812',
18282
- cvv: '884',
18283
- month: '01',
18284
- year: '30'
18285
- }, {
18286
- type: 'default',
18287
- name: 'No validation',
18288
- number: '4084084084084081',
18289
- cvv: '408',
18290
- month: '01',
18291
- year: '30'
18292
- }];
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
+ };
18293
18327
 
18294
18328
  cardValidator.creditCardType.addCard({
18295
18329
  niceType: 'Verve',
@@ -18304,7 +18338,7 @@ cardValidator.creditCardType.addCard({
18304
18338
  });
18305
18339
  cardValidator.creditCardType.changeOrder('verve', 0);
18306
18340
 
18307
- var Card = /*#__PURE__*/function () {
18341
+ var Card$1 = /*#__PURE__*/function () {
18308
18342
  function Card(_ref) {
18309
18343
  var number = _ref.number,
18310
18344
  cvv = _ref.cvv,
@@ -18324,35 +18358,27 @@ var Card = /*#__PURE__*/function () {
18324
18358
  _createClass(Card, [{
18325
18359
  key: "getEncryptedPin",
18326
18360
  value: function getEncryptedPin() {
18327
- return this.pin ? encrypt(this.pin) : undefined;
18361
+ return Card$2.getEncryptedPin(this.pin);
18328
18362
  }
18329
18363
  }, {
18330
18364
  key: "getLast4",
18331
18365
  value: function getLast4() {
18332
- return this.number.substring(this.number.length - 4);
18366
+ return Card$2.getLast4(this.number);
18333
18367
  }
18334
18368
  }, {
18335
18369
  key: "tokenize",
18336
18370
  value: function tokenize() {
18337
- return encrypt("".concat(this.number, "*").concat(this.cvv, "*").concat(this.month, "*").concat(this.year));
18371
+ return Card$2.tokenize({
18372
+ number: this.number,
18373
+ cvv: this.cvv,
18374
+ month: this.month,
18375
+ year: this.year
18376
+ });
18338
18377
  }
18339
18378
  }], [{
18340
18379
  key: "getType",
18341
18380
  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
- };
18381
+ return Card$2.getType(value);
18356
18382
  }
18357
18383
  }, {
18358
18384
  key: "validate",
@@ -18361,63 +18387,42 @@ var Card = /*#__PURE__*/function () {
18361
18387
  cvv = _ref2.cvv,
18362
18388
  month = _ref2.month,
18363
18389
  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;
18390
+ return Card$2.validate({
18391
+ number: number,
18392
+ cvv: cvv,
18393
+ month: month,
18394
+ year: year
18378
18395
  });
18379
- return {
18380
- isValid: isValid,
18381
- result: result
18382
- };
18383
18396
  }
18384
18397
  }, {
18385
18398
  key: "validateNumber",
18386
18399
  value: function validateNumber(value) {
18387
- return cardValidator.number(value);
18400
+ return Card$2.validateNumber(value);
18388
18401
  }
18389
18402
  }, {
18390
18403
  key: "isNumberValid",
18391
18404
  value: function isNumberValid(value) {
18392
- return Card.validateNumber(value).isValid;
18405
+ return Card$2.isNumberValid(value);
18393
18406
  }
18394
18407
  }, {
18395
18408
  key: "validateCVV",
18396
18409
  value: function validateCVV(cvv, cardType) {
18397
- var isAmexCard = cardType === 'american-express';
18398
- var cvvLength = isAmexCard ? 4 : 3;
18399
- return cardValidator.cvv(cvv, cvvLength);
18410
+ return Card$2.validateCVV(cvv, cardType);
18400
18411
  }
18401
18412
  }, {
18402
18413
  key: "isCvvValid",
18403
18414
  value: function isCvvValid(cvv, cardType) {
18404
- return Card.validateCVV(cvv, cardType).isValid;
18415
+ return Card$2.isCvvValid(cvv, cardType);
18405
18416
  }
18406
18417
  }, {
18407
18418
  key: "validateExpiry",
18408
18419
  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);
18420
+ return Card$2.validateExpiry(value);
18416
18421
  }
18417
18422
  }, {
18418
18423
  key: "isExpiryValid",
18419
18424
  value: function isExpiryValid(value) {
18420
- return Card.validateExpiry(value).isValid;
18425
+ return Card$2.isExpiryValid(value);
18421
18426
  }
18422
18427
  }, {
18423
18428
  key: "generateTestCard",
@@ -18433,7 +18438,7 @@ var Card = /*#__PURE__*/function () {
18433
18438
  return Card;
18434
18439
  }();
18435
18440
 
18436
- var CardAPI = {
18441
+ var CardAPI$1 = {
18437
18442
  charge: function charge(_ref) {
18438
18443
  var clientdata = _ref.clientdata,
18439
18444
  last4 = _ref.last4,
@@ -18609,14 +18614,215 @@ var CardAPI = {
18609
18614
  }).then(function (response) {
18610
18615
  return ChargeResponses.parse(response.data);
18611
18616
  });
18617
+ },
18618
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
18619
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18620
+ var url, language, headers, _yield$axiosInstance$, data;
18621
+
18622
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18623
+ while (1) {
18624
+ switch (_context.prev = _context.next) {
18625
+ case 0:
18626
+ url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18627
+ language = getLanguage();
18628
+ headers = _objectSpread2({}, language && {
18629
+ 'Accept-Language': language
18630
+ });
18631
+ _context.next = 5;
18632
+ return axiosInstance.post(url, {
18633
+ headers: headers
18634
+ });
18635
+
18636
+ case 5:
18637
+ _yield$axiosInstance$ = _context.sent;
18638
+ data = _yield$axiosInstance$.data;
18639
+ return _context.abrupt("return", data);
18640
+
18641
+ case 8:
18642
+ case "end":
18643
+ return _context.stop();
18644
+ }
18645
+ }
18646
+ }, _callee);
18647
+ }))();
18648
+ },
18649
+ addUserToSavedCards: function addUserToSavedCards(_ref6) {
18650
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18651
+ var phone, email, url, language, headers, data, response;
18652
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18653
+ while (1) {
18654
+ switch (_context2.prev = _context2.next) {
18655
+ case 0:
18656
+ phone = _ref6.phone, email = _ref6.email;
18657
+ url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18658
+ language = getLanguage();
18659
+ headers = _objectSpread2({}, language && {
18660
+ 'Accept-Language': language
18661
+ });
18662
+ data = {
18663
+ phone: phone,
18664
+ email: email
18665
+ };
18666
+ _context2.next = 7;
18667
+ return axiosInstance.post(url, data, {
18668
+ headers: headers
18669
+ });
18670
+
18671
+ case 7:
18672
+ response = _context2.sent;
18673
+ return _context2.abrupt("return", response.data);
18674
+
18675
+ case 9:
18676
+ case "end":
18677
+ return _context2.stop();
18678
+ }
18679
+ }
18680
+ }, _callee2);
18681
+ }))();
18682
+ },
18683
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18684
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18685
+ var code, phone, transaction, url, language, headers, data, response;
18686
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18687
+ while (1) {
18688
+ switch (_context3.prev = _context3.next) {
18689
+ case 0:
18690
+ code = _ref7.code, phone = _ref7.phone, transaction = _ref7.transaction;
18691
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18692
+ language = getLanguage();
18693
+ headers = _objectSpread2({}, language && {
18694
+ 'Accept-Language': language
18695
+ });
18696
+ data = {
18697
+ code: code,
18698
+ phone: phone,
18699
+ transaction: transaction
18700
+ };
18701
+ _context3.next = 7;
18702
+ return axiosInstance.post(url, data, {
18703
+ headers: headers
18704
+ });
18705
+
18706
+ case 7:
18707
+ response = _context3.sent;
18708
+ return _context3.abrupt("return", response.data);
18709
+
18710
+ case 9:
18711
+ case "end":
18712
+ return _context3.stop();
18713
+ }
18714
+ }
18715
+ }, _callee3);
18716
+ }))();
18717
+ },
18718
+ getSavedCards: function getSavedCards(_ref8) {
18719
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18720
+ var token, url, language, headers, response;
18721
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18722
+ while (1) {
18723
+ switch (_context4.prev = _context4.next) {
18724
+ case 0:
18725
+ token = _ref8.token;
18726
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18727
+ language = getLanguage();
18728
+ headers = _objectSpread2({
18729
+ Authorization: "Bearer ".concat(token),
18730
+ 'jwt-auth': true
18731
+ }, language && {
18732
+ 'Accept-Language': language
18733
+ });
18734
+ _context4.next = 6;
18735
+ return axiosInstance.get(url, {
18736
+ headers: headers
18737
+ });
18738
+
18739
+ case 6:
18740
+ response = _context4.sent;
18741
+ return _context4.abrupt("return", response.data);
18742
+
18743
+ case 8:
18744
+ case "end":
18745
+ return _context4.stop();
18746
+ }
18747
+ }
18748
+ }, _callee4);
18749
+ }))();
18750
+ },
18751
+ deleteSavedCard: function deleteSavedCard(_ref9) {
18752
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18753
+ var cardCode, token, url, language, headers, response;
18754
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18755
+ while (1) {
18756
+ switch (_context5.prev = _context5.next) {
18757
+ case 0:
18758
+ cardCode = _ref9.cardCode, token = _ref9.token;
18759
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18760
+ language = getLanguage();
18761
+ headers = _objectSpread2({
18762
+ Authorization: "Bearer ".concat(token),
18763
+ 'jwt-auth': true
18764
+ }, language && {
18765
+ 'Accept-Language': language
18766
+ });
18767
+ _context5.next = 6;
18768
+ return axiosInstance.delete(url, {
18769
+ headers: headers
18770
+ });
18771
+
18772
+ case 6:
18773
+ response = _context5.sent;
18774
+ return _context5.abrupt("return", response.data);
18775
+
18776
+ case 8:
18777
+ case "end":
18778
+ return _context5.stop();
18779
+ }
18780
+ }
18781
+ }, _callee5);
18782
+ }))();
18783
+ },
18784
+ chargeSavedCard: function chargeSavedCard(_ref10) {
18785
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18786
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18787
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
18788
+ while (1) {
18789
+ switch (_context6.prev = _context6.next) {
18790
+ case 0:
18791
+ token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18792
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18793
+ language = getLanguage();
18794
+ headers = _objectSpread2({
18795
+ Authorization: "Bearer ".concat(token),
18796
+ 'jwt-auth': true
18797
+ }, language && {
18798
+ 'Accept-Language': language
18799
+ });
18800
+ data = {
18801
+ device: device,
18802
+ transaction: transaction,
18803
+ selectedCurrency: selectedCurrency
18804
+ };
18805
+ return _context6.abrupt("return", axiosInstance.post(url, data, {
18806
+ headers: headers
18807
+ }).then(function (response) {
18808
+ return ChargeResponses.parse(response.data);
18809
+ }));
18810
+
18811
+ case 6:
18812
+ case "end":
18813
+ return _context6.stop();
18814
+ }
18815
+ }
18816
+ }, _callee6);
18817
+ }))();
18612
18818
  }
18613
18819
  };
18614
18820
 
18615
- var paymentMethod$3 = 'card';
18821
+ var paymentMethod$4 = 'card';
18616
18822
 
18617
- function validate$3(card, isSetter) {
18823
+ function validate$4(card, isSetter) {
18618
18824
  return new Promise(function (resolve, reject) {
18619
- var validation = Card.validate(card);
18825
+ var validation = Card$1.validate(card);
18620
18826
 
18621
18827
  if (!validation.isValid) {
18622
18828
  var throwValidation = isSetter || card.number;
@@ -18635,8 +18841,8 @@ var CardCharge = {
18635
18841
  setCard: function setCard(params) {
18636
18842
  var _this = this;
18637
18843
 
18638
- return validate$3(params, true).then(function () {
18639
- _this.card = new Card(params);
18844
+ return validate$4(params, true).then(function () {
18845
+ _this.card = new Card$1(params);
18640
18846
  });
18641
18847
  },
18642
18848
  rememberCard: function rememberCard() {
@@ -18651,8 +18857,8 @@ var CardCharge = {
18651
18857
  return this.chargeCardWithPin(customFields);
18652
18858
  }
18653
18859
 
18654
- return validate$3(this.card).then(function () {
18655
- _this2.logAttempt(paymentMethod$3);
18860
+ return validate$4(this.card).then(function () {
18861
+ _this2.logAttempt(paymentMethod$4);
18656
18862
 
18657
18863
  var chargeParams = {
18658
18864
  clientdata: _this2.card.tokenize(),
@@ -18665,8 +18871,8 @@ var CardCharge = {
18665
18871
  subscription: _this2.subscription,
18666
18872
  customFields: customFields
18667
18873
  };
18668
- return CardAPI.charge(chargeParams).then(function (response) {
18669
- _this2.logAPIResponse(response, paymentMethod$3);
18874
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18875
+ _this2.logAPIResponse(response, paymentMethod$4);
18670
18876
 
18671
18877
  return response;
18672
18878
  });
@@ -18681,7 +18887,7 @@ var CardCharge = {
18681
18887
  var _this3 = this;
18682
18888
 
18683
18889
  var customFields = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18684
- this.logAttempt(paymentMethod$3);
18890
+ this.logAttempt(paymentMethod$4);
18685
18891
  var chargeParams = {
18686
18892
  pin: encrypt(this.card.pin),
18687
18893
  trans: this.id,
@@ -18691,8 +18897,8 @@ var CardCharge = {
18691
18897
  subscription: this.subscription,
18692
18898
  customFields: customFields
18693
18899
  };
18694
- return CardAPI.charge(chargeParams).then(function (response) {
18695
- _this3.logAPIResponse(response, paymentMethod$3);
18900
+ return CardAPI$1.charge(chargeParams).then(function (response) {
18901
+ _this3.logAPIResponse(response, paymentMethod$4);
18696
18902
 
18697
18903
  return response;
18698
18904
  });
@@ -18704,7 +18910,7 @@ var CardCharge = {
18704
18910
  authorizationCode = _ref.authorizationCode,
18705
18911
  cardLast4 = _ref.cardLast4,
18706
18912
  pin = _ref.pin;
18707
- this.logAttempt(paymentMethod$3);
18913
+ this.logAttempt(paymentMethod$4);
18708
18914
  var encryptedPin = encrypt(pin);
18709
18915
  var chargeParams = {
18710
18916
  authorizationCode: authorizationCode,
@@ -18716,8 +18922,8 @@ var CardCharge = {
18716
18922
  transactionType: this.transactionType,
18717
18923
  subscription: this.subscription
18718
18924
  };
18719
- return CardAPI.chargeRememberedCard(chargeParams).then(function (response) {
18720
- _this4.logAPIResponse(response, paymentMethod$3);
18925
+ return CardAPI$1.chargeRememberedCard(chargeParams).then(function (response) {
18926
+ _this4.logAPIResponse(response, paymentMethod$4);
18721
18927
 
18722
18928
  return response;
18723
18929
  });
@@ -18735,8 +18941,8 @@ var CardCharge = {
18735
18941
  device: this.deviceFingerprint
18736
18942
  });
18737
18943
 
18738
- return CardAPI.resumeCardCharge(params).then(function (response) {
18739
- _this5.logAPIResponse(response, paymentMethod$3);
18944
+ return CardAPI$1.resumeCardCharge(params).then(function (response) {
18945
+ _this5.logAPIResponse(response, paymentMethod$4);
18740
18946
 
18741
18947
  return response;
18742
18948
  });
@@ -18748,8 +18954,8 @@ var CardCharge = {
18748
18954
  authorizationId: authorizationId,
18749
18955
  publicKey: this.merchant.key
18750
18956
  };
18751
- return CardAPI.forgetRememberedCard(params).then(function (response) {
18752
- _this6.logAPIResponse(response, paymentMethod$3);
18957
+ return CardAPI$1.forgetRememberedCard(params).then(function (response) {
18958
+ _this6.logAPIResponse(response, paymentMethod$4);
18753
18959
 
18754
18960
  return response;
18755
18961
  });
@@ -18757,8 +18963,8 @@ var CardCharge = {
18757
18963
  authenticateCard: function authenticateCard(token) {
18758
18964
  var _this7 = this;
18759
18965
 
18760
- return CardAPI.authenticate(this.id, token).then(function (response) {
18761
- _this7.logAPIResponse(response, paymentMethod$3);
18966
+ return CardAPI$1.authenticate(this.id, token).then(function (response) {
18967
+ _this7.logAPIResponse(response, paymentMethod$4);
18762
18968
 
18763
18969
  return response;
18764
18970
  });
@@ -18777,8 +18983,8 @@ var CardCharge = {
18777
18983
  zipCode: zipCode,
18778
18984
  transactionId: this.id
18779
18985
  };
18780
- return CardAPI.verifyAddress(payload).then(function (response) {
18781
- _this8.logAPIResponse(response, paymentMethod$3);
18986
+ return CardAPI$1.verifyAddress(payload).then(function (response) {
18987
+ _this8.logAPIResponse(response, paymentMethod$4);
18782
18988
 
18783
18989
  return response;
18784
18990
  });
@@ -18786,9 +18992,78 @@ var CardCharge = {
18786
18992
  listenFor3DSCharge: function listenFor3DSCharge(callback) {
18787
18993
  var listenerOptions = {
18788
18994
  channel: "3DS_".concat(this.id),
18789
- paymentMethod: paymentMethod$3
18995
+ paymentMethod: paymentMethod$4
18790
18996
  };
18791
18997
  return this.listenForCharge(listenerOptions, callback);
18998
+ },
18999
+ requestSavedCardsOTP: function requestSavedCardsOTP(phoneNumber) {
19000
+ return CardAPI$1.requestSavedCardsOTP(phoneNumber);
19001
+ },
19002
+ addUserToSavedCards: function addUserToSavedCards(_ref4) {
19003
+ var phone = _ref4.phone;
19004
+ return CardAPI$1.addUserToSavedCards({
19005
+ phone: phone,
19006
+ email: this.email
19007
+ });
19008
+ },
19009
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19010
+ var _this9 = this;
19011
+
19012
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19013
+ var code, phone, payload, response;
19014
+ return regeneratorRuntime.wrap(function _callee$(_context) {
19015
+ while (1) {
19016
+ switch (_context.prev = _context.next) {
19017
+ case 0:
19018
+ code = _ref5.code, phone = _ref5.phone;
19019
+ payload = {
19020
+ code: code,
19021
+ phone: phone,
19022
+ transaction: _this9.id
19023
+ };
19024
+ _context.prev = 2;
19025
+ _context.next = 5;
19026
+ return CardAPI$1.verifySavedCardsOtp(payload);
19027
+
19028
+ case 5:
19029
+ response = _context.sent;
19030
+ _this9.savedCardsToken = response.data.token;
19031
+ return _context.abrupt("return", response);
19032
+
19033
+ case 10:
19034
+ _context.prev = 10;
19035
+ _context.t0 = _context["catch"](2);
19036
+ _this9.savedCardsToken = null;
19037
+ throw _context.t0;
19038
+
19039
+ case 14:
19040
+ case "end":
19041
+ return _context.stop();
19042
+ }
19043
+ }
19044
+ }, _callee, null, [[2, 10]]);
19045
+ }))();
19046
+ },
19047
+ getSavedCards: function getSavedCards() {
19048
+ return CardAPI$1.getSavedCards({
19049
+ token: this.savedCardsToken
19050
+ });
19051
+ },
19052
+ deleteSavedCard: function deleteSavedCard(cardCode) {
19053
+ return CardAPI$1.deleteSavedCard({
19054
+ cardCode: cardCode,
19055
+ token: this.savedCardsToken
19056
+ });
19057
+ },
19058
+ chargeSavedCard: function chargeSavedCard(_ref6) {
19059
+ var cardCode = _ref6.cardCode;
19060
+ return CardAPI$1.chargeSavedCard({
19061
+ cardCode: cardCode,
19062
+ transaction: this.id,
19063
+ token: this.savedCardsToken,
19064
+ device: this.deviceFingerprint,
19065
+ selectedCurrency: this.currency
19066
+ });
18792
19067
  }
18793
19068
  };
18794
19069
 
@@ -18941,9 +19216,9 @@ var EMandateAPI = {
18941
19216
  }
18942
19217
  };
18943
19218
 
18944
- var paymentMethod$2 = 'bank account';
19219
+ var paymentMethod$3 = 'bank account';
18945
19220
 
18946
- function validate$2(bankAccount, isSetter) {
19221
+ function validate$3(bankAccount, isSetter) {
18947
19222
  return new Promise(function (resolve, reject) {
18948
19223
  var validation = BankAccount.validate(bankAccount);
18949
19224
 
@@ -18961,15 +19236,15 @@ var EMandate = {
18961
19236
  setBankAccount: function setBankAccount(params) {
18962
19237
  var _this = this;
18963
19238
 
18964
- return validate$2(params, true).then(function () {
19239
+ return validate$3(params, true).then(function () {
18965
19240
  _this.bankAccount = new BankAccount(params);
18966
19241
  });
18967
19242
  },
18968
19243
  chargeBankAccount: function chargeBankAccount() {
18969
19244
  var _this2 = this;
18970
19245
 
18971
- return validate$2(this.bankAccount).then(function () {
18972
- _this2.logAttempt(paymentMethod$2);
19246
+ return validate$3(this.bankAccount).then(function () {
19247
+ _this2.logAttempt(paymentMethod$3);
18973
19248
 
18974
19249
  var verifyParams = {
18975
19250
  bankId: _this2.bankAccount.bankId,
@@ -18978,7 +19253,7 @@ var EMandate = {
18978
19253
  device: _this2.deviceFingerprint
18979
19254
  };
18980
19255
  return EMandateAPI.verify(verifyParams).then(function (response) {
18981
- _this2.logAPIResponse(response, paymentMethod$2);
19256
+ _this2.logAPIResponse(response, paymentMethod$3);
18982
19257
 
18983
19258
  return response;
18984
19259
  });
@@ -18987,7 +19262,7 @@ var EMandate = {
18987
19262
  registerBankAccount: function registerBankAccount(birthday) {
18988
19263
  var _this3 = this;
18989
19264
 
18990
- return validate$2(this.bankAccount).then(function () {
19265
+ return validate$3(this.bankAccount).then(function () {
18991
19266
  var registerParams = {
18992
19267
  bankId: _this3.bankAccount.bankId,
18993
19268
  transactionId: _this3.id,
@@ -18995,7 +19270,7 @@ var EMandate = {
18995
19270
  birthday: birthday
18996
19271
  };
18997
19272
  return EMandateAPI.register(registerParams).then(function (response) {
18998
- _this3.logAPIResponse(response, paymentMethod$2);
19273
+ _this3.logAPIResponse(response, paymentMethod$3);
18999
19274
 
19000
19275
  return response;
19001
19276
  });
@@ -19004,7 +19279,7 @@ var EMandate = {
19004
19279
  authenticateBankAccount: function authenticateBankAccount(token) {
19005
19280
  var _this4 = this;
19006
19281
 
19007
- return validate$2(this.bankAccount).then(function () {
19282
+ return validate$3(this.bankAccount).then(function () {
19008
19283
  var chargeParams = {
19009
19284
  bankId: _this4.bankAccount.bankId,
19010
19285
  transactionId: _this4.id,
@@ -19012,7 +19287,7 @@ var EMandate = {
19012
19287
  device: _this4.deviceFingerprint
19013
19288
  };
19014
19289
  return EMandateAPI.authenticate(chargeParams).then(function (response) {
19015
- _this4.logAPIResponse(response, paymentMethod$2);
19290
+ _this4.logAPIResponse(response, paymentMethod$3);
19016
19291
 
19017
19292
  return response;
19018
19293
  });
@@ -19073,7 +19348,7 @@ var DigitalBankMandateAPI = {
19073
19348
  }
19074
19349
  };
19075
19350
 
19076
- var paymentMethod$1 = 'bank';
19351
+ var paymentMethod$2 = 'bank';
19077
19352
  var DigitalBankMandate = {
19078
19353
  chargeDigitalBankMandate: function chargeDigitalBankMandate(_ref) {
19079
19354
  var _this = this;
@@ -19088,7 +19363,7 @@ var DigitalBankMandate = {
19088
19363
  bankId: bankId
19089
19364
  };
19090
19365
  return DigitalBankMandateAPI.charge(params).then(function (response) {
19091
- _this.logAPIResponse(response, paymentMethod$1);
19366
+ _this.logAPIResponse(response, paymentMethod$2);
19092
19367
 
19093
19368
  return response;
19094
19369
  });
@@ -19096,7 +19371,7 @@ var DigitalBankMandate = {
19096
19371
  listenForDigitalBankMandateCharge: function listenForDigitalBankMandateCharge(callback) {
19097
19372
  var pusherChannel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
19098
19373
  var listenerOptions = {
19099
- paymentMethod: paymentMethod$1,
19374
+ paymentMethod: paymentMethod$2,
19100
19375
  channel: pusherChannel
19101
19376
  };
19102
19377
  return this.listenForCharge(listenerOptions, callback);
@@ -19229,7 +19504,7 @@ var QrAPI = {
19229
19504
  }
19230
19505
  };
19231
19506
 
19232
- function validate$1(channel) {
19507
+ function validate$2(channel) {
19233
19508
  return new Promise(function (resolve, reject) {
19234
19509
  var allowedChannels = ['visa', 'MPASS_OLTI'];
19235
19510
 
@@ -19247,7 +19522,7 @@ var QRCharge = {
19247
19522
  var _this = this;
19248
19523
 
19249
19524
  var channel = _ref.channel;
19250
- return validate$1(channel).then(function () {
19525
+ return validate$2(channel).then(function () {
19251
19526
  if (_this.qr[channel]) {
19252
19527
  return _this.qr[channel];
19253
19528
  }
@@ -19269,7 +19544,7 @@ var QRCharge = {
19269
19544
  var _this2 = this;
19270
19545
 
19271
19546
  var channel = _ref2.channel;
19272
- return validate$1(channel).then(function () {
19547
+ return validate$2(channel).then(function () {
19273
19548
  if (!_this2.qr[channel]) {
19274
19549
  return Promise.reject(Error('Please generate qr code with Transaction.getQRCode()'));
19275
19550
  }
@@ -19390,7 +19665,7 @@ var MobileMoneyAPI = {
19390
19665
  }
19391
19666
  };
19392
19667
 
19393
- function validate(phoneNumber) {
19668
+ function validate$1(phoneNumber) {
19394
19669
  return new Promise(function (resolve, reject) {
19395
19670
  var validation = PhoneNumber.validate(phoneNumber);
19396
19671
 
@@ -19411,7 +19686,7 @@ var MobileMoneyCharge = {
19411
19686
  provider = _ref.provider,
19412
19687
  voucher = _ref.voucher,
19413
19688
  registrationToken = _ref.registrationToken;
19414
- return validate(phoneNumber).then(function () {
19689
+ return validate$1(phoneNumber).then(function () {
19415
19690
  _this.logAttempt('mobile money');
19416
19691
 
19417
19692
  var params = {
@@ -19442,7 +19717,7 @@ var MobileMoneyCharge = {
19442
19717
  var phoneNumber = payload.phoneNumber,
19443
19718
  provider = payload.provider,
19444
19719
  registrationToken = payload.registrationToken;
19445
- return validate(phoneNumber).then(function () {
19720
+ return validate$1(phoneNumber).then(function () {
19446
19721
  _this2.logMobileMoneyActions(payload);
19447
19722
 
19448
19723
  var params = {
@@ -19582,7 +19857,7 @@ var DirectDebitAPI = {
19582
19857
  }
19583
19858
  };
19584
19859
 
19585
- var paymentMethod = 'direct debit';
19860
+ var paymentMethod$1 = 'direct debit';
19586
19861
  var DirectDebitCharge = {
19587
19862
  loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
19588
19863
  var _this = this;
@@ -19628,14 +19903,14 @@ var DirectDebitCharge = {
19628
19903
  return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
19629
19904
  }
19630
19905
 
19631
- this.logAttempt(paymentMethod);
19906
+ this.logAttempt(paymentMethod$1);
19632
19907
  var params = {
19633
19908
  account_code: accountCode,
19634
19909
  transaction: this.id,
19635
19910
  token: this.directDebit.token
19636
19911
  };
19637
19912
  return DirectDebitAPI.charge(params).then(function (response) {
19638
- _this2.logAPIResponse(response, paymentMethod);
19913
+ _this2.logAPIResponse(response, paymentMethod$1);
19639
19914
 
19640
19915
  if (response.status) {
19641
19916
  _this2.directDebit.chargeResponse = response;
@@ -19648,7 +19923,7 @@ var DirectDebitCharge = {
19648
19923
  var _this3 = this;
19649
19924
 
19650
19925
  return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
19651
- _this3.logAPIResponse(response, paymentMethod);
19926
+ _this3.logAPIResponse(response, paymentMethod$1);
19652
19927
 
19653
19928
  var status = response.status,
19654
19929
  data = response.data;
@@ -19673,7 +19948,7 @@ var DirectDebitCharge = {
19673
19948
  token: this.directDebit.token
19674
19949
  };
19675
19950
  return DirectDebitAPI.authenticate(params).then(function (response) {
19676
- _this4.logAPIResponse(response, paymentMethod);
19951
+ _this4.logAPIResponse(response, paymentMethod$1);
19677
19952
 
19678
19953
  return response;
19679
19954
  });
@@ -20117,6 +20392,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20117
20392
  this.subscription = data.subscription || null;
20118
20393
  this.planDetails = data.plan_details || null;
20119
20394
  this.exchangeRate = data.exchange_rate || null;
20395
+ this.savedCardsConfig = data.saved_cards || {};
20396
+ this.savedCardsToken = null;
20120
20397
  /**
20121
20398
  * We initialize parameters we send to the API as empty strings
20122
20399
  * when we don't have them instead of null because the API expects
@@ -20457,6 +20734,417 @@ var Toolkit = /*#__PURE__*/function () {
20457
20734
  return Toolkit;
20458
20735
  }();
20459
20736
 
20737
+ cardValidator.creditCardType.addCard({
20738
+ niceType: 'Verve',
20739
+ type: 'verve',
20740
+ patterns: [[506000, 507999], [650000, 650009]],
20741
+ gaps: [4, 8, 12, 16],
20742
+ lengths: [16, 18, 19],
20743
+ code: {
20744
+ name: 'CVV',
20745
+ size: 3
20746
+ }
20747
+ });
20748
+ cardValidator.creditCardType.changeOrder('verve', 0);
20749
+
20750
+ var Card = /*#__PURE__*/function () {
20751
+ function Card(_ref) {
20752
+ var number = _ref.number,
20753
+ cvv = _ref.cvv,
20754
+ month = _ref.month,
20755
+ year = _ref.year,
20756
+ pin = _ref.pin;
20757
+
20758
+ _classCallCheck(this, Card);
20759
+
20760
+ this.number = number;
20761
+ this.cvv = cvv;
20762
+ this.month = month;
20763
+ this.year = year;
20764
+ this.pin = pin;
20765
+ }
20766
+
20767
+ _createClass(Card, [{
20768
+ key: "getEncryptedPin",
20769
+ value: function getEncryptedPin() {
20770
+ return Card$2.getEncryptedPin(this.pin);
20771
+ }
20772
+ }, {
20773
+ key: "getLast4",
20774
+ value: function getLast4() {
20775
+ return Card$2.getLast4(this.number);
20776
+ }
20777
+ }, {
20778
+ key: "tokenize",
20779
+ value: function tokenize() {
20780
+ return Card$2.tokenize({
20781
+ number: this.number,
20782
+ cvv: this.cvv,
20783
+ month: this.month,
20784
+ year: this.year
20785
+ });
20786
+ }
20787
+ }], [{
20788
+ key: "getType",
20789
+ value: function getType(value) {
20790
+ return Card$2.getType(value);
20791
+ }
20792
+ }, {
20793
+ key: "validate",
20794
+ value: function validate(_ref2) {
20795
+ var number = _ref2.number,
20796
+ cvv = _ref2.cvv,
20797
+ month = _ref2.month,
20798
+ year = _ref2.year;
20799
+ return Card$2.validate({
20800
+ number: number,
20801
+ cvv: cvv,
20802
+ month: month,
20803
+ year: year
20804
+ });
20805
+ }
20806
+ }, {
20807
+ key: "validateNumber",
20808
+ value: function validateNumber(value) {
20809
+ return Card$2.validateNumber(value);
20810
+ }
20811
+ }, {
20812
+ key: "isNumberValid",
20813
+ value: function isNumberValid(value) {
20814
+ return Card$2.isNumberValid(value);
20815
+ }
20816
+ }, {
20817
+ key: "validateCVV",
20818
+ value: function validateCVV(cvv, cardType) {
20819
+ return Card$2.validateCVV(cvv, cardType);
20820
+ }
20821
+ }, {
20822
+ key: "isCvvValid",
20823
+ value: function isCvvValid(cvv, cardType) {
20824
+ return Card$2.isCvvValid(cvv, cardType);
20825
+ }
20826
+ }, {
20827
+ key: "validateExpiry",
20828
+ value: function validateExpiry(value) {
20829
+ return Card$2.validateExpiry(value);
20830
+ }
20831
+ }, {
20832
+ key: "isExpiryValid",
20833
+ value: function isExpiryValid(value) {
20834
+ return Card$2.isExpiryValid(value);
20835
+ }
20836
+ }, {
20837
+ key: "generateTestCard",
20838
+ value: function generateTestCard(cardType) {
20839
+ var type = cardType || 'default';
20840
+ var cardParams = testCards.find(function (card) {
20841
+ return card.type === type;
20842
+ });
20843
+ return new Card(cardParams);
20844
+ }
20845
+ }]);
20846
+
20847
+ return Card;
20848
+ }();
20849
+
20850
+ var CardAPI = {
20851
+ reserve: function reserve(_ref) {
20852
+ var clientdata = _ref.clientdata,
20853
+ last4 = _ref.last4,
20854
+ preauthorizationId = _ref.preauthorizationId;
20855
+ var url = "".concat(configToUse.paystackApiUrl, "preauthorization/reserve");
20856
+ var language = getLanguage();
20857
+
20858
+ var headers = _objectSpread2({}, language && {
20859
+ 'Accept-Language': language
20860
+ });
20861
+
20862
+ return axiosInstance.post(url, {
20863
+ clientdata: clientdata,
20864
+ last4: last4,
20865
+ preauthorization: preauthorizationId
20866
+ }, {
20867
+ headers: headers
20868
+ }).then(function (response) {
20869
+ return ChargeResponses.parse(response.data);
20870
+ });
20871
+ } // charge({
20872
+ // clientdata,
20873
+ // last4,
20874
+ // pin,
20875
+ // trans,
20876
+ // device,
20877
+ // rememberCard,
20878
+ // transactionType,
20879
+ // subscription,
20880
+ // customFields,
20881
+ // }) {
20882
+ // const url = `${config.paymentBaseUrl}charge/`;
20883
+ // const language = getLanguage();
20884
+ // const headers = {
20885
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20886
+ // ...(language && { 'Accept-Language': language }),
20887
+ // };
20888
+ // const chargeParams = {
20889
+ // clientdata,
20890
+ // last4,
20891
+ // trans,
20892
+ // device,
20893
+ // offset: new Date().getTimezoneOffset(),
20894
+ // remember_card: rememberCard,
20895
+ // ...(transactionType && { transaction_type: transactionType }),
20896
+ // ...(subscription && { subscription }),
20897
+ // ...(customFields && customFields),
20898
+ // };
20899
+ // if (pin) {
20900
+ // chargeParams.handle = pin;
20901
+ // }
20902
+ // const urlEncodedParams = formurlencoded(chargeParams);
20903
+ // return axiosInstance
20904
+ // .post(url, urlEncodedParams, { headers })
20905
+ // .then((response) => ChargeResponses.parse(response.data));
20906
+ // },
20907
+ // resumeCardCharge({ device, accessCode, pin }) {
20908
+ // const url = `${config.paymentBaseUrl}charge/resume/${accessCode}`;
20909
+ // const language = getLanguage();
20910
+ // const headers = {
20911
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20912
+ // ...(language && { 'Accept-Language': language }),
20913
+ // };
20914
+ // const data = { device, ...(pin && { handle: pin }) };
20915
+ // const urlEncodedData = formurlencoded(data);
20916
+ // return axiosInstance
20917
+ // .post(url, urlEncodedData, { headers })
20918
+ // .then((response) => ChargeResponses.parse(response.data));
20919
+ // },
20920
+ // chargeRememberedCard({
20921
+ // last4,
20922
+ // trans,
20923
+ // device,
20924
+ // authorizationCode,
20925
+ // cvv,
20926
+ // pin,
20927
+ // transactionType,
20928
+ // subscription,
20929
+ // }) {
20930
+ // const url = `${config.paymentBaseUrl}charge/`;
20931
+ // const language = getLanguage();
20932
+ // const headers = {
20933
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20934
+ // ...(language && { 'Accept-Language': language }),
20935
+ // };
20936
+ // const chargeParams = {
20937
+ // last4,
20938
+ // trans,
20939
+ // device,
20940
+ // cvv,
20941
+ // handle: pin,
20942
+ // authorization_code: authorizationCode,
20943
+ // ...(transactionType && { transaction_type: transactionType }),
20944
+ // ...(subscription && { subscription }),
20945
+ // };
20946
+ // const urlEncodedParams = formurlencoded(chargeParams);
20947
+ // return axiosInstance
20948
+ // .post(url, urlEncodedParams, { headers })
20949
+ // .then((response) => ChargeResponses.parse(response.data));
20950
+ // },
20951
+ // verifyAddress({ address, city, state, zipCode, transactionId }) {
20952
+ // const url = `${config.paymentBaseUrl}charge/avs`;
20953
+ // const language = getLanguage();
20954
+ // const headers = {
20955
+ // 'Content-Type': 'application/x-www-form-urlencoded',
20956
+ // ...(language && { 'Accept-Language': language }),
20957
+ // };
20958
+ // const data = {
20959
+ // city,
20960
+ // state,
20961
+ // address,
20962
+ // zip_code: zipCode,
20963
+ // trans: transactionId,
20964
+ // };
20965
+ // const urlEncodedData = formurlencoded(data);
20966
+ // return axiosInstance
20967
+ // .post(url, urlEncodedData, { headers })
20968
+ // .then((response) => ChargeResponses.parse(response.data));
20969
+ // },
20970
+ // forgetRememberedCard({ authorizationId, publicKey }) {
20971
+ // const language = getLanguage();
20972
+ // const headers = {
20973
+ // Authorization: `Bearer ${publicKey}`,
20974
+ // ...(language && { 'Accept-Language': language }),
20975
+ // };
20976
+ // const params = {
20977
+ // authorization_id: authorizationId,
20978
+ // };
20979
+ // const url = `${config.paystackApiUrl}rememberme/forget_card`;
20980
+ // return axiosInstance
20981
+ // .post(url, params, { headers })
20982
+ // .then((response) => ChargeResponses.parse(response.data));
20983
+ // },
20984
+
20985
+ };
20986
+
20987
+ var paymentMethod = 'card';
20988
+
20989
+ function validate(card, isSetter) {
20990
+ return new Promise(function (resolve, reject) {
20991
+ var validation = Card.validate(card);
20992
+
20993
+ if (!validation.isValid) {
20994
+ var throwValidation = isSetter || card.number;
20995
+ var errors = Object.keys(validation.result).filter(function (value) {
20996
+ return validation.result[value] === false;
20997
+ });
20998
+ var errorMessage = "Invalid card details: ".concat(errors.join(', '));
20999
+ reject(Error(throwValidation ? errorMessage : 'Please set a valid card with setCard()'));
21000
+ }
21001
+
21002
+ resolve();
21003
+ });
21004
+ }
21005
+
21006
+ var ReserveCardFunds = {
21007
+ setCard: function setCard(params) {
21008
+ var _this = this;
21009
+
21010
+ return validate(params, true).then(function () {
21011
+ _this.card = new Card(params);
21012
+ });
21013
+ },
21014
+ reserve: function reserve(preauthorizationId) {
21015
+ var _this2 = this;
21016
+
21017
+ var customFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21018
+ // TODO: Log payment method
21019
+ // https://paystack.atlassian.net/browse/RAILS-3070
21020
+ return validate(this.card).then(function () {
21021
+ var chargeParams = {
21022
+ clientdata: _this2.card.tokenize(),
21023
+ last4: _this2.card.getLast4(),
21024
+ preauthorization: preauthorizationId,
21025
+ customFields: customFields
21026
+ };
21027
+ return CardAPI.charge(chargeParams).then(function (response) {
21028
+ // TODO: Log API Response
21029
+ // https://paystack.atlassian.net/browse/RAILS-3070
21030
+ return response;
21031
+ });
21032
+ });
21033
+ },
21034
+ listenFor3DSCharge: function listenFor3DSCharge(callback) {
21035
+ var listenerOptions = {
21036
+ channel: "3DS_".concat(this.id),
21037
+ paymentMethod: paymentMethod
21038
+ };
21039
+ return this.listenForCharge(listenerOptions, callback);
21040
+ } // rememberCard() {
21041
+ // this.remember_card = true;
21042
+ // },
21043
+ // chargeCard(customFields = {}) {
21044
+ // if (!this.card.number && this.card.pin) {
21045
+ // return this.chargeCardWithPin(customFields);
21046
+ // }
21047
+ // return validate(this.card).then(() => {
21048
+ // this.logAttempt(paymentMethod);
21049
+ // const chargeParams = {
21050
+ // clientdata: this.card.tokenize(),
21051
+ // last4: this.card.getLast4(),
21052
+ // pin: this.card.getEncryptedPin(),
21053
+ // trans: this.id,
21054
+ // device: this.deviceFingerprint,
21055
+ // rememberCard: this.remember_card,
21056
+ // transactionType: this.transactionType,
21057
+ // subscription: this.subscription,
21058
+ // customFields,
21059
+ // };
21060
+ // return CardAPI.charge(chargeParams).then((response) => {
21061
+ // this.logAPIResponse(response, paymentMethod);
21062
+ // return response;
21063
+ // });
21064
+ // });
21065
+ // },
21066
+
21067
+ /**
21068
+ * Handles submitting a card pin after
21069
+ * other card details have been previously submitted.
21070
+ */
21071
+ // chargeCardWithPin(customFields = {}) {
21072
+ // this.logAttempt(paymentMethod);
21073
+ // const chargeParams = {
21074
+ // pin: encrypt(this.card.pin),
21075
+ // trans: this.id,
21076
+ // device: this.deviceFingerprint,
21077
+ // rememberCard: this.remember_card,
21078
+ // transactionType: this.transactionType,
21079
+ // subscription: this.subscription,
21080
+ // customFields,
21081
+ // };
21082
+ // return CardAPI.charge(chargeParams).then((response) => {
21083
+ // this.logAPIResponse(response, paymentMethod);
21084
+ // return response;
21085
+ // });
21086
+ // },
21087
+ // chargeRememberedCard({ cvv, authorizationCode, cardLast4, pin }) {
21088
+ // this.logAttempt(paymentMethod);
21089
+ // const encryptedPin = encrypt(pin);
21090
+ // const chargeParams = {
21091
+ // authorizationCode,
21092
+ // cvv,
21093
+ // last4: cardLast4,
21094
+ // trans: this.id,
21095
+ // device: this.deviceFingerprint,
21096
+ // pin: encryptedPin,
21097
+ // transactionType: this.transactionType,
21098
+ // subscription: this.subscription,
21099
+ // };
21100
+ // return CardAPI.chargeRememberedCard(chargeParams).then((response) => {
21101
+ // this.logAPIResponse(response, paymentMethod);
21102
+ // return response;
21103
+ // });
21104
+ // },
21105
+ // resumeCardCharge({ accessCode, pin }) {
21106
+ // const params = {
21107
+ // ...(pin && { pin: encrypt(pin) }),
21108
+ // accessCode,
21109
+ // device: this.deviceFingerprint,
21110
+ // };
21111
+ // return CardAPI.resumeCardCharge(params).then((response) => {
21112
+ // this.logAPIResponse(response, paymentMethod);
21113
+ // return response;
21114
+ // });
21115
+ // },
21116
+ // forgetRememberedCard(authorizationId) {
21117
+ // const params = {
21118
+ // authorizationId,
21119
+ // publicKey: this.merchant.key,
21120
+ // };
21121
+ // return CardAPI.forgetRememberedCard(params).then((response) => {
21122
+ // this.logAPIResponse(response, paymentMethod);
21123
+ // return response;
21124
+ // });
21125
+ // },
21126
+ // authenticateCard(token) {
21127
+ // return CardAPI.authenticate(this.id, token).then((response) => {
21128
+ // this.logAPIResponse(response, paymentMethod);
21129
+ // return response;
21130
+ // });
21131
+ // },
21132
+ // verifyAddress({ address, city, state, zipCode }) {
21133
+ // const payload = {
21134
+ // city,
21135
+ // state,
21136
+ // address,
21137
+ // zipCode,
21138
+ // transactionId: this.id,
21139
+ // };
21140
+ // return CardAPI.verifyAddress(payload).then((response) => {
21141
+ // this.logAPIResponse(response, paymentMethod);
21142
+ // return response;
21143
+ // });
21144
+ // },
21145
+
21146
+ };
21147
+
20460
21148
  var PreauthorizationInstance = /*#__PURE__*/function () {
20461
21149
  function PreauthorizationInstance(data) {
20462
21150
  _classCallCheck(this, PreauthorizationInstance);
@@ -20476,8 +21164,10 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20476
21164
  name: data.merchant_name,
20477
21165
  key: data.merchant_key
20478
21166
  };
20479
- loadPusher(); // TODO: Bind charge function to card channel
20480
- // https://paystack.atlassian.net/browse/RAILS-2887
21167
+ loadPusher(); // TODO: Analytics
21168
+ // https://paystack.atlassian.net/browse/RAILS-3070
21169
+
21170
+ Object.assign(this, ReserveCardFunds);
20481
21171
  }
20482
21172
 
20483
21173
  _createClass(PreauthorizationInstance, [{
@@ -20558,4 +21248,4 @@ var Preauthorization = {
20558
21248
  }
20559
21249
  };
20560
21250
 
20561
- export { BankAccount, Card, Preauthorization, Toolkit, Transaction };
21251
+ export { BankAccount, Card$1 as Card, Preauthorization, Toolkit, Transaction };