@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/dist/checkout.js CHANGED
@@ -6406,16 +6406,14 @@ var Paystack = (function (exports) {
6406
6406
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6407
6407
  paystackApiUrl: 'https://studio-api.paystack.co/',
6408
6408
  pusherKey: '1c7b262ee18455815893',
6409
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6410
- savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6409
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6411
6410
  });
6412
6411
  var stagingConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6413
6412
  checkoutUrl: 'https://checkout-studio.paystack.com/',
6414
6413
  paymentBaseUrl: 'https://legacy-staging.paystack.co/',
6415
6414
  paystackApiUrl: 'https://studio-api.paystack.co/',
6416
6415
  pusherKey: '1c7b262ee18455815893',
6417
- pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js',
6418
- savedCardsApiUrl: 'https://saved-cards-api.public.paystack.studio/'
6416
+ pusherUrl: 'https://s3-eu-west-1.amazonaws.com/pstk-public-files/js/pusher.min.js'
6419
6417
  });
6420
6418
  var productionConfig = _objectSpread2(_objectSpread2({}, config), {}, {
6421
6419
  checkoutUrl: 'https://checkout.paystack.com/',
@@ -18670,32 +18668,30 @@ var Paystack = (function (exports) {
18670
18668
  return ChargeResponses.parse(response.data);
18671
18669
  });
18672
18670
  },
18673
- sendSavedCardsOTP: function sendSavedCardsOTP(email) {
18671
+ sendSavedCardsOTP: function sendSavedCardsOTP(transaction) {
18674
18672
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
18675
- var url, language, headers, _yield$axiosInstance$, data;
18676
-
18673
+ var url, language, headers, response;
18677
18674
  return regeneratorRuntime.wrap(function _callee$(_context) {
18678
18675
  while (1) {
18679
18676
  switch (_context.prev = _context.next) {
18680
18677
  case 0:
18681
- url = new URL("/authorize", configToUse.savedCardsApiUrl).toString();
18678
+ url = new URL('/saved_cards/authorize', configToUse.paystackApiUrl).toString();
18682
18679
  language = getLanguage();
18683
18680
  headers = _objectSpread2({}, language && {
18684
18681
  'Accept-Language': language
18685
18682
  });
18686
18683
  _context.next = 5;
18687
18684
  return axiosInstance.post(url, {
18688
- email: email
18685
+ transaction: transaction
18689
18686
  }, {
18690
18687
  headers: headers
18691
18688
  });
18692
18689
 
18693
18690
  case 5:
18694
- _yield$axiosInstance$ = _context.sent;
18695
- data = _yield$axiosInstance$.data;
18696
- return _context.abrupt("return", data);
18691
+ response = _context.sent;
18692
+ return _context.abrupt("return", response.data);
18697
18693
 
18698
- case 8:
18694
+ case 7:
18699
18695
  case "end":
18700
18696
  return _context.stop();
18701
18697
  }
@@ -18705,20 +18701,20 @@ var Paystack = (function (exports) {
18705
18701
  },
18706
18702
  addUserToSavedCards: function addUserToSavedCards(_ref6) {
18707
18703
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
18708
- var phone, email, url, language, headers, data, response;
18704
+ var phone, transaction, url, language, headers, data, response;
18709
18705
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
18710
18706
  while (1) {
18711
18707
  switch (_context2.prev = _context2.next) {
18712
18708
  case 0:
18713
- phone = _ref6.phone, email = _ref6.email;
18714
- url = new URL('/user', configToUse.savedCardsApiUrl).toString();
18709
+ phone = _ref6.phone, transaction = _ref6.transaction;
18710
+ url = new URL('/saved_cards/user', configToUse.paystackApiUrl).toString();
18715
18711
  language = getLanguage();
18716
18712
  headers = _objectSpread2({}, language && {
18717
18713
  'Accept-Language': language
18718
18714
  });
18719
18715
  data = {
18720
18716
  phone: phone,
18721
- email: email
18717
+ transaction: transaction
18722
18718
  };
18723
18719
  _context2.next = 7;
18724
18720
  return axiosInstance.post(url, data, {
@@ -18745,7 +18741,7 @@ var Paystack = (function (exports) {
18745
18741
  switch (_context3.prev = _context3.next) {
18746
18742
  case 0:
18747
18743
  code = _ref7.code, transaction = _ref7.transaction;
18748
- url = new URL('/authorize/verify', configToUse.savedCardsApiUrl).toString();
18744
+ url = new URL('/saved_cards/authorize/verify', configToUse.paystackApiUrl).toString();
18749
18745
  language = getLanguage();
18750
18746
  headers = _objectSpread2({}, language && {
18751
18747
  'Accept-Language': language
@@ -18779,7 +18775,7 @@ var Paystack = (function (exports) {
18779
18775
  switch (_context4.prev = _context4.next) {
18780
18776
  case 0:
18781
18777
  token = _ref8.token;
18782
- url = new URL('/cards', configToUse.savedCardsApiUrl).toString();
18778
+ url = new URL('/saved_cards/cards', configToUse.paystackApiUrl).toString();
18783
18779
  language = getLanguage();
18784
18780
  headers = _objectSpread2({
18785
18781
  Authorization: "Bearer ".concat(token),
@@ -18812,7 +18808,7 @@ var Paystack = (function (exports) {
18812
18808
  switch (_context5.prev = _context5.next) {
18813
18809
  case 0:
18814
18810
  cardCode = _ref9.cardCode, token = _ref9.token;
18815
- url = new URL("/cards/".concat(cardCode), configToUse.savedCardsApiUrl).toString();
18811
+ url = new URL("/saved_cards/cards/".concat(cardCode), configToUse.paystackApiUrl).toString();
18816
18812
  language = getLanguage();
18817
18813
  headers = _objectSpread2({
18818
18814
  Authorization: "Bearer ".concat(token),
@@ -18839,13 +18835,13 @@ var Paystack = (function (exports) {
18839
18835
  },
18840
18836
  chargeSavedCard: function chargeSavedCard(_ref10) {
18841
18837
  return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
18842
- var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data;
18838
+ var token, device, cardCode, transaction, selectedCurrency, url, language, headers, data, response;
18843
18839
  return regeneratorRuntime.wrap(function _callee6$(_context6) {
18844
18840
  while (1) {
18845
18841
  switch (_context6.prev = _context6.next) {
18846
18842
  case 0:
18847
18843
  token = _ref10.token, device = _ref10.device, cardCode = _ref10.cardCode, transaction = _ref10.transaction, selectedCurrency = _ref10.selectedCurrency;
18848
- url = new URL("/cards/".concat(cardCode, "/charge"), configToUse.savedCardsApiUrl).toString();
18844
+ url = new URL("/saved_cards/cards/".concat(cardCode, "/charge"), configToUse.paystackApiUrl).toString();
18849
18845
  language = getLanguage();
18850
18846
  headers = _objectSpread2({
18851
18847
  Authorization: "Bearer ".concat(token),
@@ -18858,13 +18854,16 @@ var Paystack = (function (exports) {
18858
18854
  transaction: transaction,
18859
18855
  selected_currency: selectedCurrency
18860
18856
  };
18861
- return _context6.abrupt("return", axiosInstance.post(url, data, {
18857
+ _context6.next = 7;
18858
+ return axiosInstance.post(url, data, {
18862
18859
  headers: headers
18863
- }).then(function (response) {
18864
- return ChargeResponses.parse(response.data);
18865
- }));
18860
+ });
18866
18861
 
18867
- case 6:
18862
+ case 7:
18863
+ response = _context6.sent;
18864
+ return _context6.abrupt("return", ChargeResponses.parse(response.data));
18865
+
18866
+ case 9:
18868
18867
  case "end":
18869
18868
  return _context6.stop();
18870
18869
  }
@@ -19053,13 +19052,13 @@ var Paystack = (function (exports) {
19053
19052
  return this.listenForCharge(listenerOptions, callback);
19054
19053
  },
19055
19054
  sendSavedCardsOTP: function sendSavedCardsOTP() {
19056
- return CardAPI$1.sendSavedCardsOTP(this.email);
19055
+ return CardAPI$1.sendSavedCardsOTP(this.id);
19057
19056
  },
19058
19057
  addUserToSavedCards: function addUserToSavedCards(_ref4) {
19059
19058
  var phone = _ref4.phone;
19060
19059
  return CardAPI$1.addUserToSavedCards({
19061
19060
  phone: phone,
19062
- email: this.email
19061
+ transaction: this.id
19063
19062
  });
19064
19063
  },
19065
19064
  verifySavedCardsOtp: function verifySavedCardsOtp(_ref5) {
@@ -20041,6 +20040,32 @@ var Paystack = (function (exports) {
20041
20040
  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));
20042
20041
  }
20043
20042
 
20043
+ var AnalyticsUtils = {
20044
+ initializeLog: function initializeLog(log) {
20045
+ var _ref = log || {},
20046
+ attempts = _ref.attempts,
20047
+ authentication = _ref.authentication,
20048
+ errors = _ref.errors,
20049
+ history = _ref.history;
20050
+
20051
+ return {
20052
+ start_time: Math.round(Date.now() / 1000),
20053
+ time_spent: 0,
20054
+ attempts: attempts || 0,
20055
+ authentication: authentication,
20056
+ errors: errors || 0,
20057
+ success: false,
20058
+ mobile: isMobile_1(),
20059
+ input: [],
20060
+ history: history || []
20061
+ };
20062
+ },
20063
+ getTimeSpent: function getTimeSpent(startTime) {
20064
+ var currentTimeInSeconds = Math.round(Date.now() / 1000);
20065
+ return currentTimeInSeconds - startTime;
20066
+ }
20067
+ };
20068
+
20044
20069
  var $ = _export;
20045
20070
  var global$1 = global$R;
20046
20071
  var getBuiltIn = getBuiltIn$a;
@@ -20087,9 +20112,10 @@ var Paystack = (function (exports) {
20087
20112
  });
20088
20113
  }
20089
20114
 
20090
- var AnalyticsAPI = {
20091
- saveLog: function saveLog(transactionId, merchantKey, log) {
20092
- var url = "".concat(configToUse.paystackApiUrl, "transaction/update_log/").concat(transactionId);
20115
+ var AnalyticsAPIUtils = {
20116
+ saveLog: function saveLog(url, _ref) {
20117
+ var merchantKey = _ref.merchantKey,
20118
+ log = _ref.log;
20093
20119
  var language = getLanguage();
20094
20120
 
20095
20121
  var headers = _objectSpread2({
@@ -20120,8 +20146,8 @@ var Paystack = (function (exports) {
20120
20146
  return response.data.data.ip_address;
20121
20147
  });
20122
20148
  },
20123
- saveIp: function saveIp(transactionId, merchantKey) {
20124
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_ip/").concat(transactionId);
20149
+ saveIp: function saveIp(url, _ref2) {
20150
+ var merchantKey = _ref2.merchantKey;
20125
20151
  var language = getLanguage();
20126
20152
 
20127
20153
  var headers = _objectSpread2({
@@ -20136,8 +20162,9 @@ var Paystack = (function (exports) {
20136
20162
  return response.data;
20137
20163
  });
20138
20164
  },
20139
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20140
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_referrer/").concat(transactionId);
20165
+ saveReferrer: function saveReferrer(url, _ref3) {
20166
+ var merchantKey = _ref3.merchantKey,
20167
+ referrer = _ref3.referrer;
20141
20168
  var language = getLanguage();
20142
20169
 
20143
20170
  var headers = _objectSpread2({
@@ -20156,29 +20183,38 @@ var Paystack = (function (exports) {
20156
20183
  }
20157
20184
  };
20158
20185
 
20159
- var AnalyticsFunctions = {
20160
- initializeLog: function initializeLog(log) {
20161
- var _ref = log || {},
20162
- attempts = _ref.attempts,
20163
- authentication = _ref.authentication,
20164
- errors = _ref.errors,
20165
- history = _ref.history;
20186
+ var AnalyticsAPI = {
20187
+ saveLog: function saveLog(transactionId, merchantKey, log) {
20188
+ var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
20189
+ return AnalyticsAPIUtils.saveLog(url, {
20190
+ merchantKey: merchantKey,
20191
+ log: log
20192
+ });
20193
+ },
20194
+ getIp: function getIp() {
20195
+ return AnalyticsAPIUtils.getIp();
20196
+ },
20197
+ saveIp: function saveIp(transactionId, merchantKey) {
20198
+ var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
20199
+ return AnalyticsAPIUtils.saveIp(url, {
20200
+ merchantKey: merchantKey
20201
+ });
20202
+ },
20203
+ saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20204
+ var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
20205
+ return AnalyticsAPIUtils.saveReferrer(url, {
20206
+ merchantKey: merchantKey,
20207
+ referrer: referrer
20208
+ });
20209
+ }
20210
+ };
20166
20211
 
20167
- this.log = {
20168
- start_time: Math.round(Date.now() / 1000),
20169
- time_spent: 0,
20170
- attempts: attempts || 0,
20171
- authentication: authentication,
20172
- errors: errors || 0,
20173
- success: false,
20174
- mobile: isMobile_1(),
20175
- input: [],
20176
- history: history || []
20177
- };
20212
+ var AnalyticsFunctions$1 = {
20213
+ initializeLog: function initializeLog(log) {
20214
+ this.log = AnalyticsUtils.initializeLog(log);
20178
20215
  },
20179
20216
  getTimeSpent: function getTimeSpent() {
20180
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
20181
- this.log.time_spent = currentTimeInSeconds - this.log.start_time;
20217
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20182
20218
  return this.log.time_spent;
20183
20219
  },
20184
20220
  logPageOpen: function logPageOpen() {
@@ -20262,9 +20298,9 @@ var Paystack = (function (exports) {
20262
20298
  return false;
20263
20299
  }
20264
20300
  },
20265
- logMobileMoneyActions: function logMobileMoneyActions(_ref2) {
20266
- var numberOfTokenRequests = _ref2.numberOfTokenRequests,
20267
- registrationToken = _ref2.registrationToken;
20301
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20302
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20303
+ registrationToken = _ref.registrationToken;
20268
20304
 
20269
20305
  if (numberOfTokenRequests) {
20270
20306
  this.logTokenRequest('mobile money', numberOfTokenRequests);
@@ -20390,9 +20426,10 @@ var Paystack = (function (exports) {
20390
20426
  });
20391
20427
  return this.saveLog();
20392
20428
  },
20393
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20394
- var currency = _ref3.currency,
20395
- isUserAction = _ref3.isUserAction;
20429
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20430
+ var currency = _ref2.currency,
20431
+ _ref2$isUserAction = _ref2.isUserAction,
20432
+ isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20396
20433
  var prefix = isUserAction ? 'User switched' : 'Switched';
20397
20434
  this.log.history.push({
20398
20435
  type: 'action',
@@ -20470,7 +20507,7 @@ var Paystack = (function (exports) {
20470
20507
  loadPusher(); // Analytics
20471
20508
 
20472
20509
  this.log = null;
20473
- Object.assign(this, AnalyticsFunctions);
20510
+ Object.assign(this, AnalyticsFunctions$1);
20474
20511
  this.initializeLog(data.log);
20475
20512
  this.saveIpAddress(); // Bind charge functions for the available channels
20476
20513
 
@@ -20977,9 +21014,9 @@ var Paystack = (function (exports) {
20977
21014
  publicKey = _ref.publicKey,
20978
21015
  _ref$customFields = _ref.customFields,
20979
21016
  customFields = _ref$customFields === void 0 ? {} : _ref$customFields;
20980
- // TODO: Log payment method
20981
- // https://paystack.atlassian.net/browse/RAILS-3070
20982
21017
  return validate(this.card).then(function () {
21018
+ _this2.logAttempt(paymentMethod);
21019
+
20983
21020
  var chargeParams = {
20984
21021
  clientdata: _this2.card.tokenize(),
20985
21022
  last4: _this2.card.getLast4(),
@@ -20988,8 +21025,8 @@ var Paystack = (function (exports) {
20988
21025
  customFields: customFields
20989
21026
  };
20990
21027
  return CardAPI.reserveFunds(chargeParams).then(function (response) {
20991
- // TODO: Log API Response
20992
- // https://paystack.atlassian.net/browse/RAILS-3070
21028
+ _this2.logAPIResponse(response, paymentMethod);
21029
+
20993
21030
  return response;
20994
21031
  });
20995
21032
  });
@@ -21038,6 +21075,191 @@ var Paystack = (function (exports) {
21038
21075
  }
21039
21076
  };
21040
21077
 
21078
+ var PreauthorizationAnalyticsAPI = {
21079
+ saveLog: function saveLog(preauthorizationId, merchantKey, log) {
21080
+ var url = new URL("preauthorization/update_log/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21081
+ return AnalyticsAPIUtils.saveLog(url, {
21082
+ merchantKey: merchantKey,
21083
+ log: log
21084
+ });
21085
+ },
21086
+ getIp: function getIp() {
21087
+ return AnalyticsAPIUtils.getIp();
21088
+ },
21089
+ saveIp: function saveIp(preauthorizationId, merchantKey) {
21090
+ var url = new URL("preauthorization/set_ip/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21091
+ return AnalyticsAPIUtils.saveIp(url, {
21092
+ merchantKey: merchantKey
21093
+ });
21094
+ },
21095
+ saveReferrer: function saveReferrer(preauthorizationId, merchantKey, referrer) {
21096
+ var url = new URL("preauthorization/set_referrer/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21097
+ return AnalyticsAPIUtils.saveReferrer(url, {
21098
+ merchantKey: merchantKey,
21099
+ referrer: referrer
21100
+ });
21101
+ }
21102
+ };
21103
+
21104
+ var AnalyticsFunctions = {
21105
+ initializeLog: function initializeLog(log) {
21106
+ this.log = AnalyticsUtils.initializeLog(log);
21107
+ },
21108
+ getTimeSpent: function getTimeSpent() {
21109
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
21110
+ return this.log.time_spent;
21111
+ },
21112
+ logPageOpen: function logPageOpen() {
21113
+ this.log.history.push({
21114
+ type: 'open',
21115
+ message: 'Opened checkout',
21116
+ time: this.getTimeSpent()
21117
+ });
21118
+ return this.saveLog();
21119
+ },
21120
+ logChannelSwitch: function logChannelSwitch(value) {
21121
+ this.log.history.push({
21122
+ type: 'action',
21123
+ message: "Set payment method to: ".concat(value),
21124
+ time: this.getTimeSpent()
21125
+ });
21126
+ return this.saveLog();
21127
+ },
21128
+ logValidationErrors: function logValidationErrors(inputs) {
21129
+ var _this = this;
21130
+
21131
+ inputs.forEach(function (input) {
21132
+ _this.log.history.push({
21133
+ type: 'error',
21134
+ message: "Invalid ".concat(input),
21135
+ time: _this.getTimeSpent()
21136
+ });
21137
+ });
21138
+ return this.saveLog();
21139
+ },
21140
+ logInput: function logInput(value) {
21141
+ var isUpdate = this.log.history.find(function (item) {
21142
+ return item.message === "Filled this field: ".concat(value);
21143
+ });
21144
+ this.log.history.push({
21145
+ type: 'input',
21146
+ message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
21147
+ time: this.getTimeSpent()
21148
+ });
21149
+ return this.saveLog();
21150
+ },
21151
+ logAuthWindowOpen: function logAuthWindowOpen() {
21152
+ this.log.history.push({
21153
+ type: 'action',
21154
+ message: 'Third-party authentication window opened',
21155
+ time: this.getTimeSpent()
21156
+ });
21157
+ return this.saveLog();
21158
+ },
21159
+ logAuthWindowClose: function logAuthWindowClose() {
21160
+ this.log.history.push({
21161
+ type: 'action',
21162
+ message: 'Third-party authentication window closed',
21163
+ time: this.getTimeSpent()
21164
+ });
21165
+ return this.saveLog();
21166
+ },
21167
+ logAPIResponse: function logAPIResponse(response, channel) {
21168
+ switch (response.status) {
21169
+ case 'success':
21170
+ return this.logSuccess(channel);
21171
+
21172
+ case 'failed':
21173
+ return this.logError(response.message);
21174
+
21175
+ case 'auth':
21176
+ return this.logAuth(response.data.auth);
21177
+
21178
+ default:
21179
+ return false;
21180
+ }
21181
+ },
21182
+ logAPIResponseMessage: function logAPIResponseMessage(message) {
21183
+ this.log.history.push({
21184
+ type: 'action',
21185
+ message: message,
21186
+ time: this.getTimeSpent()
21187
+ });
21188
+ return this.saveLog();
21189
+ },
21190
+ logAttempt: function logAttempt(channel) {
21191
+ var message = 'Attempted to pay';
21192
+
21193
+ if (channel) {
21194
+ message += " with ".concat(channel);
21195
+ }
21196
+
21197
+ this.log.attempts += 1;
21198
+ this.log.history.push({
21199
+ type: 'action',
21200
+ message: message,
21201
+ time: this.getTimeSpent()
21202
+ });
21203
+ return this.saveLog();
21204
+ },
21205
+ logAuth: function logAuth(value) {
21206
+ this.log.authentication = value;
21207
+ this.log.history.push({
21208
+ type: 'auth',
21209
+ message: "Authentication Required: ".concat(value),
21210
+ time: this.getTimeSpent()
21211
+ });
21212
+ return this.saveLog();
21213
+ },
21214
+ logSuccess: function logSuccess(channel) {
21215
+ var message = 'Successfully reserved funds';
21216
+
21217
+ if (channel) {
21218
+ message += " with ".concat(channel);
21219
+ }
21220
+
21221
+ this.log.success = true;
21222
+ this.log.history.push({
21223
+ type: 'success',
21224
+ message: message,
21225
+ time: this.getTimeSpent()
21226
+ });
21227
+ return this.saveLog();
21228
+ },
21229
+ logPageClose: function logPageClose() {
21230
+ this.log.history.push({
21231
+ type: 'close',
21232
+ message: 'Closed checkout',
21233
+ time: this.getTimeSpent()
21234
+ });
21235
+ return this.saveLog();
21236
+ },
21237
+ logError: function logError(error) {
21238
+ var message = 'Error';
21239
+
21240
+ if (error) {
21241
+ message += ": ".concat(error);
21242
+ }
21243
+
21244
+ this.log.errors += 1;
21245
+ this.log.history.push({
21246
+ type: 'error',
21247
+ message: message,
21248
+ time: this.getTimeSpent()
21249
+ });
21250
+ return this.saveLog();
21251
+ },
21252
+ saveLog: function saveLog() {
21253
+ return PreauthorizationAnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
21254
+ },
21255
+ saveIpAddress: function saveIpAddress() {
21256
+ return PreauthorizationAnalyticsAPI.saveIp(this.id, this.merchant.key);
21257
+ },
21258
+ saveReferrer: function saveReferrer(referrer) {
21259
+ return PreauthorizationAnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
21260
+ }
21261
+ };
21262
+
21041
21263
  var PreauthorizationInstance = /*#__PURE__*/function () {
21042
21264
  function PreauthorizationInstance(data) {
21043
21265
  _classCallCheck(this, PreauthorizationInstance);
@@ -21060,9 +21282,11 @@ var Paystack = (function (exports) {
21060
21282
  key: data.merchant_key
21061
21283
  };
21062
21284
  this.card = {};
21063
- loadPusher(); // TODO: Analytics
21064
- // https://paystack.atlassian.net/browse/RAILS-3070
21065
-
21285
+ loadPusher();
21286
+ this.log = null;
21287
+ Object.assign(this, AnalyticsFunctions);
21288
+ this.initializeLog(data.log);
21289
+ this.saveIpAddress();
21066
21290
  Object.assign(this, CardPreauthorization);
21067
21291
  }
21068
21292
 
@@ -21114,20 +21338,6 @@ var Paystack = (function (exports) {
21114
21338
  }
21115
21339
  }, _callee);
21116
21340
  }))();
21117
- },
21118
- verify: function verify() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
21119
-
21120
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
21121
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
21122
- while (1) {
21123
- switch (_context2.prev = _context2.next) {
21124
- case 0:
21125
- case "end":
21126
- return _context2.stop();
21127
- }
21128
- }
21129
- }, _callee2);
21130
- }))();
21131
21341
  }
21132
21342
  };
21133
21343