@paystack/checkout-js 1.18.1 → 1.19.0-dev.10

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.private.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.private.paystack.studio/'
6414
6416
  });
6415
6417
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6416
6418
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -18564,6 +18566,173 @@ var CardAPI = {
18564
18566
  }).then(function (response) {
18565
18567
  return ChargeResponses.parse(response.data);
18566
18568
  });
18569
+ },
18570
+ requestOtpForSavedCards: function requestOtpForSavedCards(phoneNumber) {
18571
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18572
+ var url, language, headers, _yield$axiosInstance$, data;
18573
+
18574
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18575
+ while (1) {
18576
+ switch (_context.prev = _context.next) {
18577
+ case 0:
18578
+ url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18579
+ language = getLanguage();
18580
+ headers = _objectSpread2({}, language && {
18581
+ 'Accept-Language': language
18582
+ });
18583
+ _context.next = 5;
18584
+ return axiosInstance.post(url, {
18585
+ headers: headers
18586
+ });
18587
+
18588
+ case 5:
18589
+ _yield$axiosInstance$ = _context.sent;
18590
+ data = _yield$axiosInstance$.data;
18591
+ return _context.abrupt("return", data);
18592
+
18593
+ case 8:
18594
+ case "end":
18595
+ return _context.stop();
18596
+ }
18597
+ }
18598
+ }, _callee);
18599
+ }))();
18600
+ },
18601
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref6) {
18602
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18603
+ var code, phone, transaction, url, language, headers, data, response;
18604
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18605
+ while (1) {
18606
+ switch (_context2.prev = _context2.next) {
18607
+ case 0:
18608
+ code = _ref6.code, phone = _ref6.phone, transaction = _ref6.transaction;
18609
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18610
+ language = getLanguage();
18611
+ headers = _objectSpread2({}, language && {
18612
+ 'Accept-Language': language
18613
+ });
18614
+ data = {
18615
+ code: code,
18616
+ phone: phone,
18617
+ transaction: transaction
18618
+ };
18619
+ _context2.next = 7;
18620
+ return axiosInstance.post(url, data, {
18621
+ headers: headers
18622
+ });
18623
+
18624
+ case 7:
18625
+ response = _context2.sent;
18626
+ return _context2.abrupt("return", response.data);
18627
+
18628
+ case 9:
18629
+ case "end":
18630
+ return _context2.stop();
18631
+ }
18632
+ }
18633
+ }, _callee2);
18634
+ }))();
18635
+ },
18636
+ getSavedCards: function getSavedCards(_ref7) {
18637
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18638
+ var token, url, language, headers, response;
18639
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18640
+ while (1) {
18641
+ switch (_context3.prev = _context3.next) {
18642
+ case 0:
18643
+ token = _ref7.token;
18644
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18645
+ language = getLanguage();
18646
+ headers = _objectSpread2({
18647
+ Authorization: "Bearer ".concat(token),
18648
+ 'jwt-auth': true
18649
+ }, language && {
18650
+ 'Accept-Language': language
18651
+ });
18652
+ _context3.next = 6;
18653
+ return axiosInstance.get(url, {
18654
+ headers: headers
18655
+ });
18656
+
18657
+ case 6:
18658
+ response = _context3.sent;
18659
+ return _context3.abrupt("return", response.data);
18660
+
18661
+ case 8:
18662
+ case "end":
18663
+ return _context3.stop();
18664
+ }
18665
+ }
18666
+ }, _callee3);
18667
+ }))();
18668
+ },
18669
+ deleteSavedCard: function deleteSavedCard(_ref8) {
18670
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18671
+ var cardCode, token, url, language, headers, response;
18672
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18673
+ while (1) {
18674
+ switch (_context4.prev = _context4.next) {
18675
+ case 0:
18676
+ cardCode = _ref8.cardCode, token = _ref8.token;
18677
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18678
+ language = getLanguage();
18679
+ headers = _objectSpread2({
18680
+ Authorization: "Bearer ".concat(token),
18681
+ 'jwt-auth': true
18682
+ }, language && {
18683
+ 'Accept-Language': language
18684
+ });
18685
+ _context4.next = 6;
18686
+ return axiosInstance.delete(url, {
18687
+ headers: headers
18688
+ });
18689
+
18690
+ case 6:
18691
+ response = _context4.sent;
18692
+ return _context4.abrupt("return", response.data);
18693
+
18694
+ case 8:
18695
+ case "end":
18696
+ return _context4.stop();
18697
+ }
18698
+ }
18699
+ }, _callee4);
18700
+ }))();
18701
+ },
18702
+ chargeSavedCard: function chargeSavedCard(_ref9) {
18703
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18704
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18705
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18706
+ while (1) {
18707
+ switch (_context5.prev = _context5.next) {
18708
+ case 0:
18709
+ token = _ref9.token, device = _ref9.device, cardCode = _ref9.cardCode, transaction = _ref9.transaction, selectedCurrency = _ref9.selectedCurrency;
18710
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18711
+ language = getLanguage();
18712
+ headers = _objectSpread2({
18713
+ Authorization: "Bearer ".concat(token),
18714
+ 'jwt-auth': true
18715
+ }, language && {
18716
+ 'Accept-Language': language
18717
+ });
18718
+ data = {
18719
+ device: device,
18720
+ transaction: transaction,
18721
+ selectedCurrency: selectedCurrency
18722
+ };
18723
+ return _context5.abrupt("return", axiosInstance.post(url, data, {
18724
+ headers: headers
18725
+ }).then(function (response) {
18726
+ return ChargeResponses.parse(response.data);
18727
+ }));
18728
+
18729
+ case 6:
18730
+ case "end":
18731
+ return _context5.stop();
18732
+ }
18733
+ }
18734
+ }, _callee5);
18735
+ }))();
18567
18736
  }
18568
18737
  };
18569
18738
 
@@ -18744,6 +18913,68 @@ var CardCharge = {
18744
18913
  paymentMethod: paymentMethod$3
18745
18914
  };
18746
18915
  return this.listenForCharge(listenerOptions, callback);
18916
+ },
18917
+ requestOtpForSavedCards: function requestOtpForSavedCards(phoneNumber) {
18918
+ return CardAPI.requestOtpForSavedCards(phoneNumber);
18919
+ },
18920
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref4) {
18921
+ var _this9 = this;
18922
+
18923
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18924
+ var code, phone, payload, response;
18925
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18926
+ while (1) {
18927
+ switch (_context.prev = _context.next) {
18928
+ case 0:
18929
+ code = _ref4.code, phone = _ref4.phone;
18930
+ payload = {
18931
+ code: code,
18932
+ phone: phone,
18933
+ transaction: _this9.id
18934
+ };
18935
+ _context.prev = 2;
18936
+ _context.next = 5;
18937
+ return CardAPI.verifySavedCardsOtp(payload);
18938
+
18939
+ case 5:
18940
+ response = _context.sent;
18941
+ _this9.savedCardsToken = response.data.token;
18942
+ return _context.abrupt("return", response);
18943
+
18944
+ case 10:
18945
+ _context.prev = 10;
18946
+ _context.t0 = _context["catch"](2);
18947
+ _this9.savedCardsToken = null;
18948
+ throw new Error(_context.t0);
18949
+
18950
+ case 14:
18951
+ case "end":
18952
+ return _context.stop();
18953
+ }
18954
+ }
18955
+ }, _callee, null, [[2, 10]]);
18956
+ }))();
18957
+ },
18958
+ getSavedCards: function getSavedCards() {
18959
+ return CardAPI.getSavedCards({
18960
+ token: this.savedCardsToken
18961
+ });
18962
+ },
18963
+ deleteSavedCard: function deleteSavedCard(cardCode) {
18964
+ return CardAPI.deleteSavedCard({
18965
+ cardCode: cardCode,
18966
+ token: this.savedCardsToken
18967
+ });
18968
+ },
18969
+ chargeSavedCard: function chargeSavedCard(_ref5) {
18970
+ var cardCode = _ref5.cardCode;
18971
+ return CardAPI.chargeSavedCard({
18972
+ cardCode: cardCode,
18973
+ transaction: this.id,
18974
+ token: this.savedCardsToken,
18975
+ device: this.deviceFingerprint,
18976
+ selectedCurrency: this.currency
18977
+ });
18747
18978
  }
18748
18979
  };
18749
18980
 
@@ -20072,6 +20303,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20072
20303
  this.subscription = data.subscription || null;
20073
20304
  this.planDetails = data.plan_details || null;
20074
20305
  this.exchangeRate = data.exchange_rate || null;
20306
+ this.savedCardsToken = null;
20307
+ this.isSavedCardsEnabled = data.saved_cards && data.saved_cards.enabled || null;
20075
20308
  /**
20076
20309
  * We initialize parameters we send to the API as empty strings
20077
20310
  * when we don't have them instead of null because the API expects
package/lib/checkout.js CHANGED
@@ -6407,14 +6407,16 @@ var devConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6407
6407
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6408
6408
  paystackApiUrl: 'https://studio-api.paystack.co/',
6409
6409
  pusherKey: '1c7b262ee18455815893',
6410
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6410
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6411
+ savedCardsApiUrl: 'https://saved-cards-api.private.paystack.studio/'
6411
6412
  });
6412
6413
  var stagingConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6413
6414
  checkoutUrl: 'https://checkout-studio.paystack.com/',
6414
6415
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6415
6416
  paystackApiUrl: 'https://studio-api.paystack.co/',
6416
6417
  pusherKey: '1c7b262ee18455815893',
6417
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6418
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6419
+ savedCardsApiUrl: 'https://saved-cards-api.private.paystack.studio/'
6418
6420
  });
6419
6421
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6420
6422
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -18568,6 +18570,173 @@ var CardAPI = {
18568
18570
  }).then(function (response) {
18569
18571
  return ChargeResponses.parse(response.data);
18570
18572
  });
18573
+ },
18574
+ requestOtpForSavedCards: function requestOtpForSavedCards(phoneNumber) {
18575
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18576
+ var url, language, headers, _yield$axiosInstance$, data;
18577
+
18578
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18579
+ while (1) {
18580
+ switch (_context.prev = _context.next) {
18581
+ case 0:
18582
+ url = new URL("/authorize/".concat(phoneNumber), configToUse.savedCardsApiUrl).toString();
18583
+ language = getLanguage();
18584
+ headers = _objectSpread2({}, language && {
18585
+ 'Accept-Language': language
18586
+ });
18587
+ _context.next = 5;
18588
+ return axiosInstance.post(url, {
18589
+ headers: headers
18590
+ });
18591
+
18592
+ case 5:
18593
+ _yield$axiosInstance$ = _context.sent;
18594
+ data = _yield$axiosInstance$.data;
18595
+ return _context.abrupt("return", data);
18596
+
18597
+ case 8:
18598
+ case "end":
18599
+ return _context.stop();
18600
+ }
18601
+ }
18602
+ }, _callee);
18603
+ }))();
18604
+ },
18605
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref6) {
18606
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18607
+ var code, phone, transaction, url, language, headers, data, response;
18608
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
18609
+ while (1) {
18610
+ switch (_context2.prev = _context2.next) {
18611
+ case 0:
18612
+ code = _ref6.code, phone = _ref6.phone, transaction = _ref6.transaction;
18613
+ url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18614
+ language = getLanguage();
18615
+ headers = _objectSpread2({}, language && {
18616
+ 'Accept-Language': language
18617
+ });
18618
+ data = {
18619
+ code: code,
18620
+ phone: phone,
18621
+ transaction: transaction
18622
+ };
18623
+ _context2.next = 7;
18624
+ return axiosInstance.post(url, data, {
18625
+ headers: headers
18626
+ });
18627
+
18628
+ case 7:
18629
+ response = _context2.sent;
18630
+ return _context2.abrupt("return", response.data);
18631
+
18632
+ case 9:
18633
+ case "end":
18634
+ return _context2.stop();
18635
+ }
18636
+ }
18637
+ }, _callee2);
18638
+ }))();
18639
+ },
18640
+ getSavedCards: function getSavedCards(_ref7) {
18641
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
18642
+ var token, url, language, headers, response;
18643
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
18644
+ while (1) {
18645
+ switch (_context3.prev = _context3.next) {
18646
+ case 0:
18647
+ token = _ref7.token;
18648
+ url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18649
+ language = getLanguage();
18650
+ headers = _objectSpread2({
18651
+ Authorization: "Bearer ".concat(token),
18652
+ 'jwt-auth': true
18653
+ }, language && {
18654
+ 'Accept-Language': language
18655
+ });
18656
+ _context3.next = 6;
18657
+ return axiosInstance.get(url, {
18658
+ headers: headers
18659
+ });
18660
+
18661
+ case 6:
18662
+ response = _context3.sent;
18663
+ return _context3.abrupt("return", response.data);
18664
+
18665
+ case 8:
18666
+ case "end":
18667
+ return _context3.stop();
18668
+ }
18669
+ }
18670
+ }, _callee3);
18671
+ }))();
18672
+ },
18673
+ deleteSavedCard: function deleteSavedCard(_ref8) {
18674
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
18675
+ var cardCode, token, url, language, headers, response;
18676
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
18677
+ while (1) {
18678
+ switch (_context4.prev = _context4.next) {
18679
+ case 0:
18680
+ cardCode = _ref8.cardCode, token = _ref8.token;
18681
+ url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18682
+ language = getLanguage();
18683
+ headers = _objectSpread2({
18684
+ Authorization: "Bearer ".concat(token),
18685
+ 'jwt-auth': true
18686
+ }, language && {
18687
+ 'Accept-Language': language
18688
+ });
18689
+ _context4.next = 6;
18690
+ return axiosInstance.delete(url, {
18691
+ headers: headers
18692
+ });
18693
+
18694
+ case 6:
18695
+ response = _context4.sent;
18696
+ return _context4.abrupt("return", response.data);
18697
+
18698
+ case 8:
18699
+ case "end":
18700
+ return _context4.stop();
18701
+ }
18702
+ }
18703
+ }, _callee4);
18704
+ }))();
18705
+ },
18706
+ chargeSavedCard: function chargeSavedCard(_ref9) {
18707
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
18708
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18709
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
18710
+ while (1) {
18711
+ switch (_context5.prev = _context5.next) {
18712
+ case 0:
18713
+ token = _ref9.token, device = _ref9.device, cardCode = _ref9.cardCode, transaction = _ref9.transaction, selectedCurrency = _ref9.selectedCurrency;
18714
+ url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18715
+ language = getLanguage();
18716
+ headers = _objectSpread2({
18717
+ Authorization: "Bearer ".concat(token),
18718
+ 'jwt-auth': true
18719
+ }, language && {
18720
+ 'Accept-Language': language
18721
+ });
18722
+ data = {
18723
+ device: device,
18724
+ transaction: transaction,
18725
+ selectedCurrency: selectedCurrency
18726
+ };
18727
+ return _context5.abrupt("return", axiosInstance.post(url, data, {
18728
+ headers: headers
18729
+ }).then(function (response) {
18730
+ return ChargeResponses.parse(response.data);
18731
+ }));
18732
+
18733
+ case 6:
18734
+ case "end":
18735
+ return _context5.stop();
18736
+ }
18737
+ }
18738
+ }, _callee5);
18739
+ }))();
18571
18740
  }
18572
18741
  };
18573
18742
 
@@ -18748,6 +18917,68 @@ var CardCharge = {
18748
18917
  paymentMethod: paymentMethod$3
18749
18918
  };
18750
18919
  return this.listenForCharge(listenerOptions, callback);
18920
+ },
18921
+ requestOtpForSavedCards: function requestOtpForSavedCards(phoneNumber) {
18922
+ return CardAPI.requestOtpForSavedCards(phoneNumber);
18923
+ },
18924
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref4) {
18925
+ var _this9 = this;
18926
+
18927
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18928
+ var code, phone, payload, response;
18929
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18930
+ while (1) {
18931
+ switch (_context.prev = _context.next) {
18932
+ case 0:
18933
+ code = _ref4.code, phone = _ref4.phone;
18934
+ payload = {
18935
+ code: code,
18936
+ phone: phone,
18937
+ transaction: _this9.id
18938
+ };
18939
+ _context.prev = 2;
18940
+ _context.next = 5;
18941
+ return CardAPI.verifySavedCardsOtp(payload);
18942
+
18943
+ case 5:
18944
+ response = _context.sent;
18945
+ _this9.savedCardsToken = response.data.token;
18946
+ return _context.abrupt("return", response);
18947
+
18948
+ case 10:
18949
+ _context.prev = 10;
18950
+ _context.t0 = _context["catch"](2);
18951
+ _this9.savedCardsToken = null;
18952
+ throw new Error(_context.t0);
18953
+
18954
+ case 14:
18955
+ case "end":
18956
+ return _context.stop();
18957
+ }
18958
+ }
18959
+ }, _callee, null, [[2, 10]]);
18960
+ }))();
18961
+ },
18962
+ getSavedCards: function getSavedCards() {
18963
+ return CardAPI.getSavedCards({
18964
+ token: this.savedCardsToken
18965
+ });
18966
+ },
18967
+ deleteSavedCard: function deleteSavedCard(cardCode) {
18968
+ return CardAPI.deleteSavedCard({
18969
+ cardCode: cardCode,
18970
+ token: this.savedCardsToken
18971
+ });
18972
+ },
18973
+ chargeSavedCard: function chargeSavedCard(_ref5) {
18974
+ var cardCode = _ref5.cardCode;
18975
+ return CardAPI.chargeSavedCard({
18976
+ cardCode: cardCode,
18977
+ transaction: this.id,
18978
+ token: this.savedCardsToken,
18979
+ device: this.deviceFingerprint,
18980
+ selectedCurrency: this.currency
18981
+ });
18751
18982
  }
18752
18983
  };
18753
18984
 
@@ -20076,6 +20307,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20076
20307
  this.subscription = data.subscription || null;
20077
20308
  this.planDetails = data.plan_details || null;
20078
20309
  this.exchangeRate = data.exchange_rate || null;
20310
+ this.savedCardsToken = null;
20311
+ this.isSavedCardsEnabled = data.saved_cards && data.saved_cards.enabled || null;
20079
20312
  /**
20080
20313
  * We initialize parameters we send to the API as empty strings
20081
20314
  * when we don't have them instead of null because the API expects
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paystack/checkout-js",
3
- "version": "1.18.1",
3
+ "version": "1.19.0-dev.10",
4
4
  "description": "Client-side JS library for billing on Paystack",
5
5
  "main": "lib/checkout.js",
6
6
  "module": "es/checkout.js",