@paystack/checkout-js 1.23.0 → 1.23.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
@@ -18665,30 +18665,34 @@ var CardAPI$1 = {
18665
18665
  return ChargeResponses.parse(response.data);
18666
18666
  });
18667
18667
  },
18668
- sendSavedCardsOTP: function sendSavedCardsOTP(transaction) {
18668
+ sendSavedCardsOTP: function sendSavedCardsOTP(_ref6) {
18669
18669
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18670
- var url, language, headers, response;
18670
+ var transaction, phone, url, language, headers, data, response;
18671
18671
  return regeneratorRuntime.wrap(function _callee$(_context) {
18672
18672
  while (1) {
18673
18673
  switch (_context.prev = _context.next) {
18674
18674
  case 0:
18675
+ transaction = _ref6.transaction, phone = _ref6.phone;
18675
18676
  url = new URL('/saved_cards/authorize', configToUse.paystackApiUrl).toString();
18676
18677
  language = getLanguage();
18677
18678
  headers = _objectSpread2({}, language && {
18678
18679
  'Accept-Language': language
18679
18680
  });
18680
- _context.next = 5;
18681
- return axiosInstance.post(url, {
18681
+ data = _objectSpread2(_objectSpread2({}, phone && {
18682
+ phone: phone
18683
+ }), {}, {
18682
18684
  transaction: transaction
18683
- }, {
18685
+ });
18686
+ _context.next = 7;
18687
+ return axiosInstance.post(url, data, {
18684
18688
  headers: headers
18685
18689
  });
18686
18690
 
18687
- case 5:
18691
+ case 7:
18688
18692
  response = _context.sent;
18689
18693
  return _context.abrupt("return", response.data);
18690
18694
 
18691
- case 7:
18695
+ case 9:
18692
18696
  case "end":
18693
18697
  return _context.stop();
18694
18698
  }
@@ -18696,21 +18700,23 @@ var CardAPI$1 = {
18696
18700
  }, _callee);
18697
18701
  }))();
18698
18702
  },
18699
- addUserToSavedCards: function addUserToSavedCards(_ref6) {
18703
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18700
18704
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18701
- var phone, transaction, url, language, headers, data, response;
18705
+ var code, transaction, token, url, language, headers, data, response;
18702
18706
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
18703
18707
  while (1) {
18704
18708
  switch (_context2.prev = _context2.next) {
18705
18709
  case 0:
18706
- phone = _ref6.phone, transaction = _ref6.transaction;
18707
- url = new URL('/saved_cards/user', configToUse.paystackApiUrl).toString();
18710
+ code = _ref7.code, transaction = _ref7.transaction, token = _ref7.token;
18711
+ url = new URL('/saved_cards/authorize/verify', configToUse.paystackApiUrl).toString();
18708
18712
  language = getLanguage();
18709
- headers = _objectSpread2({}, language && {
18713
+ headers = _objectSpread2({
18714
+ Authorization: "Bearer ".concat(token)
18715
+ }, language && {
18710
18716
  'Accept-Language': language
18711
18717
  });
18712
18718
  data = {
18713
- phone: phone,
18719
+ code: code,
18714
18720
  transaction: transaction
18715
18721
  };
18716
18722
  _context2.next = 7;
@@ -18730,46 +18736,12 @@ var CardAPI$1 = {
18730
18736
  }, _callee2);
18731
18737
  }))();
18732
18738
  },
18733
- verifySavedCardsOtp: function verifySavedCardsOtp(_ref7) {
18739
+ getSavedCards: function getSavedCards(_ref8) {
18734
18740
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18735
- var code, transaction, url, language, headers, data, response;
18741
+ var token, url, language, headers, response;
18736
18742
  return regeneratorRuntime.wrap(function _callee3$(_context3) {
18737
18743
  while (1) {
18738
18744
  switch (_context3.prev = _context3.next) {
18739
- case 0:
18740
- code = _ref7.code, transaction = _ref7.transaction;
18741
- url = new URL('/saved_cards/authorize/verify', configToUse.paystackApiUrl).toString();
18742
- language = getLanguage();
18743
- headers = _objectSpread2({}, language && {
18744
- 'Accept-Language': language
18745
- });
18746
- data = {
18747
- code: code,
18748
- transaction: transaction
18749
- };
18750
- _context3.next = 7;
18751
- return axiosInstance.post(url, data, {
18752
- headers: headers
18753
- });
18754
-
18755
- case 7:
18756
- response = _context3.sent;
18757
- return _context3.abrupt("return", response.data);
18758
-
18759
- case 9:
18760
- case "end":
18761
- return _context3.stop();
18762
- }
18763
- }
18764
- }, _callee3);
18765
- }))();
18766
- },
18767
- getSavedCards: function getSavedCards(_ref8) {
18768
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18769
- var token, url, language, headers, response;
18770
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
18771
- while (1) {
18772
- switch (_context4.prev = _context4.next) {
18773
18745
  case 0:
18774
18746
  token = _ref8.token;
18775
18747
  url = new URL('/saved_cards/cards', configToUse.paystackApiUrl).toString();
@@ -18780,29 +18752,29 @@ var CardAPI$1 = {
18780
18752
  }, language && {
18781
18753
  'Accept-Language': language
18782
18754
  });
18783
- _context4.next = 6;
18755
+ _context3.next = 6;
18784
18756
  return axiosInstance.get(url, {
18785
18757
  headers: headers
18786
18758
  });
18787
18759
 
18788
18760
  case 6:
18789
- response = _context4.sent;
18790
- return _context4.abrupt("return", response.data);
18761
+ response = _context3.sent;
18762
+ return _context3.abrupt("return", response.data);
18791
18763
 
18792
18764
  case 8:
18793
18765
  case "end":
18794
- return _context4.stop();
18766
+ return _context3.stop();
18795
18767
  }
18796
18768
  }
18797
- }, _callee4);
18769
+ }, _callee3);
18798
18770
  }))();
18799
18771
  },
18800
18772
  deleteSavedCard: function deleteSavedCard(_ref9) {
18801
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18773
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18802
18774
  var cardCode, token, url, language, headers, response;
18803
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
18775
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18804
18776
  while (1) {
18805
- switch (_context5.prev = _context5.next) {
18777
+ switch (_context4.prev = _context4.next) {
18806
18778
  case 0:
18807
18779
  cardCode = _ref9.cardCode, token = _ref9.token;
18808
18780
  url = new URL("/saved_cards/cards/".concat(cardCode), configToUse.paystackApiUrl).toString();
@@ -18813,29 +18785,29 @@ var CardAPI$1 = {
18813
18785
  }, language && {
18814
18786
  'Accept-Language': language
18815
18787
  });
18816
- _context5.next = 6;
18788
+ _context4.next = 6;
18817
18789
  return axiosInstance.delete(url, {
18818
18790
  headers: headers
18819
18791
  });
18820
18792
 
18821
18793
  case 6:
18822
- response = _context5.sent;
18823
- return _context5.abrupt("return", response.data);
18794
+ response = _context4.sent;
18795
+ return _context4.abrupt("return", response.data);
18824
18796
 
18825
18797
  case 8:
18826
18798
  case "end":
18827
- return _context5.stop();
18799
+ return _context4.stop();
18828
18800
  }
18829
18801
  }
18830
- }, _callee5);
18802
+ }, _callee4);
18831
18803
  }))();
18832
18804
  },
18833
18805
  chargeSavedCard: function chargeSavedCard(_ref10) {
18834
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18806
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18835
18807
  var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data, response;
18836
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
18808
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18837
18809
  while (1) {
18838
- switch (_context6.prev = _context6.next) {
18810
+ switch (_context5.prev = _context5.next) {
18839
18811
  case 0:
18840
18812
  token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18841
18813
  url = new URL("/saved_cards/cards/".concat(cardCode, "/charge"), configToUse.paystackApiUrl).toString();
@@ -18851,21 +18823,21 @@ var CardAPI$1 = {
18851
18823
  transaction: transaction,
18852
18824
  selected_currency: selectedCurrency
18853
18825
  };
18854
- _context6.next = 7;
18826
+ _context5.next = 7;
18855
18827
  return axiosInstance.post(url, data, {
18856
18828
  headers: headers
18857
18829
  });
18858
18830
 
18859
18831
  case 7:
18860
- response = _context6.sent;
18861
- return _context6.abrupt("return", ChargeResponses.parse(response.data));
18832
+ response = _context5.sent;
18833
+ return _context5.abrupt("return", ChargeResponses.parse(response.data));
18862
18834
 
18863
18835
  case 9:
18864
18836
  case "end":
18865
- return _context6.stop();
18837
+ return _context5.stop();
18866
18838
  }
18867
18839
  }
18868
- }, _callee6);
18840
+ }, _callee5);
18869
18841
  }))();
18870
18842
  }
18871
18843
  };
@@ -19048,51 +19020,77 @@ var CardCharge = {
19048
19020
  };
19049
19021
  return this.listenForCharge(listenerOptions, callback);
19050
19022
  },
19051
- sendSavedCardsOTP: function sendSavedCardsOTP() {
19052
- return CardAPI$1.sendSavedCardsOTP(this.id);
19053
- },
19054
- addUserToSavedCards: function addUserToSavedCards(_ref4) {
19055
- var phone = _ref4.phone;
19056
- return CardAPI$1.addUserToSavedCards({
19057
- phone: phone,
19058
- transaction: this.id
19059
- });
19060
- },
19061
- verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19023
+ sendSavedCardsOTP: function sendSavedCardsOTP(phone) {
19062
19024
  var _this9 = this;
19063
19025
 
19064
19026
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19065
- var code, payload, response;
19027
+ var response;
19066
19028
  return regeneratorRuntime.wrap(function _callee$(_context) {
19067
19029
  while (1) {
19068
19030
  switch (_context.prev = _context.next) {
19069
19031
  case 0:
19070
- code = _ref5.code;
19032
+ _context.prev = 0;
19033
+ _context.next = 3;
19034
+ return CardAPI$1.sendSavedCardsOTP({
19035
+ phone: phone,
19036
+ transaction: _this9.id
19037
+ });
19038
+
19039
+ case 3:
19040
+ response = _context.sent;
19041
+ _this9.savedCardsTempAuthToken = response.data.token;
19042
+ return _context.abrupt("return", response);
19043
+
19044
+ case 8:
19045
+ _context.prev = 8;
19046
+ _context.t0 = _context["catch"](0);
19047
+ _this9.savedCardsTempAuthToken = null;
19048
+ throw _context.t0;
19049
+
19050
+ case 12:
19051
+ case "end":
19052
+ return _context.stop();
19053
+ }
19054
+ }
19055
+ }, _callee, null, [[0, 8]]);
19056
+ }))();
19057
+ },
19058
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref4) {
19059
+ var _this10 = this;
19060
+
19061
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
19062
+ var code, payload, response;
19063
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
19064
+ while (1) {
19065
+ switch (_context2.prev = _context2.next) {
19066
+ case 0:
19067
+ code = _ref4.code;
19071
19068
  payload = {
19072
19069
  code: code,
19073
- transaction: _this9.id
19070
+ transaction: _this10.id,
19071
+ token: _this10.savedCardsTempAuthToken
19074
19072
  };
19075
- _context.prev = 2;
19076
- _context.next = 5;
19073
+ _context2.prev = 2;
19074
+ _context2.next = 5;
19077
19075
  return CardAPI$1.verifySavedCardsOtp(payload);
19078
19076
 
19079
19077
  case 5:
19080
- response = _context.sent;
19081
- _this9.savedCardsToken = response.data.token;
19082
- return _context.abrupt("return", response);
19078
+ response = _context2.sent;
19079
+ _this10.savedCardsToken = response.data.token;
19080
+ return _context2.abrupt("return", response);
19083
19081
 
19084
19082
  case 10:
19085
- _context.prev = 10;
19086
- _context.t0 = _context["catch"](2);
19087
- _this9.savedCardsToken = null;
19088
- throw _context.t0;
19083
+ _context2.prev = 10;
19084
+ _context2.t0 = _context2["catch"](2);
19085
+ _this10.savedCardsToken = null;
19086
+ throw _context2.t0;
19089
19087
 
19090
19088
  case 14:
19091
19089
  case "end":
19092
- return _context.stop();
19090
+ return _context2.stop();
19093
19091
  }
19094
19092
  }
19095
- }, _callee, null, [[2, 10]]);
19093
+ }, _callee2, null, [[2, 10]]);
19096
19094
  }))();
19097
19095
  },
19098
19096
  getSavedCards: function getSavedCards() {
@@ -19106,8 +19104,8 @@ var CardCharge = {
19106
19104
  token: this.savedCardsToken
19107
19105
  });
19108
19106
  },
19109
- chargeSavedCard: function chargeSavedCard(_ref6) {
19110
- var cardCode = _ref6.cardCode;
19107
+ chargeSavedCard: function chargeSavedCard(_ref5) {
19108
+ var cardCode = _ref5.cardCode;
19111
19109
  return CardAPI$1.chargeSavedCard({
19112
19110
  cardCode: cardCode,
19113
19111
  transaction: this.id,
@@ -20493,6 +20491,12 @@ var TransactionInstance = /*#__PURE__*/function () {
20493
20491
  this.planDetails = data.plan_details || null;
20494
20492
  this.exchangeRate = data.exchange_rate || null;
20495
20493
  this.savedCardsConfig = data.saved_cards || {};
20494
+ /**
20495
+ * savedCardsTempAuthToken: This token is issued on calling `authorize` and we pass it down to `authorize/verify` to ensure we only add users to saved cards only after a successful verification.
20496
+ * savedCardsToken: This token is issued after verification and is used for all saved card auth requests.
20497
+ */
20498
+
20499
+ this.savedCardsTempAuthToken = null;
20496
20500
  this.savedCardsToken = null;
20497
20501
  /**
20498
20502
  * We initialize parameters we send to the API as empty strings