@paystack/checkout-js 1.21.0 → 1.22.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/',
@@ -18664,6 +18666,208 @@ var CardAPI$1 = {
18664
18666
  }).then(function (response) {
18665
18667
  return ChargeResponses.parse(response.data);
18666
18668
  });
18669
+ },
18670
+ sendSavedCardsOTP: function sendSavedCardsOTP(email) {
18671
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18672
+ var url, language, headers, _yield$axiosInstance$, data;
18673
+
18674
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18675
+ while (1) {
18676
+ switch (_context.prev = _context.next) {
18677
+ case 0:
18678
+ url = new URL("/authorize", configToUse.savedCardsApiUrl).toString();
18679
+ language = getLanguage();
18680
+ headers = _objectSpread2({}, language && {
18681
+ 'Accept-Language': language
18682
+ });
18683
+ _context.next = 5;
18684
+ return axiosInstance.post(url, {
18685
+ email: email
18686
+ }, {
18687
+ headers: headers
18688
+ });
18689
+
18690
+ case 5:
18691
+ _yield$axiosInstance$ = _context.sent;
18692
+ data = _yield$axiosInstance$.data;
18693
+ return _context.abrupt("return", data);
18694
+
18695
+ case 8:
18696
+ case "end":
18697
+ return _context.stop();
18698
+ }
18699
+ }
18700
+ }, _callee);
18701
+ }))();
18702
+ },
18703
+ addUserToSavedCards: function addUserToSavedCards(_ref6) {
18704
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18705
+ var phone, email, url, language, headers, data, response;
18706
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18707
+ while (1) {
18708
+ switch (_context2.prev = _context2.next) {
18709
+ case 0:
18710
+ phone = _ref6.phone, email = _ref6.email;
18711
+ url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18712
+ language = getLanguage();
18713
+ headers = _objectSpread2({}, language && {
18714
+ 'Accept-Language': language
18715
+ });
18716
+ data = {
18717
+ phone: phone,
18718
+ email: email
18719
+ };
18720
+ _context2.next = 7;
18721
+ return axiosInstance.post(url, data, {
18722
+ headers: headers
18723
+ });
18724
+
18725
+ case 7:
18726
+ response = _context2.sent;
18727
+ return _context2.abrupt("return", response.data);
18728
+
18729
+ case 9:
18730
+ case "end":
18731
+ return _context2.stop();
18732
+ }
18733
+ }
18734
+ }, _callee2);
18735
+ }))();
18736
+ },
18737
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18738
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18739
+ var code, transaction, url, language, headers, data, response;
18740
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18741
+ while (1) {
18742
+ switch (_context3.prev = _context3.next) {
18743
+ case 0:
18744
+ code = _ref7.code, transaction = _ref7.transaction;
18745
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18746
+ language = getLanguage();
18747
+ headers = _objectSpread2({}, language && {
18748
+ 'Accept-Language': language
18749
+ });
18750
+ data = {
18751
+ code: code,
18752
+ transaction: transaction
18753
+ };
18754
+ _context3.next = 7;
18755
+ return axiosInstance.post(url, data, {
18756
+ headers: headers
18757
+ });
18758
+
18759
+ case 7:
18760
+ response = _context3.sent;
18761
+ return _context3.abrupt("return", response.data);
18762
+
18763
+ case 9:
18764
+ case "end":
18765
+ return _context3.stop();
18766
+ }
18767
+ }
18768
+ }, _callee3);
18769
+ }))();
18770
+ },
18771
+ getSavedCards: function getSavedCards(_ref8) {
18772
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18773
+ var token, url, language, headers, response;
18774
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18775
+ while (1) {
18776
+ switch (_context4.prev = _context4.next) {
18777
+ case 0:
18778
+ token = _ref8.token;
18779
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18780
+ language = getLanguage();
18781
+ headers = _objectSpread2({
18782
+ Authorization: "Bearer ".concat(token),
18783
+ 'jwt-auth': true
18784
+ }, language && {
18785
+ 'Accept-Language': language
18786
+ });
18787
+ _context4.next = 6;
18788
+ return axiosInstance.get(url, {
18789
+ headers: headers
18790
+ });
18791
+
18792
+ case 6:
18793
+ response = _context4.sent;
18794
+ return _context4.abrupt("return", response.data);
18795
+
18796
+ case 8:
18797
+ case "end":
18798
+ return _context4.stop();
18799
+ }
18800
+ }
18801
+ }, _callee4);
18802
+ }))();
18803
+ },
18804
+ deleteSavedCard: function deleteSavedCard(_ref9) {
18805
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18806
+ var cardCode, token, url, language, headers, response;
18807
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18808
+ while (1) {
18809
+ switch (_context5.prev = _context5.next) {
18810
+ case 0:
18811
+ cardCode = _ref9.cardCode, token = _ref9.token;
18812
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18813
+ language = getLanguage();
18814
+ headers = _objectSpread2({
18815
+ Authorization: "Bearer ".concat(token),
18816
+ 'jwt-auth': true
18817
+ }, language && {
18818
+ 'Accept-Language': language
18819
+ });
18820
+ _context5.next = 6;
18821
+ return axiosInstance.delete(url, {
18822
+ headers: headers
18823
+ });
18824
+
18825
+ case 6:
18826
+ response = _context5.sent;
18827
+ return _context5.abrupt("return", response.data);
18828
+
18829
+ case 8:
18830
+ case "end":
18831
+ return _context5.stop();
18832
+ }
18833
+ }
18834
+ }, _callee5);
18835
+ }))();
18836
+ },
18837
+ chargeSavedCard: function chargeSavedCard(_ref10) {
18838
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18839
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18840
+ return regeneratorRuntime.wrap(function _callee6$(_context6) {
18841
+ while (1) {
18842
+ switch (_context6.prev = _context6.next) {
18843
+ case 0:
18844
+ token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18845
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18846
+ language = getLanguage();
18847
+ headers = _objectSpread2({
18848
+ Authorization: "Bearer ".concat(token),
18849
+ 'jwt-auth': true
18850
+ }, language && {
18851
+ 'Accept-Language': language
18852
+ });
18853
+ data = {
18854
+ device: device,
18855
+ transaction: transaction,
18856
+ selected_currency: selectedCurrency
18857
+ };
18858
+ return _context6.abrupt("return", axiosInstance.post(url, data, {
18859
+ headers: headers
18860
+ }).then(function (response) {
18861
+ return ChargeResponses.parse(response.data);
18862
+ }));
18863
+
18864
+ case 6:
18865
+ case "end":
18866
+ return _context6.stop();
18867
+ }
18868
+ }
18869
+ }, _callee6);
18870
+ }))();
18667
18871
  }
18668
18872
  };
18669
18873
 
@@ -18844,6 +19048,74 @@ var CardCharge = {
18844
19048
  paymentMethod: paymentMethod$4
18845
19049
  };
18846
19050
  return this.listenForCharge(listenerOptions, callback);
19051
+ },
19052
+ sendSavedCardsOTP: function sendSavedCardsOTP() {
19053
+ return CardAPI$1.sendSavedCardsOTP(this.email);
19054
+ },
19055
+ addUserToSavedCards: function addUserToSavedCards(_ref4) {
19056
+ var phone = _ref4.phone;
19057
+ return CardAPI$1.addUserToSavedCards({
19058
+ phone: phone,
19059
+ email: this.email
19060
+ });
19061
+ },
19062
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19063
+ var _this9 = this;
19064
+
19065
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19066
+ var code, payload, response;
19067
+ return regeneratorRuntime.wrap(function _callee$(_context) {
19068
+ while (1) {
19069
+ switch (_context.prev = _context.next) {
19070
+ case 0:
19071
+ code = _ref5.code;
19072
+ payload = {
19073
+ code: code,
19074
+ transaction: _this9.id
19075
+ };
19076
+ _context.prev = 2;
19077
+ _context.next = 5;
19078
+ return CardAPI$1.verifySavedCardsOtp(payload);
19079
+
19080
+ case 5:
19081
+ response = _context.sent;
19082
+ _this9.savedCardsToken = response.data.token;
19083
+ return _context.abrupt("return", response);
19084
+
19085
+ case 10:
19086
+ _context.prev = 10;
19087
+ _context.t0 = _context["catch"](2);
19088
+ _this9.savedCardsToken = null;
19089
+ throw _context.t0;
19090
+
19091
+ case 14:
19092
+ case "end":
19093
+ return _context.stop();
19094
+ }
19095
+ }
19096
+ }, _callee, null, [[2, 10]]);
19097
+ }))();
19098
+ },
19099
+ getSavedCards: function getSavedCards() {
19100
+ return CardAPI$1.getSavedCards({
19101
+ token: this.savedCardsToken
19102
+ });
19103
+ },
19104
+ deleteSavedCard: function deleteSavedCard(cardCode) {
19105
+ return CardAPI$1.deleteSavedCard({
19106
+ cardCode: cardCode,
19107
+ token: this.savedCardsToken
19108
+ });
19109
+ },
19110
+ chargeSavedCard: function chargeSavedCard(_ref6) {
19111
+ var cardCode = _ref6.cardCode;
19112
+ return CardAPI$1.chargeSavedCard({
19113
+ cardCode: cardCode,
19114
+ transaction: this.id,
19115
+ token: this.savedCardsToken,
19116
+ device: this.deviceFingerprint,
19117
+ selectedCurrency: this.currency
19118
+ });
18847
19119
  }
18848
19120
  };
18849
19121
 
@@ -20115,6 +20387,17 @@ var AnalyticsFunctions = {
20115
20387
  });
20116
20388
  return this.saveLog();
20117
20389
  },
20390
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20391
+ var currency = _ref3.currency,
20392
+ isUserAction = _ref3.isUserAction;
20393
+ var prefix = isUserAction ? 'User switched' : 'Switched';
20394
+ this.log.history.push({
20395
+ type: 'action',
20396
+ message: "".concat(prefix, " transaction currency to ").concat(currency),
20397
+ time: this.getTimeSpent()
20398
+ });
20399
+ return this.saveLog();
20400
+ },
20118
20401
  saveLog: function saveLog() {
20119
20402
  return AnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
20120
20403
  },
@@ -20172,6 +20455,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20172
20455
  this.subscription = data.subscription || null;
20173
20456
  this.planDetails = data.plan_details || null;
20174
20457
  this.exchangeRate = data.exchange_rate || null;
20458
+ this.savedCardsConfig = data.saved_cards || {};
20459
+ this.savedCardsToken = null;
20175
20460
  /**
20176
20461
  * We initialize parameters we send to the API as empty strings
20177
20462
  * when we don't have them instead of null because the API expects
@@ -20442,6 +20727,21 @@ var ToolkitAPI = {
20442
20727
  resolvedCardBins[bin] = data;
20443
20728
  return data;
20444
20729
  });
20730
+ },
20731
+ resolveIPAddress: function resolveIPAddress(ipAddress) {
20732
+ var url = new URL("decision/resolve_ip/".concat(ipAddress), configToUse.paystackApiUrl).toString();
20733
+ var language = getLanguage();
20734
+
20735
+ var headers = _objectSpread2({}, language && {
20736
+ 'Accept-Language': language
20737
+ });
20738
+
20739
+ return axiosInstance.get(url, {
20740
+ headers: headers
20741
+ }).then(function (_ref2) {
20742
+ var data = _ref2.data;
20743
+ return data;
20744
+ });
20445
20745
  }
20446
20746
  };
20447
20747
 
@@ -20507,6 +20807,11 @@ var Toolkit = /*#__PURE__*/function () {
20507
20807
  value: function resolveCardBin(bin) {
20508
20808
  return ToolkitAPI.resolveCardBin(bin);
20509
20809
  }
20810
+ }, {
20811
+ key: "resolveIPAddress",
20812
+ value: function resolveIPAddress(ipAddress) {
20813
+ return ToolkitAPI.resolveIPAddress(ipAddress);
20814
+ }
20510
20815
  }]);
20511
20816
 
20512
20817
  return Toolkit;
@@ -20744,6 +21049,7 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20744
21049
  this.customer = data.customer;
20745
21050
  this.channels = data.channels || ['card'];
20746
21051
  this.isListening = false;
21052
+ this.isTest = data.domain === 'test';
20747
21053
  this.merchant = {
20748
21054
  id: data.merchant_id,
20749
21055
  logo: data.merchant_logo,