@paystack/checkout-js 1.21.1 → 1.22.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/lib/checkout.js CHANGED
@@ -18668,6 +18668,209 @@ var CardAPI$1 = {
18668
18668
  }).then(function (response) {
18669
18669
  return ChargeResponses.parse(response.data);
18670
18670
  });
18671
+ },
18672
+ sendSavedCardsOTP: function sendSavedCardsOTP(transaction) {
18673
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18674
+ var url, language, headers, response;
18675
+ return regeneratorRuntime.wrap(function _callee$(_context) {
18676
+ while (1) {
18677
+ switch (_context.prev = _context.next) {
18678
+ case 0:
18679
+ url = new URL('/saved_cards/authorize', configToUse.paystackApiUrl).toString();
18680
+ language = getLanguage();
18681
+ headers = _objectSpread2({}, language && {
18682
+ 'Accept-Language': language
18683
+ });
18684
+ _context.next = 5;
18685
+ return axiosInstance.post(url, {
18686
+ transaction: transaction
18687
+ }, {
18688
+ headers: headers
18689
+ });
18690
+
18691
+ case 5:
18692
+ response = _context.sent;
18693
+ return _context.abrupt("return", response.data);
18694
+
18695
+ case 7:
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, transaction, 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, transaction = _ref6.transaction;
18711
+ url = new URL('/saved_cards/user', configToUse.paystackApiUrl).toString();
18712
+ language = getLanguage();
18713
+ headers = _objectSpread2({}, language && {
18714
+ 'Accept-Language': language
18715
+ });
18716
+ data = {
18717
+ phone: phone,
18718
+ transaction: transaction
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('/saved_cards/authorize/verify', configToUse.paystackApiUrl).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('/saved_cards/cards', configToUse.paystackApiUrl).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("/saved_cards/cards/".concat(cardCode), configToUse.paystackApiUrl).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, response;
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("/saved_cards/cards/".concat(cardCode, "/charge"), configToUse.paystackApiUrl).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
+ _context6.next = 7;
18859
+ return axiosInstance.post(url, data, {
18860
+ headers: headers
18861
+ });
18862
+
18863
+ case 7:
18864
+ response = _context6.sent;
18865
+ return _context6.abrupt("return", ChargeResponses.parse(response.data));
18866
+
18867
+ case 9:
18868
+ case "end":
18869
+ return _context6.stop();
18870
+ }
18871
+ }
18872
+ }, _callee6);
18873
+ }))();
18671
18874
  }
18672
18875
  };
18673
18876
 
@@ -18848,6 +19051,74 @@ var CardCharge = {
18848
19051
  paymentMethod: paymentMethod$4
18849
19052
  };
18850
19053
  return this.listenForCharge(listenerOptions, callback);
19054
+ },
19055
+ sendSavedCardsOTP: function sendSavedCardsOTP() {
19056
+ return CardAPI$1.sendSavedCardsOTP(this.id);
19057
+ },
19058
+ addUserToSavedCards: function addUserToSavedCards(_ref4) {
19059
+ var phone = _ref4.phone;
19060
+ return CardAPI$1.addUserToSavedCards({
19061
+ phone: phone,
19062
+ transaction: this.id
19063
+ });
19064
+ },
19065
+ verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
19066
+ var _this9 = this;
19067
+
19068
+ return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
19069
+ var code, payload, response;
19070
+ return regeneratorRuntime.wrap(function _callee$(_context) {
19071
+ while (1) {
19072
+ switch (_context.prev = _context.next) {
19073
+ case 0:
19074
+ code = _ref5.code;
19075
+ payload = {
19076
+ code: code,
19077
+ transaction: _this9.id
19078
+ };
19079
+ _context.prev = 2;
19080
+ _context.next = 5;
19081
+ return CardAPI$1.verifySavedCardsOtp(payload);
19082
+
19083
+ case 5:
19084
+ response = _context.sent;
19085
+ _this9.savedCardsToken = response.data.token;
19086
+ return _context.abrupt("return", response);
19087
+
19088
+ case 10:
19089
+ _context.prev = 10;
19090
+ _context.t0 = _context["catch"](2);
19091
+ _this9.savedCardsToken = null;
19092
+ throw _context.t0;
19093
+
19094
+ case 14:
19095
+ case "end":
19096
+ return _context.stop();
19097
+ }
19098
+ }
19099
+ }, _callee, null, [[2, 10]]);
19100
+ }))();
19101
+ },
19102
+ getSavedCards: function getSavedCards() {
19103
+ return CardAPI$1.getSavedCards({
19104
+ token: this.savedCardsToken
19105
+ });
19106
+ },
19107
+ deleteSavedCard: function deleteSavedCard(cardCode) {
19108
+ return CardAPI$1.deleteSavedCard({
19109
+ cardCode: cardCode,
19110
+ token: this.savedCardsToken
19111
+ });
19112
+ },
19113
+ chargeSavedCard: function chargeSavedCard(_ref6) {
19114
+ var cardCode = _ref6.cardCode;
19115
+ return CardAPI$1.chargeSavedCard({
19116
+ cardCode: cardCode,
19117
+ transaction: this.id,
19118
+ token: this.savedCardsToken,
19119
+ device: this.deviceFingerprint,
19120
+ selectedCurrency: this.currency
19121
+ });
18851
19122
  }
18852
19123
  };
18853
19124
 
@@ -19770,6 +20041,32 @@ function isMobile (ua) {
19770
20041
  return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(ua) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(ua.substr(0,4));
19771
20042
  }
19772
20043
 
20044
+ var AnalyticsUtils = {
20045
+ initializeLog: function initializeLog(log) {
20046
+ var _ref = log || {},
20047
+ attempts = _ref.attempts,
20048
+ authentication = _ref.authentication,
20049
+ errors = _ref.errors,
20050
+ history = _ref.history;
20051
+
20052
+ return {
20053
+ start_time: Math.round(Date.now() / 1000),
20054
+ time_spent: 0,
20055
+ attempts: attempts || 0,
20056
+ authentication: authentication,
20057
+ errors: errors || 0,
20058
+ success: false,
20059
+ mobile: isMobile_1(),
20060
+ input: [],
20061
+ history: history || []
20062
+ };
20063
+ },
20064
+ getTimeSpent: function getTimeSpent(startTime) {
20065
+ var currentTimeInSeconds = Math.round(Date.now() / 1000);
20066
+ return currentTimeInSeconds - startTime;
20067
+ }
20068
+ };
20069
+
19773
20070
  var $ = _export;
19774
20071
  var global$1 = global$R;
19775
20072
  var getBuiltIn = getBuiltIn$a;
@@ -19816,9 +20113,10 @@ if ($stringify) {
19816
20113
  });
19817
20114
  }
19818
20115
 
19819
- var AnalyticsAPI = {
19820
- saveLog: function saveLog(transactionId, merchantKey, log) {
19821
- var url = "".concat(configToUse.paystackApiUrl, "transaction/update_log/").concat(transactionId);
20116
+ var AnalyticsAPIUtils = {
20117
+ saveLog: function saveLog(url, _ref) {
20118
+ var merchantKey = _ref.merchantKey,
20119
+ log = _ref.log;
19822
20120
  var language = getLanguage();
19823
20121
 
19824
20122
  var headers = _objectSpread2({
@@ -19849,8 +20147,8 @@ var AnalyticsAPI = {
19849
20147
  return response.data.data.ip_address;
19850
20148
  });
19851
20149
  },
19852
- saveIp: function saveIp(transactionId, merchantKey) {
19853
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_ip/").concat(transactionId);
20150
+ saveIp: function saveIp(url, _ref2) {
20151
+ var merchantKey = _ref2.merchantKey;
19854
20152
  var language = getLanguage();
19855
20153
 
19856
20154
  var headers = _objectSpread2({
@@ -19865,8 +20163,9 @@ var AnalyticsAPI = {
19865
20163
  return response.data;
19866
20164
  });
19867
20165
  },
19868
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
19869
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_referrer/").concat(transactionId);
20166
+ saveReferrer: function saveReferrer(url, _ref3) {
20167
+ var merchantKey = _ref3.merchantKey,
20168
+ referrer = _ref3.referrer;
19870
20169
  var language = getLanguage();
19871
20170
 
19872
20171
  var headers = _objectSpread2({
@@ -19885,29 +20184,38 @@ var AnalyticsAPI = {
19885
20184
  }
19886
20185
  };
19887
20186
 
19888
- var AnalyticsFunctions = {
19889
- initializeLog: function initializeLog(log) {
19890
- var _ref = log || {},
19891
- attempts = _ref.attempts,
19892
- authentication = _ref.authentication,
19893
- errors = _ref.errors,
19894
- history = _ref.history;
20187
+ var AnalyticsAPI = {
20188
+ saveLog: function saveLog(transactionId, merchantKey, log) {
20189
+ var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
20190
+ return AnalyticsAPIUtils.saveLog(url, {
20191
+ merchantKey: merchantKey,
20192
+ log: log
20193
+ });
20194
+ },
20195
+ getIp: function getIp() {
20196
+ return AnalyticsAPIUtils.getIp();
20197
+ },
20198
+ saveIp: function saveIp(transactionId, merchantKey) {
20199
+ var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
20200
+ return AnalyticsAPIUtils.saveIp(url, {
20201
+ merchantKey: merchantKey
20202
+ });
20203
+ },
20204
+ saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20205
+ var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
20206
+ return AnalyticsAPIUtils.saveReferrer(url, {
20207
+ merchantKey: merchantKey,
20208
+ referrer: referrer
20209
+ });
20210
+ }
20211
+ };
19895
20212
 
19896
- this.log = {
19897
- start_time: Math.round(Date.now() / 1000),
19898
- time_spent: 0,
19899
- attempts: attempts || 0,
19900
- authentication: authentication,
19901
- errors: errors || 0,
19902
- success: false,
19903
- mobile: isMobile_1(),
19904
- input: [],
19905
- history: history || []
19906
- };
20213
+ var AnalyticsFunctions$1 = {
20214
+ initializeLog: function initializeLog(log) {
20215
+ this.log = AnalyticsUtils.initializeLog(log);
19907
20216
  },
19908
20217
  getTimeSpent: function getTimeSpent() {
19909
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
19910
- this.log.time_spent = currentTimeInSeconds - this.log.start_time;
20218
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
19911
20219
  return this.log.time_spent;
19912
20220
  },
19913
20221
  logPageOpen: function logPageOpen() {
@@ -19991,9 +20299,9 @@ var AnalyticsFunctions = {
19991
20299
  return false;
19992
20300
  }
19993
20301
  },
19994
- logMobileMoneyActions: function logMobileMoneyActions(_ref2) {
19995
- var numberOfTokenRequests = _ref2.numberOfTokenRequests,
19996
- registrationToken = _ref2.registrationToken;
20302
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20303
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20304
+ registrationToken = _ref.registrationToken;
19997
20305
 
19998
20306
  if (numberOfTokenRequests) {
19999
20307
  this.logTokenRequest('mobile money', numberOfTokenRequests);
@@ -20119,10 +20427,10 @@ var AnalyticsFunctions = {
20119
20427
  });
20120
20428
  return this.saveLog();
20121
20429
  },
20122
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20123
- var currency = _ref3.currency,
20124
- _ref3$isUserAction = _ref3.isUserAction,
20125
- isUserAction = _ref3$isUserAction === void 0 ? true : _ref3$isUserAction;
20430
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20431
+ var currency = _ref2.currency,
20432
+ _ref2$isUserAction = _ref2.isUserAction,
20433
+ isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20126
20434
  var prefix = isUserAction ? 'User switched' : 'Switched';
20127
20435
  this.log.history.push({
20128
20436
  type: 'action',
@@ -20188,6 +20496,8 @@ var TransactionInstance = /*#__PURE__*/function () {
20188
20496
  this.subscription = data.subscription || null;
20189
20497
  this.planDetails = data.plan_details || null;
20190
20498
  this.exchangeRate = data.exchange_rate || null;
20499
+ this.savedCardsConfig = data.saved_cards || {};
20500
+ this.savedCardsToken = null;
20191
20501
  /**
20192
20502
  * We initialize parameters we send to the API as empty strings
20193
20503
  * when we don't have them instead of null because the API expects
@@ -20198,7 +20508,7 @@ var TransactionInstance = /*#__PURE__*/function () {
20198
20508
  loadPusher(); // Analytics
20199
20509
 
20200
20510
  this.log = null;
20201
- Object.assign(this, AnalyticsFunctions);
20511
+ Object.assign(this, AnalyticsFunctions$1);
20202
20512
  this.initializeLog(data.log);
20203
20513
  this.saveIpAddress(); // Bind charge functions for the available channels
20204
20514
 
@@ -20458,6 +20768,21 @@ var ToolkitAPI = {
20458
20768
  resolvedCardBins[bin] = data;
20459
20769
  return data;
20460
20770
  });
20771
+ },
20772
+ resolveIPAddress: function resolveIPAddress(ipAddress) {
20773
+ var url = new URL("decision/resolve_ip/".concat(ipAddress), configToUse.paystackApiUrl).toString();
20774
+ var language = getLanguage();
20775
+
20776
+ var headers = _objectSpread2({}, language && {
20777
+ 'Accept-Language': language
20778
+ });
20779
+
20780
+ return axiosInstance.get(url, {
20781
+ headers: headers
20782
+ }).then(function (_ref2) {
20783
+ var data = _ref2.data;
20784
+ return data;
20785
+ });
20461
20786
  }
20462
20787
  };
20463
20788
 
@@ -20523,6 +20848,11 @@ var Toolkit = /*#__PURE__*/function () {
20523
20848
  value: function resolveCardBin(bin) {
20524
20849
  return ToolkitAPI.resolveCardBin(bin);
20525
20850
  }
20851
+ }, {
20852
+ key: "resolveIPAddress",
20853
+ value: function resolveIPAddress(ipAddress) {
20854
+ return ToolkitAPI.resolveIPAddress(ipAddress);
20855
+ }
20526
20856
  }]);
20527
20857
 
20528
20858
  return Toolkit;
@@ -20685,9 +21015,9 @@ var CardPreauthorization = {
20685
21015
  publicKey = _ref.publicKey,
20686
21016
  _ref$customFields = _ref.customFields,
20687
21017
  customFields = _ref$customFields === void 0 ? {} : _ref$customFields;
20688
- // TODO: Log payment method
20689
- // https://paystack.atlassian.net/browse/RAILS-3070
20690
21018
  return validate(this.card).then(function () {
21019
+ _this2.logAttempt(paymentMethod);
21020
+
20691
21021
  var chargeParams = {
20692
21022
  clientdata: _this2.card.tokenize(),
20693
21023
  last4: _this2.card.getLast4(),
@@ -20696,8 +21026,8 @@ var CardPreauthorization = {
20696
21026
  customFields: customFields
20697
21027
  };
20698
21028
  return CardAPI.reserveFunds(chargeParams).then(function (response) {
20699
- // TODO: Log API Response
20700
- // https://paystack.atlassian.net/browse/RAILS-3070
21029
+ _this2.logAPIResponse(response, paymentMethod);
21030
+
20701
21031
  return response;
20702
21032
  });
20703
21033
  });
@@ -20746,6 +21076,191 @@ var PreauthorisationAPI = {
20746
21076
  }
20747
21077
  };
20748
21078
 
21079
+ var PreauthorizationAnalyticsAPI = {
21080
+ saveLog: function saveLog(preauthorizationId, merchantKey, log) {
21081
+ var url = new URL("preauthorization/update_log/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21082
+ return AnalyticsAPIUtils.saveLog(url, {
21083
+ merchantKey: merchantKey,
21084
+ log: log
21085
+ });
21086
+ },
21087
+ getIp: function getIp() {
21088
+ return AnalyticsAPIUtils.getIp();
21089
+ },
21090
+ saveIp: function saveIp(preauthorizationId, merchantKey) {
21091
+ var url = new URL("preauthorization/set_ip/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21092
+ return AnalyticsAPIUtils.saveIp(url, {
21093
+ merchantKey: merchantKey
21094
+ });
21095
+ },
21096
+ saveReferrer: function saveReferrer(preauthorizationId, merchantKey, referrer) {
21097
+ var url = new URL("preauthorization/set_referrer/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21098
+ return AnalyticsAPIUtils.saveReferrer(url, {
21099
+ merchantKey: merchantKey,
21100
+ referrer: referrer
21101
+ });
21102
+ }
21103
+ };
21104
+
21105
+ var AnalyticsFunctions = {
21106
+ initializeLog: function initializeLog(log) {
21107
+ this.log = AnalyticsUtils.initializeLog(log);
21108
+ },
21109
+ getTimeSpent: function getTimeSpent() {
21110
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
21111
+ return this.log.time_spent;
21112
+ },
21113
+ logPageOpen: function logPageOpen() {
21114
+ this.log.history.push({
21115
+ type: 'open',
21116
+ message: 'Opened checkout',
21117
+ time: this.getTimeSpent()
21118
+ });
21119
+ return this.saveLog();
21120
+ },
21121
+ logChannelSwitch: function logChannelSwitch(value) {
21122
+ this.log.history.push({
21123
+ type: 'action',
21124
+ message: "Set payment method to: ".concat(value),
21125
+ time: this.getTimeSpent()
21126
+ });
21127
+ return this.saveLog();
21128
+ },
21129
+ logValidationErrors: function logValidationErrors(inputs) {
21130
+ var _this = this;
21131
+
21132
+ inputs.forEach(function (input) {
21133
+ _this.log.history.push({
21134
+ type: 'error',
21135
+ message: "Invalid ".concat(input),
21136
+ time: _this.getTimeSpent()
21137
+ });
21138
+ });
21139
+ return this.saveLog();
21140
+ },
21141
+ logInput: function logInput(value) {
21142
+ var isUpdate = this.log.history.find(function (item) {
21143
+ return item.message === "Filled this field: ".concat(value);
21144
+ });
21145
+ this.log.history.push({
21146
+ type: 'input',
21147
+ message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
21148
+ time: this.getTimeSpent()
21149
+ });
21150
+ return this.saveLog();
21151
+ },
21152
+ logAuthWindowOpen: function logAuthWindowOpen() {
21153
+ this.log.history.push({
21154
+ type: 'action',
21155
+ message: 'Third-party authentication window opened',
21156
+ time: this.getTimeSpent()
21157
+ });
21158
+ return this.saveLog();
21159
+ },
21160
+ logAuthWindowClose: function logAuthWindowClose() {
21161
+ this.log.history.push({
21162
+ type: 'action',
21163
+ message: 'Third-party authentication window closed',
21164
+ time: this.getTimeSpent()
21165
+ });
21166
+ return this.saveLog();
21167
+ },
21168
+ logAPIResponse: function logAPIResponse(response, channel) {
21169
+ switch (response.status) {
21170
+ case 'success':
21171
+ return this.logSuccess(channel);
21172
+
21173
+ case 'failed':
21174
+ return this.logError(response.message);
21175
+
21176
+ case 'auth':
21177
+ return this.logAuth(response.data.auth);
21178
+
21179
+ default:
21180
+ return false;
21181
+ }
21182
+ },
21183
+ logAPIResponseMessage: function logAPIResponseMessage(message) {
21184
+ this.log.history.push({
21185
+ type: 'action',
21186
+ message: message,
21187
+ time: this.getTimeSpent()
21188
+ });
21189
+ return this.saveLog();
21190
+ },
21191
+ logAttempt: function logAttempt(channel) {
21192
+ var message = 'Attempted to pay';
21193
+
21194
+ if (channel) {
21195
+ message += " with ".concat(channel);
21196
+ }
21197
+
21198
+ this.log.attempts += 1;
21199
+ this.log.history.push({
21200
+ type: 'action',
21201
+ message: message,
21202
+ time: this.getTimeSpent()
21203
+ });
21204
+ return this.saveLog();
21205
+ },
21206
+ logAuth: function logAuth(value) {
21207
+ this.log.authentication = value;
21208
+ this.log.history.push({
21209
+ type: 'auth',
21210
+ message: "Authentication Required: ".concat(value),
21211
+ time: this.getTimeSpent()
21212
+ });
21213
+ return this.saveLog();
21214
+ },
21215
+ logSuccess: function logSuccess(channel) {
21216
+ var message = 'Successfully reserved funds';
21217
+
21218
+ if (channel) {
21219
+ message += " with ".concat(channel);
21220
+ }
21221
+
21222
+ this.log.success = true;
21223
+ this.log.history.push({
21224
+ type: 'success',
21225
+ message: message,
21226
+ time: this.getTimeSpent()
21227
+ });
21228
+ return this.saveLog();
21229
+ },
21230
+ logPageClose: function logPageClose() {
21231
+ this.log.history.push({
21232
+ type: 'close',
21233
+ message: 'Closed checkout',
21234
+ time: this.getTimeSpent()
21235
+ });
21236
+ return this.saveLog();
21237
+ },
21238
+ logError: function logError(error) {
21239
+ var message = 'Error';
21240
+
21241
+ if (error) {
21242
+ message += ": ".concat(error);
21243
+ }
21244
+
21245
+ this.log.errors += 1;
21246
+ this.log.history.push({
21247
+ type: 'error',
21248
+ message: message,
21249
+ time: this.getTimeSpent()
21250
+ });
21251
+ return this.saveLog();
21252
+ },
21253
+ saveLog: function saveLog() {
21254
+ return PreauthorizationAnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
21255
+ },
21256
+ saveIpAddress: function saveIpAddress() {
21257
+ return PreauthorizationAnalyticsAPI.saveIp(this.id, this.merchant.key);
21258
+ },
21259
+ saveReferrer: function saveReferrer(referrer) {
21260
+ return PreauthorizationAnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
21261
+ }
21262
+ };
21263
+
20749
21264
  var PreauthorizationInstance = /*#__PURE__*/function () {
20750
21265
  function PreauthorizationInstance(data) {
20751
21266
  _classCallCheck(this, PreauthorizationInstance);
@@ -20760,6 +21275,7 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20760
21275
  this.customer = data.customer;
20761
21276
  this.channels = data.channels || ['card'];
20762
21277
  this.isListening = false;
21278
+ this.isTest = data.domain === 'test';
20763
21279
  this.merchant = {
20764
21280
  id: data.merchant_id,
20765
21281
  logo: data.merchant_logo,
@@ -20767,9 +21283,11 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
20767
21283
  key: data.merchant_key
20768
21284
  };
20769
21285
  this.card = {};
20770
- loadPusher(); // TODO: Analytics
20771
- // https://paystack.atlassian.net/browse/RAILS-3070
20772
-
21286
+ loadPusher();
21287
+ this.log = null;
21288
+ Object.assign(this, AnalyticsFunctions);
21289
+ this.initializeLog(data.log);
21290
+ this.saveIpAddress();
20773
21291
  Object.assign(this, CardPreauthorization);
20774
21292
  }
20775
21293
 
@@ -20821,20 +21339,6 @@ var Preauthorization = {
20821
21339
  }
20822
21340
  }, _callee);
20823
21341
  }))();
20824
- },
20825
- verify: function verify() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
20826
-
20827
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
20828
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
20829
- while (1) {
20830
- switch (_context2.prev = _context2.next) {
20831
- case 0:
20832
- case "end":
20833
- return _context2.stop();
20834
- }
20835
- }
20836
- }, _callee2);
20837
- }))();
20838
21342
  }
20839
21343
  };
20840
21344