@paystack/checkout-js 1.22.0-dev.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
@@ -6407,16 +6407,14 @@ 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',
6411
- savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6410
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6412
6411
  });
6413
6412
  var stagingConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6414
6413
  checkoutUrl: 'https://checkout-studio.paystack.com/',
6415
6414
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6416
6415
  paystackApiUrl: 'https://studio-api.paystack.co/',
6417
6416
  pusherKey: '1c7b262ee18455815893',
6418
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6419
- savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6417
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6420
6418
  });
6421
6419
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6422
6420
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -18671,32 +18669,30 @@ var CardAPI$1 = {
18671
18669
  return ChargeResponses.parse(response.data);
18672
18670
  });
18673
18671
  },
18674
- sendSavedCardsOTP: function sendSavedCardsOTP(email) {
18672
+ sendSavedCardsOTP: function sendSavedCardsOTP(transaction) {
18675
18673
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18676
- var url, language, headers, _yield$axiosInstance$, data;
18677
-
18674
+ var url, language, headers, response;
18678
18675
  return regeneratorRuntime.wrap(function _callee$(_context) {
18679
18676
  while (1) {
18680
18677
  switch (_context.prev = _context.next) {
18681
18678
  case 0:
18682
- url = new URL("/authorize", configToUse.savedCardsApiUrl).toString();
18679
+ url = new URL('/saved_cards/authorize', configToUse.paystackApiUrl).toString();
18683
18680
  language = getLanguage();
18684
18681
  headers = _objectSpread2({}, language && {
18685
18682
  'Accept-Language': language
18686
18683
  });
18687
18684
  _context.next = 5;
18688
18685
  return axiosInstance.post(url, {
18689
- email: email
18686
+ transaction: transaction
18690
18687
  }, {
18691
18688
  headers: headers
18692
18689
  });
18693
18690
 
18694
18691
  case 5:
18695
- _yield$axiosInstance$ = _context.sent;
18696
- data = _yield$axiosInstance$.data;
18697
- return _context.abrupt("return", data);
18692
+ response = _context.sent;
18693
+ return _context.abrupt("return", response.data);
18698
18694
 
18699
- case 8:
18695
+ case 7:
18700
18696
  case "end":
18701
18697
  return _context.stop();
18702
18698
  }
@@ -18706,20 +18702,20 @@ var CardAPI$1 = {
18706
18702
  },
18707
18703
  addUserToSavedCards: function addUserToSavedCards(_ref6) {
18708
18704
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18709
- var phone, email, url, language, headers, data, response;
18705
+ var phone, transaction, url, language, headers, data, response;
18710
18706
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
18711
18707
  while (1) {
18712
18708
  switch (_context2.prev = _context2.next) {
18713
18709
  case 0:
18714
- phone = _ref6.phone, email = _ref6.email;
18715
- url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18710
+ phone = _ref6.phone, transaction = _ref6.transaction;
18711
+ url = new URL('/saved_cards/user', configToUse.paystackApiUrl).toString();
18716
18712
  language = getLanguage();
18717
18713
  headers = _objectSpread2({}, language && {
18718
18714
  'Accept-Language': language
18719
18715
  });
18720
18716
  data = {
18721
18717
  phone: phone,
18722
- email: email
18718
+ transaction: transaction
18723
18719
  };
18724
18720
  _context2.next = 7;
18725
18721
  return axiosInstance.post(url, data, {
@@ -18746,7 +18742,7 @@ var CardAPI$1 = {
18746
18742
  switch (_context3.prev = _context3.next) {
18747
18743
  case 0:
18748
18744
  code = _ref7.code, transaction = _ref7.transaction;
18749
- url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18745
+ url = new URL('/saved_cards/authorize/verify', configToUse.paystackApiUrl).toString();
18750
18746
  language = getLanguage();
18751
18747
  headers = _objectSpread2({}, language && {
18752
18748
  'Accept-Language': language
@@ -18780,7 +18776,7 @@ var CardAPI$1 = {
18780
18776
  switch (_context4.prev = _context4.next) {
18781
18777
  case 0:
18782
18778
  token = _ref8.token;
18783
- url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18779
+ url = new URL('/saved_cards/cards', configToUse.paystackApiUrl).toString();
18784
18780
  language = getLanguage();
18785
18781
  headers = _objectSpread2({
18786
18782
  Authorization: "Bearer ".concat(token),
@@ -18813,7 +18809,7 @@ var CardAPI$1 = {
18813
18809
  switch (_context5.prev = _context5.next) {
18814
18810
  case 0:
18815
18811
  cardCode = _ref9.cardCode, token = _ref9.token;
18816
- url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18812
+ url = new URL("/saved_cards/cards/".concat(cardCode), configToUse.paystackApiUrl).toString();
18817
18813
  language = getLanguage();
18818
18814
  headers = _objectSpread2({
18819
18815
  Authorization: "Bearer ".concat(token),
@@ -18840,13 +18836,13 @@ var CardAPI$1 = {
18840
18836
  },
18841
18837
  chargeSavedCard: function chargeSavedCard(_ref10) {
18842
18838
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18843
- var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18839
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data, response;
18844
18840
  return regeneratorRuntime.wrap(function _callee6$(_context6) {
18845
18841
  while (1) {
18846
18842
  switch (_context6.prev = _context6.next) {
18847
18843
  case 0:
18848
18844
  token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18849
- url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18845
+ url = new URL("/saved_cards/cards/".concat(cardCode, "/charge"), configToUse.paystackApiUrl).toString();
18850
18846
  language = getLanguage();
18851
18847
  headers = _objectSpread2({
18852
18848
  Authorization: "Bearer ".concat(token),
@@ -18859,13 +18855,16 @@ var CardAPI$1 = {
18859
18855
  transaction: transaction,
18860
18856
  selected_currency: selectedCurrency
18861
18857
  };
18862
- return _context6.abrupt("return", axiosInstance.post(url, data, {
18858
+ _context6.next = 7;
18859
+ return axiosInstance.post(url, data, {
18863
18860
  headers: headers
18864
- }).then(function (response) {
18865
- return ChargeResponses.parse(response.data);
18866
- }));
18861
+ });
18867
18862
 
18868
- case 6:
18863
+ case 7:
18864
+ response = _context6.sent;
18865
+ return _context6.abrupt("return", ChargeResponses.parse(response.data));
18866
+
18867
+ case 9:
18869
18868
  case "end":
18870
18869
  return _context6.stop();
18871
18870
  }
@@ -19054,13 +19053,13 @@ var CardCharge = {
19054
19053
  return this.listenForCharge(listenerOptions, callback);
19055
19054
  },
19056
19055
  sendSavedCardsOTP: function sendSavedCardsOTP() {
19057
- return CardAPI$1.sendSavedCardsOTP(this.email);
19056
+ return CardAPI$1.sendSavedCardsOTP(this.id);
19058
19057
  },
19059
19058
  addUserToSavedCards: function addUserToSavedCards(_ref4) {
19060
19059
  var phone = _ref4.phone;
19061
19060
  return CardAPI$1.addUserToSavedCards({
19062
19061
  phone: phone,
19063
- email: this.email
19062
+ transaction: this.id
19064
19063
  });
19065
19064
  },
19066
19065
  verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
@@ -20042,6 +20041,32 @@ function isMobile (ua) {
20042
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));
20043
20042
  }
20044
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
+
20045
20070
  var $ = _export;
20046
20071
  var global$1 = global$R;
20047
20072
  var getBuiltIn = getBuiltIn$a;
@@ -20088,9 +20113,10 @@ if ($stringify) {
20088
20113
  });
20089
20114
  }
20090
20115
 
20091
- var AnalyticsAPI = {
20092
- saveLog: function saveLog(transactionId, merchantKey, log) {
20093
- 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;
20094
20120
  var language = getLanguage();
20095
20121
 
20096
20122
  var headers = _objectSpread2({
@@ -20121,8 +20147,8 @@ var AnalyticsAPI = {
20121
20147
  return response.data.data.ip_address;
20122
20148
  });
20123
20149
  },
20124
- saveIp: function saveIp(transactionId, merchantKey) {
20125
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_ip/").concat(transactionId);
20150
+ saveIp: function saveIp(url, _ref2) {
20151
+ var merchantKey = _ref2.merchantKey;
20126
20152
  var language = getLanguage();
20127
20153
 
20128
20154
  var headers = _objectSpread2({
@@ -20137,8 +20163,9 @@ var AnalyticsAPI = {
20137
20163
  return response.data;
20138
20164
  });
20139
20165
  },
20140
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20141
- 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;
20142
20169
  var language = getLanguage();
20143
20170
 
20144
20171
  var headers = _objectSpread2({
@@ -20157,29 +20184,38 @@ var AnalyticsAPI = {
20157
20184
  }
20158
20185
  };
20159
20186
 
20160
- var AnalyticsFunctions = {
20161
- initializeLog: function initializeLog(log) {
20162
- var _ref = log || {},
20163
- attempts = _ref.attempts,
20164
- authentication = _ref.authentication,
20165
- errors = _ref.errors,
20166
- 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
+ };
20167
20212
 
20168
- this.log = {
20169
- start_time: Math.round(Date.now() / 1000),
20170
- time_spent: 0,
20171
- attempts: attempts || 0,
20172
- authentication: authentication,
20173
- errors: errors || 0,
20174
- success: false,
20175
- mobile: isMobile_1(),
20176
- input: [],
20177
- history: history || []
20178
- };
20213
+ var AnalyticsFunctions$1 = {
20214
+ initializeLog: function initializeLog(log) {
20215
+ this.log = AnalyticsUtils.initializeLog(log);
20179
20216
  },
20180
20217
  getTimeSpent: function getTimeSpent() {
20181
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
20182
- this.log.time_spent = currentTimeInSeconds - this.log.start_time;
20218
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20183
20219
  return this.log.time_spent;
20184
20220
  },
20185
20221
  logPageOpen: function logPageOpen() {
@@ -20263,9 +20299,9 @@ var AnalyticsFunctions = {
20263
20299
  return false;
20264
20300
  }
20265
20301
  },
20266
- logMobileMoneyActions: function logMobileMoneyActions(_ref2) {
20267
- var numberOfTokenRequests = _ref2.numberOfTokenRequests,
20268
- registrationToken = _ref2.registrationToken;
20302
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20303
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20304
+ registrationToken = _ref.registrationToken;
20269
20305
 
20270
20306
  if (numberOfTokenRequests) {
20271
20307
  this.logTokenRequest('mobile money', numberOfTokenRequests);
@@ -20391,9 +20427,10 @@ var AnalyticsFunctions = {
20391
20427
  });
20392
20428
  return this.saveLog();
20393
20429
  },
20394
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20395
- var currency = _ref3.currency,
20396
- isUserAction = _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;
20397
20434
  var prefix = isUserAction ? 'User switched' : 'Switched';
20398
20435
  this.log.history.push({
20399
20436
  type: 'action',
@@ -20471,7 +20508,7 @@ var TransactionInstance = /*#__PURE__*/function () {
20471
20508
  loadPusher(); // Analytics
20472
20509
 
20473
20510
  this.log = null;
20474
- Object.assign(this, AnalyticsFunctions);
20511
+ Object.assign(this, AnalyticsFunctions$1);
20475
20512
  this.initializeLog(data.log);
20476
20513
  this.saveIpAddress(); // Bind charge functions for the available channels
20477
20514
 
@@ -20978,9 +21015,9 @@ var CardPreauthorization = {
20978
21015
  publicKey = _ref.publicKey,
20979
21016
  _ref$customFields = _ref.customFields,
20980
21017
  customFields = _ref$customFields === void 0 ? {} : _ref$customFields;
20981
- // TODO: Log payment method
20982
- // https://paystack.atlassian.net/browse/RAILS-3070
20983
21018
  return validate(this.card).then(function () {
21019
+ _this2.logAttempt(paymentMethod);
21020
+
20984
21021
  var chargeParams = {
20985
21022
  clientdata: _this2.card.tokenize(),
20986
21023
  last4: _this2.card.getLast4(),
@@ -20989,8 +21026,8 @@ var CardPreauthorization = {
20989
21026
  customFields: customFields
20990
21027
  };
20991
21028
  return CardAPI.reserveFunds(chargeParams).then(function (response) {
20992
- // TODO: Log API Response
20993
- // https://paystack.atlassian.net/browse/RAILS-3070
21029
+ _this2.logAPIResponse(response, paymentMethod);
21030
+
20994
21031
  return response;
20995
21032
  });
20996
21033
  });
@@ -21039,6 +21076,191 @@ var PreauthorisationAPI = {
21039
21076
  }
21040
21077
  };
21041
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
+
21042
21264
  var PreauthorizationInstance = /*#__PURE__*/function () {
21043
21265
  function PreauthorizationInstance(data) {
21044
21266
  _classCallCheck(this, PreauthorizationInstance);
@@ -21061,9 +21283,11 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
21061
21283
  key: data.merchant_key
21062
21284
  };
21063
21285
  this.card = {};
21064
- loadPusher(); // TODO: Analytics
21065
- // https://paystack.atlassian.net/browse/RAILS-3070
21066
-
21286
+ loadPusher();
21287
+ this.log = null;
21288
+ Object.assign(this, AnalyticsFunctions);
21289
+ this.initializeLog(data.log);
21290
+ this.saveIpAddress();
21067
21291
  Object.assign(this, CardPreauthorization);
21068
21292
  }
21069
21293
 
@@ -21115,20 +21339,6 @@ var Preauthorization = {
21115
21339
  }
21116
21340
  }, _callee);
21117
21341
  }))();
21118
- },
21119
- verify: function verify() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
21120
-
21121
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
21122
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
21123
- while (1) {
21124
- switch (_context2.prev = _context2.next) {
21125
- case 0:
21126
- case "end":
21127
- return _context2.stop();
21128
- }
21129
- }
21130
- }, _callee2);
21131
- }))();
21132
21342
  }
21133
21343
  };
21134
21344
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paystack/checkout-js",
3
- "version": "1.22.0-dev.1",
3
+ "version": "1.22.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",