@paystack/checkout-js 1.22.0-dev.5 → 1.22.0-dev.7

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
@@ -20041,6 +20041,32 @@ var Paystack = (function (exports) {
20041
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));
20042
20042
  }
20043
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
+
20044
20070
  var $ = _export;
20045
20071
  var global$1 = global$R;
20046
20072
  var getBuiltIn = getBuiltIn$a;
@@ -20087,9 +20113,8 @@ var Paystack = (function (exports) {
20087
20113
  });
20088
20114
  }
20089
20115
 
20090
- var AnalyticsAPI = {
20091
- saveLog: function saveLog(transactionId, merchantKey, log) {
20092
- var url = "".concat(configToUse.paystackApiUrl, "transaction/update_log/").concat(transactionId);
20116
+ var AnalyticsAPIUtils = {
20117
+ saveLog: function saveLog(url, merchantKey, log) {
20093
20118
  var language = getLanguage();
20094
20119
 
20095
20120
  var headers = _objectSpread2({
@@ -20120,8 +20145,7 @@ var Paystack = (function (exports) {
20120
20145
  return response.data.data.ip_address;
20121
20146
  });
20122
20147
  },
20123
- saveIp: function saveIp(transactionId, merchantKey) {
20124
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_ip/").concat(transactionId);
20148
+ saveIp: function saveIp(url, merchantKey) {
20125
20149
  var language = getLanguage();
20126
20150
 
20127
20151
  var headers = _objectSpread2({
@@ -20136,8 +20160,7 @@ var Paystack = (function (exports) {
20136
20160
  return response.data;
20137
20161
  });
20138
20162
  },
20139
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20140
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_referrer/").concat(transactionId);
20163
+ saveReferrer: function saveReferrer(url, merchantKey, referrer) {
20141
20164
  var language = getLanguage();
20142
20165
 
20143
20166
  var headers = _objectSpread2({
@@ -20156,29 +20179,30 @@ var Paystack = (function (exports) {
20156
20179
  }
20157
20180
  };
20158
20181
 
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;
20182
+ var AnalyticsAPI = {
20183
+ saveLog: function saveLog(transactionId, merchantKey, log) {
20184
+ var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
20185
+ return AnalyticsAPIUtils.saveLog(url, merchantKey, log);
20186
+ },
20187
+ getIp: function getIp() {
20188
+ return AnalyticsAPIUtils.getIp();
20189
+ },
20190
+ saveIp: function saveIp(transactionId, merchantKey) {
20191
+ var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
20192
+ return AnalyticsAPIUtils.saveIp(url, merchantKey);
20193
+ },
20194
+ saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20195
+ var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
20196
+ return AnalyticsAPIUtils.saveReferrer(url, merchantKey, referrer);
20197
+ }
20198
+ };
20166
20199
 
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
- };
20200
+ var AnalyticsFunctions$1 = {
20201
+ initializeLog: function initializeLog(log) {
20202
+ this.log = AnalyticsUtils.initializeLog(log);
20178
20203
  },
20179
20204
  getTimeSpent: function getTimeSpent() {
20180
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
20181
- this.log.time_spent = currentTimeInSeconds - this.log.start_time;
20205
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20182
20206
  return this.log.time_spent;
20183
20207
  },
20184
20208
  logPageOpen: function logPageOpen() {
@@ -20262,9 +20286,9 @@ var Paystack = (function (exports) {
20262
20286
  return false;
20263
20287
  }
20264
20288
  },
20265
- logMobileMoneyActions: function logMobileMoneyActions(_ref2) {
20266
- var numberOfTokenRequests = _ref2.numberOfTokenRequests,
20267
- registrationToken = _ref2.registrationToken;
20289
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20290
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20291
+ registrationToken = _ref.registrationToken;
20268
20292
 
20269
20293
  if (numberOfTokenRequests) {
20270
20294
  this.logTokenRequest('mobile money', numberOfTokenRequests);
@@ -20390,10 +20414,10 @@ var Paystack = (function (exports) {
20390
20414
  });
20391
20415
  return this.saveLog();
20392
20416
  },
20393
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20394
- var currency = _ref3.currency,
20395
- _ref3$isUserAction = _ref3.isUserAction,
20396
- isUserAction = _ref3$isUserAction === void 0 ? true : _ref3$isUserAction;
20417
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20418
+ var currency = _ref2.currency,
20419
+ _ref2$isUserAction = _ref2.isUserAction,
20420
+ isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20397
20421
  var prefix = isUserAction ? 'User switched' : 'Switched';
20398
20422
  this.log.history.push({
20399
20423
  type: 'action',
@@ -20471,7 +20495,7 @@ var Paystack = (function (exports) {
20471
20495
  loadPusher(); // Analytics
20472
20496
 
20473
20497
  this.log = null;
20474
- Object.assign(this, AnalyticsFunctions);
20498
+ Object.assign(this, AnalyticsFunctions$1);
20475
20499
  this.initializeLog(data.log);
20476
20500
  this.saveIpAddress(); // Bind charge functions for the available channels
20477
20501
 
@@ -20978,9 +21002,9 @@ var Paystack = (function (exports) {
20978
21002
  publicKey = _ref.publicKey,
20979
21003
  _ref$customFields = _ref.customFields,
20980
21004
  customFields = _ref$customFields === void 0 ? {} : _ref$customFields;
20981
- // TODO: Log payment method
20982
- // https://paystack.atlassian.net/browse/RAILS-3070
20983
21005
  return validate(this.card).then(function () {
21006
+ _this2.logAttempt(paymentMethod);
21007
+
20984
21008
  var chargeParams = {
20985
21009
  clientdata: _this2.card.tokenize(),
20986
21010
  last4: _this2.card.getLast4(),
@@ -20989,8 +21013,8 @@ var Paystack = (function (exports) {
20989
21013
  customFields: customFields
20990
21014
  };
20991
21015
  return CardAPI.reserveFunds(chargeParams).then(function (response) {
20992
- // TODO: Log API Response
20993
- // https://paystack.atlassian.net/browse/RAILS-3070
21016
+ _this2.logAPIResponse(response, paymentMethod);
21017
+
20994
21018
  return response;
20995
21019
  });
20996
21020
  });
@@ -21039,6 +21063,200 @@ var Paystack = (function (exports) {
21039
21063
  }
21040
21064
  };
21041
21065
 
21066
+ var PreauthorizationAnalyticsAPI = {
21067
+ saveLog: function saveLog(preauthorizationId, merchantKey, log) {
21068
+ var url = new URL("preauthorization/update_log/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21069
+ return AnalyticsAPIUtils.saveLog(url, merchantKey, log);
21070
+ },
21071
+ getIp: function getIp() {
21072
+ return AnalyticsAPIUtils.getIp();
21073
+ },
21074
+ saveIp: function saveIp(preauthorizationId, merchantKey) {
21075
+ var url = new URL("preauthorization/set_ip/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21076
+ return AnalyticsAPIUtils.saveIp(url, merchantKey);
21077
+ },
21078
+ saveReferrer: function saveReferrer(preauthorizationId, merchantKey, referrer) {
21079
+ var url = new URL("preauthorization/set_referrer/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21080
+ return AnalyticsAPIUtils.saveReferrer(url, merchantKey, referrer);
21081
+ }
21082
+ };
21083
+
21084
+ var AnalyticsFunctions = {
21085
+ initializeLog: function initializeLog(log) {
21086
+ this.log = AnalyticsUtils.initializeLog(log);
21087
+ },
21088
+ getTimeSpent: function getTimeSpent() {
21089
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
21090
+ return this.log.time_spent;
21091
+ },
21092
+ logPageOpen: function logPageOpen() {
21093
+ this.log.history.push({
21094
+ type: 'open',
21095
+ message: 'Opened checkout',
21096
+ time: this.getTimeSpent()
21097
+ });
21098
+ return this.saveLog();
21099
+ },
21100
+ logChannelSwitch: function logChannelSwitch(value) {
21101
+ this.log.history.push({
21102
+ type: 'action',
21103
+ message: "Set payment method to: ".concat(value),
21104
+ time: this.getTimeSpent()
21105
+ });
21106
+ return this.saveLog();
21107
+ },
21108
+ logValidationErrors: function logValidationErrors(inputs) {
21109
+ var _this = this;
21110
+
21111
+ inputs.forEach(function (input) {
21112
+ _this.log.history.push({
21113
+ type: 'error',
21114
+ message: "Invalid ".concat(input),
21115
+ time: _this.getTimeSpent()
21116
+ });
21117
+ });
21118
+ return this.saveLog();
21119
+ },
21120
+ logInput: function logInput(value) {
21121
+ var isUpdate = this.log.history.find(function (item) {
21122
+ return item.message === "Filled this field: ".concat(value);
21123
+ });
21124
+ this.log.history.push({
21125
+ type: 'input',
21126
+ message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
21127
+ time: this.getTimeSpent()
21128
+ });
21129
+ return this.saveLog();
21130
+ },
21131
+ logAuthWindowOpen: function logAuthWindowOpen() {
21132
+ this.log.history.push({
21133
+ type: 'action',
21134
+ message: 'Third-party authentication window opened',
21135
+ time: this.getTimeSpent()
21136
+ });
21137
+ return this.saveLog();
21138
+ },
21139
+ logAuthWindowClose: function logAuthWindowClose() {
21140
+ this.log.history.push({
21141
+ type: 'action',
21142
+ message: 'Third-party authentication window closed',
21143
+ time: this.getTimeSpent()
21144
+ });
21145
+ return this.saveLog();
21146
+ },
21147
+ logAPIResponse: function logAPIResponse(response, channel) {
21148
+ switch (response.status) {
21149
+ case 'success':
21150
+ return this.logSuccess(channel);
21151
+
21152
+ case 'pending':
21153
+ return this.logPending(channel);
21154
+
21155
+ case 'failed':
21156
+ return this.logError(response.message);
21157
+
21158
+ case 'auth':
21159
+ return this.logAuth(response.data.auth);
21160
+
21161
+ default:
21162
+ return false;
21163
+ }
21164
+ },
21165
+ logAPIResponseMessage: function logAPIResponseMessage(message) {
21166
+ this.log.history.push({
21167
+ type: 'action',
21168
+ message: message,
21169
+ time: this.getTimeSpent()
21170
+ });
21171
+ return this.saveLog();
21172
+ },
21173
+ logAttempt: function logAttempt(channel) {
21174
+ var message = 'Attempted to pay';
21175
+
21176
+ if (channel) {
21177
+ message += " with ".concat(channel);
21178
+ }
21179
+
21180
+ this.log.attempts += 1;
21181
+ this.log.history.push({
21182
+ type: 'action',
21183
+ message: message,
21184
+ time: this.getTimeSpent()
21185
+ });
21186
+ return this.saveLog();
21187
+ },
21188
+ logAuth: function logAuth(value) {
21189
+ this.log.authentication = value;
21190
+ this.log.history.push({
21191
+ type: 'auth',
21192
+ message: "Authentication Required: ".concat(value),
21193
+ time: this.getTimeSpent()
21194
+ });
21195
+ return this.saveLog();
21196
+ },
21197
+ logSuccess: function logSuccess(channel) {
21198
+ var message = 'Successfully paid';
21199
+
21200
+ if (channel) {
21201
+ message += " with ".concat(channel);
21202
+ }
21203
+
21204
+ this.log.success = true;
21205
+ this.log.history.push({
21206
+ type: 'success',
21207
+ message: message,
21208
+ time: this.getTimeSpent()
21209
+ });
21210
+ return this.saveLog();
21211
+ },
21212
+ logPending: function logPending(channel) {
21213
+ var message = 'Payment in progress';
21214
+
21215
+ if (channel) {
21216
+ message += " with ".concat(channel);
21217
+ }
21218
+
21219
+ this.log.history.push({
21220
+ type: 'pending',
21221
+ message: message,
21222
+ time: this.getTimeSpent()
21223
+ });
21224
+ return this.saveLog();
21225
+ },
21226
+ logPageClose: function logPageClose() {
21227
+ this.log.history.push({
21228
+ type: 'close',
21229
+ message: 'Closed checkout',
21230
+ time: this.getTimeSpent()
21231
+ });
21232
+ return this.saveLog();
21233
+ },
21234
+ logError: function logError(error) {
21235
+ var message = 'Error';
21236
+
21237
+ if (error) {
21238
+ message += ": ".concat(error);
21239
+ }
21240
+
21241
+ this.log.errors += 1;
21242
+ this.log.history.push({
21243
+ type: 'error',
21244
+ message: message,
21245
+ time: this.getTimeSpent()
21246
+ });
21247
+ return this.saveLog();
21248
+ },
21249
+ saveLog: function saveLog() {
21250
+ return PreauthorizationAnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
21251
+ },
21252
+ saveIpAddress: function saveIpAddress() {
21253
+ return PreauthorizationAnalyticsAPI.saveIp(this.id, this.merchant.key);
21254
+ },
21255
+ saveReferrer: function saveReferrer(referrer) {
21256
+ return PreauthorizationAnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
21257
+ }
21258
+ };
21259
+
21042
21260
  var PreauthorizationInstance = /*#__PURE__*/function () {
21043
21261
  function PreauthorizationInstance(data) {
21044
21262
  _classCallCheck(this, PreauthorizationInstance);
@@ -21061,9 +21279,11 @@ var Paystack = (function (exports) {
21061
21279
  key: data.merchant_key
21062
21280
  };
21063
21281
  this.card = {};
21064
- loadPusher(); // TODO: Analytics
21065
- // https://paystack.atlassian.net/browse/RAILS-3070
21066
-
21282
+ loadPusher();
21283
+ this.log = null;
21284
+ Object.assign(this, AnalyticsFunctions);
21285
+ this.initializeLog(data.log);
21286
+ this.saveIpAddress();
21067
21287
  Object.assign(this, CardPreauthorization);
21068
21288
  }
21069
21289
 
@@ -21115,20 +21335,6 @@ var Paystack = (function (exports) {
21115
21335
  }
21116
21336
  }, _callee);
21117
21337
  }))();
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
21338
  }
21133
21339
  };
21134
21340
 
package/es/checkout.js CHANGED
@@ -20038,6 +20038,32 @@ function isMobile (ua) {
20038
20038
  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));
20039
20039
  }
20040
20040
 
20041
+ var AnalyticsUtils = {
20042
+ initializeLog: function initializeLog(log) {
20043
+ var _ref = log || {},
20044
+ attempts = _ref.attempts,
20045
+ authentication = _ref.authentication,
20046
+ errors = _ref.errors,
20047
+ history = _ref.history;
20048
+
20049
+ return {
20050
+ start_time: Math.round(Date.now() / 1000),
20051
+ time_spent: 0,
20052
+ attempts: attempts || 0,
20053
+ authentication: authentication,
20054
+ errors: errors || 0,
20055
+ success: false,
20056
+ mobile: isMobile_1(),
20057
+ input: [],
20058
+ history: history || []
20059
+ };
20060
+ },
20061
+ getTimeSpent: function getTimeSpent(startTime) {
20062
+ var currentTimeInSeconds = Math.round(Date.now() / 1000);
20063
+ return currentTimeInSeconds - startTime;
20064
+ }
20065
+ };
20066
+
20041
20067
  var $ = _export;
20042
20068
  var global$1 = global$R;
20043
20069
  var getBuiltIn = getBuiltIn$a;
@@ -20084,9 +20110,8 @@ if ($stringify) {
20084
20110
  });
20085
20111
  }
20086
20112
 
20087
- var AnalyticsAPI = {
20088
- saveLog: function saveLog(transactionId, merchantKey, log) {
20089
- var url = "".concat(configToUse.paystackApiUrl, "transaction/update_log/").concat(transactionId);
20113
+ var AnalyticsAPIUtils = {
20114
+ saveLog: function saveLog(url, merchantKey, log) {
20090
20115
  var language = getLanguage();
20091
20116
 
20092
20117
  var headers = _objectSpread2({
@@ -20117,8 +20142,7 @@ var AnalyticsAPI = {
20117
20142
  return response.data.data.ip_address;
20118
20143
  });
20119
20144
  },
20120
- saveIp: function saveIp(transactionId, merchantKey) {
20121
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_ip/").concat(transactionId);
20145
+ saveIp: function saveIp(url, merchantKey) {
20122
20146
  var language = getLanguage();
20123
20147
 
20124
20148
  var headers = _objectSpread2({
@@ -20133,8 +20157,7 @@ var AnalyticsAPI = {
20133
20157
  return response.data;
20134
20158
  });
20135
20159
  },
20136
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20137
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_referrer/").concat(transactionId);
20160
+ saveReferrer: function saveReferrer(url, merchantKey, referrer) {
20138
20161
  var language = getLanguage();
20139
20162
 
20140
20163
  var headers = _objectSpread2({
@@ -20153,29 +20176,30 @@ var AnalyticsAPI = {
20153
20176
  }
20154
20177
  };
20155
20178
 
20156
- var AnalyticsFunctions = {
20157
- initializeLog: function initializeLog(log) {
20158
- var _ref = log || {},
20159
- attempts = _ref.attempts,
20160
- authentication = _ref.authentication,
20161
- errors = _ref.errors,
20162
- history = _ref.history;
20179
+ var AnalyticsAPI = {
20180
+ saveLog: function saveLog(transactionId, merchantKey, log) {
20181
+ var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
20182
+ return AnalyticsAPIUtils.saveLog(url, merchantKey, log);
20183
+ },
20184
+ getIp: function getIp() {
20185
+ return AnalyticsAPIUtils.getIp();
20186
+ },
20187
+ saveIp: function saveIp(transactionId, merchantKey) {
20188
+ var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
20189
+ return AnalyticsAPIUtils.saveIp(url, merchantKey);
20190
+ },
20191
+ saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20192
+ var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
20193
+ return AnalyticsAPIUtils.saveReferrer(url, merchantKey, referrer);
20194
+ }
20195
+ };
20163
20196
 
20164
- this.log = {
20165
- start_time: Math.round(Date.now() / 1000),
20166
- time_spent: 0,
20167
- attempts: attempts || 0,
20168
- authentication: authentication,
20169
- errors: errors || 0,
20170
- success: false,
20171
- mobile: isMobile_1(),
20172
- input: [],
20173
- history: history || []
20174
- };
20197
+ var AnalyticsFunctions$1 = {
20198
+ initializeLog: function initializeLog(log) {
20199
+ this.log = AnalyticsUtils.initializeLog(log);
20175
20200
  },
20176
20201
  getTimeSpent: function getTimeSpent() {
20177
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
20178
- this.log.time_spent = currentTimeInSeconds - this.log.start_time;
20202
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20179
20203
  return this.log.time_spent;
20180
20204
  },
20181
20205
  logPageOpen: function logPageOpen() {
@@ -20259,9 +20283,9 @@ var AnalyticsFunctions = {
20259
20283
  return false;
20260
20284
  }
20261
20285
  },
20262
- logMobileMoneyActions: function logMobileMoneyActions(_ref2) {
20263
- var numberOfTokenRequests = _ref2.numberOfTokenRequests,
20264
- registrationToken = _ref2.registrationToken;
20286
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20287
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20288
+ registrationToken = _ref.registrationToken;
20265
20289
 
20266
20290
  if (numberOfTokenRequests) {
20267
20291
  this.logTokenRequest('mobile money', numberOfTokenRequests);
@@ -20387,10 +20411,10 @@ var AnalyticsFunctions = {
20387
20411
  });
20388
20412
  return this.saveLog();
20389
20413
  },
20390
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20391
- var currency = _ref3.currency,
20392
- _ref3$isUserAction = _ref3.isUserAction,
20393
- isUserAction = _ref3$isUserAction === void 0 ? true : _ref3$isUserAction;
20414
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20415
+ var currency = _ref2.currency,
20416
+ _ref2$isUserAction = _ref2.isUserAction,
20417
+ isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20394
20418
  var prefix = isUserAction ? 'User switched' : 'Switched';
20395
20419
  this.log.history.push({
20396
20420
  type: 'action',
@@ -20468,7 +20492,7 @@ var TransactionInstance = /*#__PURE__*/function () {
20468
20492
  loadPusher(); // Analytics
20469
20493
 
20470
20494
  this.log = null;
20471
- Object.assign(this, AnalyticsFunctions);
20495
+ Object.assign(this, AnalyticsFunctions$1);
20472
20496
  this.initializeLog(data.log);
20473
20497
  this.saveIpAddress(); // Bind charge functions for the available channels
20474
20498
 
@@ -20975,9 +20999,9 @@ var CardPreauthorization = {
20975
20999
  publicKey = _ref.publicKey,
20976
21000
  _ref$customFields = _ref.customFields,
20977
21001
  customFields = _ref$customFields === void 0 ? {} : _ref$customFields;
20978
- // TODO: Log payment method
20979
- // https://paystack.atlassian.net/browse/RAILS-3070
20980
21002
  return validate(this.card).then(function () {
21003
+ _this2.logAttempt(paymentMethod);
21004
+
20981
21005
  var chargeParams = {
20982
21006
  clientdata: _this2.card.tokenize(),
20983
21007
  last4: _this2.card.getLast4(),
@@ -20986,8 +21010,8 @@ var CardPreauthorization = {
20986
21010
  customFields: customFields
20987
21011
  };
20988
21012
  return CardAPI.reserveFunds(chargeParams).then(function (response) {
20989
- // TODO: Log API Response
20990
- // https://paystack.atlassian.net/browse/RAILS-3070
21013
+ _this2.logAPIResponse(response, paymentMethod);
21014
+
20991
21015
  return response;
20992
21016
  });
20993
21017
  });
@@ -21036,6 +21060,200 @@ var PreauthorisationAPI = {
21036
21060
  }
21037
21061
  };
21038
21062
 
21063
+ var PreauthorizationAnalyticsAPI = {
21064
+ saveLog: function saveLog(preauthorizationId, merchantKey, log) {
21065
+ var url = new URL("preauthorization/update_log/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21066
+ return AnalyticsAPIUtils.saveLog(url, merchantKey, log);
21067
+ },
21068
+ getIp: function getIp() {
21069
+ return AnalyticsAPIUtils.getIp();
21070
+ },
21071
+ saveIp: function saveIp(preauthorizationId, merchantKey) {
21072
+ var url = new URL("preauthorization/set_ip/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21073
+ return AnalyticsAPIUtils.saveIp(url, merchantKey);
21074
+ },
21075
+ saveReferrer: function saveReferrer(preauthorizationId, merchantKey, referrer) {
21076
+ var url = new URL("preauthorization/set_referrer/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21077
+ return AnalyticsAPIUtils.saveReferrer(url, merchantKey, referrer);
21078
+ }
21079
+ };
21080
+
21081
+ var AnalyticsFunctions = {
21082
+ initializeLog: function initializeLog(log) {
21083
+ this.log = AnalyticsUtils.initializeLog(log);
21084
+ },
21085
+ getTimeSpent: function getTimeSpent() {
21086
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
21087
+ return this.log.time_spent;
21088
+ },
21089
+ logPageOpen: function logPageOpen() {
21090
+ this.log.history.push({
21091
+ type: 'open',
21092
+ message: 'Opened checkout',
21093
+ time: this.getTimeSpent()
21094
+ });
21095
+ return this.saveLog();
21096
+ },
21097
+ logChannelSwitch: function logChannelSwitch(value) {
21098
+ this.log.history.push({
21099
+ type: 'action',
21100
+ message: "Set payment method to: ".concat(value),
21101
+ time: this.getTimeSpent()
21102
+ });
21103
+ return this.saveLog();
21104
+ },
21105
+ logValidationErrors: function logValidationErrors(inputs) {
21106
+ var _this = this;
21107
+
21108
+ inputs.forEach(function (input) {
21109
+ _this.log.history.push({
21110
+ type: 'error',
21111
+ message: "Invalid ".concat(input),
21112
+ time: _this.getTimeSpent()
21113
+ });
21114
+ });
21115
+ return this.saveLog();
21116
+ },
21117
+ logInput: function logInput(value) {
21118
+ var isUpdate = this.log.history.find(function (item) {
21119
+ return item.message === "Filled this field: ".concat(value);
21120
+ });
21121
+ this.log.history.push({
21122
+ type: 'input',
21123
+ message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
21124
+ time: this.getTimeSpent()
21125
+ });
21126
+ return this.saveLog();
21127
+ },
21128
+ logAuthWindowOpen: function logAuthWindowOpen() {
21129
+ this.log.history.push({
21130
+ type: 'action',
21131
+ message: 'Third-party authentication window opened',
21132
+ time: this.getTimeSpent()
21133
+ });
21134
+ return this.saveLog();
21135
+ },
21136
+ logAuthWindowClose: function logAuthWindowClose() {
21137
+ this.log.history.push({
21138
+ type: 'action',
21139
+ message: 'Third-party authentication window closed',
21140
+ time: this.getTimeSpent()
21141
+ });
21142
+ return this.saveLog();
21143
+ },
21144
+ logAPIResponse: function logAPIResponse(response, channel) {
21145
+ switch (response.status) {
21146
+ case 'success':
21147
+ return this.logSuccess(channel);
21148
+
21149
+ case 'pending':
21150
+ return this.logPending(channel);
21151
+
21152
+ case 'failed':
21153
+ return this.logError(response.message);
21154
+
21155
+ case 'auth':
21156
+ return this.logAuth(response.data.auth);
21157
+
21158
+ default:
21159
+ return false;
21160
+ }
21161
+ },
21162
+ logAPIResponseMessage: function logAPIResponseMessage(message) {
21163
+ this.log.history.push({
21164
+ type: 'action',
21165
+ message: message,
21166
+ time: this.getTimeSpent()
21167
+ });
21168
+ return this.saveLog();
21169
+ },
21170
+ logAttempt: function logAttempt(channel) {
21171
+ var message = 'Attempted to pay';
21172
+
21173
+ if (channel) {
21174
+ message += " with ".concat(channel);
21175
+ }
21176
+
21177
+ this.log.attempts += 1;
21178
+ this.log.history.push({
21179
+ type: 'action',
21180
+ message: message,
21181
+ time: this.getTimeSpent()
21182
+ });
21183
+ return this.saveLog();
21184
+ },
21185
+ logAuth: function logAuth(value) {
21186
+ this.log.authentication = value;
21187
+ this.log.history.push({
21188
+ type: 'auth',
21189
+ message: "Authentication Required: ".concat(value),
21190
+ time: this.getTimeSpent()
21191
+ });
21192
+ return this.saveLog();
21193
+ },
21194
+ logSuccess: function logSuccess(channel) {
21195
+ var message = 'Successfully paid';
21196
+
21197
+ if (channel) {
21198
+ message += " with ".concat(channel);
21199
+ }
21200
+
21201
+ this.log.success = true;
21202
+ this.log.history.push({
21203
+ type: 'success',
21204
+ message: message,
21205
+ time: this.getTimeSpent()
21206
+ });
21207
+ return this.saveLog();
21208
+ },
21209
+ logPending: function logPending(channel) {
21210
+ var message = 'Payment in progress';
21211
+
21212
+ if (channel) {
21213
+ message += " with ".concat(channel);
21214
+ }
21215
+
21216
+ this.log.history.push({
21217
+ type: 'pending',
21218
+ message: message,
21219
+ time: this.getTimeSpent()
21220
+ });
21221
+ return this.saveLog();
21222
+ },
21223
+ logPageClose: function logPageClose() {
21224
+ this.log.history.push({
21225
+ type: 'close',
21226
+ message: 'Closed checkout',
21227
+ time: this.getTimeSpent()
21228
+ });
21229
+ return this.saveLog();
21230
+ },
21231
+ logError: function logError(error) {
21232
+ var message = 'Error';
21233
+
21234
+ if (error) {
21235
+ message += ": ".concat(error);
21236
+ }
21237
+
21238
+ this.log.errors += 1;
21239
+ this.log.history.push({
21240
+ type: 'error',
21241
+ message: message,
21242
+ time: this.getTimeSpent()
21243
+ });
21244
+ return this.saveLog();
21245
+ },
21246
+ saveLog: function saveLog() {
21247
+ return PreauthorizationAnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
21248
+ },
21249
+ saveIpAddress: function saveIpAddress() {
21250
+ return PreauthorizationAnalyticsAPI.saveIp(this.id, this.merchant.key);
21251
+ },
21252
+ saveReferrer: function saveReferrer(referrer) {
21253
+ return PreauthorizationAnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
21254
+ }
21255
+ };
21256
+
21039
21257
  var PreauthorizationInstance = /*#__PURE__*/function () {
21040
21258
  function PreauthorizationInstance(data) {
21041
21259
  _classCallCheck(this, PreauthorizationInstance);
@@ -21058,9 +21276,11 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
21058
21276
  key: data.merchant_key
21059
21277
  };
21060
21278
  this.card = {};
21061
- loadPusher(); // TODO: Analytics
21062
- // https://paystack.atlassian.net/browse/RAILS-3070
21063
-
21279
+ loadPusher();
21280
+ this.log = null;
21281
+ Object.assign(this, AnalyticsFunctions);
21282
+ this.initializeLog(data.log);
21283
+ this.saveIpAddress();
21064
21284
  Object.assign(this, CardPreauthorization);
21065
21285
  }
21066
21286
 
@@ -21112,20 +21332,6 @@ var Preauthorization = {
21112
21332
  }
21113
21333
  }, _callee);
21114
21334
  }))();
21115
- },
21116
- verify: function verify() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
21117
-
21118
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
21119
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
21120
- while (1) {
21121
- switch (_context2.prev = _context2.next) {
21122
- case 0:
21123
- case "end":
21124
- return _context2.stop();
21125
- }
21126
- }
21127
- }, _callee2);
21128
- }))();
21129
21335
  }
21130
21336
  };
21131
21337
 
package/lib/checkout.js CHANGED
@@ -20042,6 +20042,32 @@ function isMobile (ua) {
20042
20042
  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
20043
  }
20044
20044
 
20045
+ var AnalyticsUtils = {
20046
+ initializeLog: function initializeLog(log) {
20047
+ var _ref = log || {},
20048
+ attempts = _ref.attempts,
20049
+ authentication = _ref.authentication,
20050
+ errors = _ref.errors,
20051
+ history = _ref.history;
20052
+
20053
+ return {
20054
+ start_time: Math.round(Date.now() / 1000),
20055
+ time_spent: 0,
20056
+ attempts: attempts || 0,
20057
+ authentication: authentication,
20058
+ errors: errors || 0,
20059
+ success: false,
20060
+ mobile: isMobile_1(),
20061
+ input: [],
20062
+ history: history || []
20063
+ };
20064
+ },
20065
+ getTimeSpent: function getTimeSpent(startTime) {
20066
+ var currentTimeInSeconds = Math.round(Date.now() / 1000);
20067
+ return currentTimeInSeconds - startTime;
20068
+ }
20069
+ };
20070
+
20045
20071
  var $ = _export;
20046
20072
  var global$1 = global$R;
20047
20073
  var getBuiltIn = getBuiltIn$a;
@@ -20088,9 +20114,8 @@ if ($stringify) {
20088
20114
  });
20089
20115
  }
20090
20116
 
20091
- var AnalyticsAPI = {
20092
- saveLog: function saveLog(transactionId, merchantKey, log) {
20093
- var url = "".concat(configToUse.paystackApiUrl, "transaction/update_log/").concat(transactionId);
20117
+ var AnalyticsAPIUtils = {
20118
+ saveLog: function saveLog(url, merchantKey, log) {
20094
20119
  var language = getLanguage();
20095
20120
 
20096
20121
  var headers = _objectSpread2({
@@ -20121,8 +20146,7 @@ var AnalyticsAPI = {
20121
20146
  return response.data.data.ip_address;
20122
20147
  });
20123
20148
  },
20124
- saveIp: function saveIp(transactionId, merchantKey) {
20125
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_ip/").concat(transactionId);
20149
+ saveIp: function saveIp(url, merchantKey) {
20126
20150
  var language = getLanguage();
20127
20151
 
20128
20152
  var headers = _objectSpread2({
@@ -20137,8 +20161,7 @@ var AnalyticsAPI = {
20137
20161
  return response.data;
20138
20162
  });
20139
20163
  },
20140
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20141
- var url = "".concat(configToUse.paystackApiUrl, "transaction/set_referrer/").concat(transactionId);
20164
+ saveReferrer: function saveReferrer(url, merchantKey, referrer) {
20142
20165
  var language = getLanguage();
20143
20166
 
20144
20167
  var headers = _objectSpread2({
@@ -20157,29 +20180,30 @@ var AnalyticsAPI = {
20157
20180
  }
20158
20181
  };
20159
20182
 
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;
20183
+ var AnalyticsAPI = {
20184
+ saveLog: function saveLog(transactionId, merchantKey, log) {
20185
+ var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
20186
+ return AnalyticsAPIUtils.saveLog(url, merchantKey, log);
20187
+ },
20188
+ getIp: function getIp() {
20189
+ return AnalyticsAPIUtils.getIp();
20190
+ },
20191
+ saveIp: function saveIp(transactionId, merchantKey) {
20192
+ var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
20193
+ return AnalyticsAPIUtils.saveIp(url, merchantKey);
20194
+ },
20195
+ saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20196
+ var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
20197
+ return AnalyticsAPIUtils.saveReferrer(url, merchantKey, referrer);
20198
+ }
20199
+ };
20167
20200
 
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
- };
20201
+ var AnalyticsFunctions$1 = {
20202
+ initializeLog: function initializeLog(log) {
20203
+ this.log = AnalyticsUtils.initializeLog(log);
20179
20204
  },
20180
20205
  getTimeSpent: function getTimeSpent() {
20181
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
20182
- this.log.time_spent = currentTimeInSeconds - this.log.start_time;
20206
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20183
20207
  return this.log.time_spent;
20184
20208
  },
20185
20209
  logPageOpen: function logPageOpen() {
@@ -20263,9 +20287,9 @@ var AnalyticsFunctions = {
20263
20287
  return false;
20264
20288
  }
20265
20289
  },
20266
- logMobileMoneyActions: function logMobileMoneyActions(_ref2) {
20267
- var numberOfTokenRequests = _ref2.numberOfTokenRequests,
20268
- registrationToken = _ref2.registrationToken;
20290
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20291
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20292
+ registrationToken = _ref.registrationToken;
20269
20293
 
20270
20294
  if (numberOfTokenRequests) {
20271
20295
  this.logTokenRequest('mobile money', numberOfTokenRequests);
@@ -20391,10 +20415,10 @@ var AnalyticsFunctions = {
20391
20415
  });
20392
20416
  return this.saveLog();
20393
20417
  },
20394
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref3) {
20395
- var currency = _ref3.currency,
20396
- _ref3$isUserAction = _ref3.isUserAction,
20397
- isUserAction = _ref3$isUserAction === void 0 ? true : _ref3$isUserAction;
20418
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20419
+ var currency = _ref2.currency,
20420
+ _ref2$isUserAction = _ref2.isUserAction,
20421
+ isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20398
20422
  var prefix = isUserAction ? 'User switched' : 'Switched';
20399
20423
  this.log.history.push({
20400
20424
  type: 'action',
@@ -20472,7 +20496,7 @@ var TransactionInstance = /*#__PURE__*/function () {
20472
20496
  loadPusher(); // Analytics
20473
20497
 
20474
20498
  this.log = null;
20475
- Object.assign(this, AnalyticsFunctions);
20499
+ Object.assign(this, AnalyticsFunctions$1);
20476
20500
  this.initializeLog(data.log);
20477
20501
  this.saveIpAddress(); // Bind charge functions for the available channels
20478
20502
 
@@ -20979,9 +21003,9 @@ var CardPreauthorization = {
20979
21003
  publicKey = _ref.publicKey,
20980
21004
  _ref$customFields = _ref.customFields,
20981
21005
  customFields = _ref$customFields === void 0 ? {} : _ref$customFields;
20982
- // TODO: Log payment method
20983
- // https://paystack.atlassian.net/browse/RAILS-3070
20984
21006
  return validate(this.card).then(function () {
21007
+ _this2.logAttempt(paymentMethod);
21008
+
20985
21009
  var chargeParams = {
20986
21010
  clientdata: _this2.card.tokenize(),
20987
21011
  last4: _this2.card.getLast4(),
@@ -20990,8 +21014,8 @@ var CardPreauthorization = {
20990
21014
  customFields: customFields
20991
21015
  };
20992
21016
  return CardAPI.reserveFunds(chargeParams).then(function (response) {
20993
- // TODO: Log API Response
20994
- // https://paystack.atlassian.net/browse/RAILS-3070
21017
+ _this2.logAPIResponse(response, paymentMethod);
21018
+
20995
21019
  return response;
20996
21020
  });
20997
21021
  });
@@ -21040,6 +21064,200 @@ var PreauthorisationAPI = {
21040
21064
  }
21041
21065
  };
21042
21066
 
21067
+ var PreauthorizationAnalyticsAPI = {
21068
+ saveLog: function saveLog(preauthorizationId, merchantKey, log) {
21069
+ var url = new URL("preauthorization/update_log/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21070
+ return AnalyticsAPIUtils.saveLog(url, merchantKey, log);
21071
+ },
21072
+ getIp: function getIp() {
21073
+ return AnalyticsAPIUtils.getIp();
21074
+ },
21075
+ saveIp: function saveIp(preauthorizationId, merchantKey) {
21076
+ var url = new URL("preauthorization/set_ip/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21077
+ return AnalyticsAPIUtils.saveIp(url, merchantKey);
21078
+ },
21079
+ saveReferrer: function saveReferrer(preauthorizationId, merchantKey, referrer) {
21080
+ var url = new URL("preauthorization/set_referrer/".concat(preauthorizationId), configToUse.paystackApiUrl).toString();
21081
+ return AnalyticsAPIUtils.saveReferrer(url, merchantKey, referrer);
21082
+ }
21083
+ };
21084
+
21085
+ var AnalyticsFunctions = {
21086
+ initializeLog: function initializeLog(log) {
21087
+ this.log = AnalyticsUtils.initializeLog(log);
21088
+ },
21089
+ getTimeSpent: function getTimeSpent() {
21090
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
21091
+ return this.log.time_spent;
21092
+ },
21093
+ logPageOpen: function logPageOpen() {
21094
+ this.log.history.push({
21095
+ type: 'open',
21096
+ message: 'Opened checkout',
21097
+ time: this.getTimeSpent()
21098
+ });
21099
+ return this.saveLog();
21100
+ },
21101
+ logChannelSwitch: function logChannelSwitch(value) {
21102
+ this.log.history.push({
21103
+ type: 'action',
21104
+ message: "Set payment method to: ".concat(value),
21105
+ time: this.getTimeSpent()
21106
+ });
21107
+ return this.saveLog();
21108
+ },
21109
+ logValidationErrors: function logValidationErrors(inputs) {
21110
+ var _this = this;
21111
+
21112
+ inputs.forEach(function (input) {
21113
+ _this.log.history.push({
21114
+ type: 'error',
21115
+ message: "Invalid ".concat(input),
21116
+ time: _this.getTimeSpent()
21117
+ });
21118
+ });
21119
+ return this.saveLog();
21120
+ },
21121
+ logInput: function logInput(value) {
21122
+ var isUpdate = this.log.history.find(function (item) {
21123
+ return item.message === "Filled this field: ".concat(value);
21124
+ });
21125
+ this.log.history.push({
21126
+ type: 'input',
21127
+ message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
21128
+ time: this.getTimeSpent()
21129
+ });
21130
+ return this.saveLog();
21131
+ },
21132
+ logAuthWindowOpen: function logAuthWindowOpen() {
21133
+ this.log.history.push({
21134
+ type: 'action',
21135
+ message: 'Third-party authentication window opened',
21136
+ time: this.getTimeSpent()
21137
+ });
21138
+ return this.saveLog();
21139
+ },
21140
+ logAuthWindowClose: function logAuthWindowClose() {
21141
+ this.log.history.push({
21142
+ type: 'action',
21143
+ message: 'Third-party authentication window closed',
21144
+ time: this.getTimeSpent()
21145
+ });
21146
+ return this.saveLog();
21147
+ },
21148
+ logAPIResponse: function logAPIResponse(response, channel) {
21149
+ switch (response.status) {
21150
+ case 'success':
21151
+ return this.logSuccess(channel);
21152
+
21153
+ case 'pending':
21154
+ return this.logPending(channel);
21155
+
21156
+ case 'failed':
21157
+ return this.logError(response.message);
21158
+
21159
+ case 'auth':
21160
+ return this.logAuth(response.data.auth);
21161
+
21162
+ default:
21163
+ return false;
21164
+ }
21165
+ },
21166
+ logAPIResponseMessage: function logAPIResponseMessage(message) {
21167
+ this.log.history.push({
21168
+ type: 'action',
21169
+ message: message,
21170
+ time: this.getTimeSpent()
21171
+ });
21172
+ return this.saveLog();
21173
+ },
21174
+ logAttempt: function logAttempt(channel) {
21175
+ var message = 'Attempted to pay';
21176
+
21177
+ if (channel) {
21178
+ message += " with ".concat(channel);
21179
+ }
21180
+
21181
+ this.log.attempts += 1;
21182
+ this.log.history.push({
21183
+ type: 'action',
21184
+ message: message,
21185
+ time: this.getTimeSpent()
21186
+ });
21187
+ return this.saveLog();
21188
+ },
21189
+ logAuth: function logAuth(value) {
21190
+ this.log.authentication = value;
21191
+ this.log.history.push({
21192
+ type: 'auth',
21193
+ message: "Authentication Required: ".concat(value),
21194
+ time: this.getTimeSpent()
21195
+ });
21196
+ return this.saveLog();
21197
+ },
21198
+ logSuccess: function logSuccess(channel) {
21199
+ var message = 'Successfully paid';
21200
+
21201
+ if (channel) {
21202
+ message += " with ".concat(channel);
21203
+ }
21204
+
21205
+ this.log.success = true;
21206
+ this.log.history.push({
21207
+ type: 'success',
21208
+ message: message,
21209
+ time: this.getTimeSpent()
21210
+ });
21211
+ return this.saveLog();
21212
+ },
21213
+ logPending: function logPending(channel) {
21214
+ var message = 'Payment in progress';
21215
+
21216
+ if (channel) {
21217
+ message += " with ".concat(channel);
21218
+ }
21219
+
21220
+ this.log.history.push({
21221
+ type: 'pending',
21222
+ message: message,
21223
+ time: this.getTimeSpent()
21224
+ });
21225
+ return this.saveLog();
21226
+ },
21227
+ logPageClose: function logPageClose() {
21228
+ this.log.history.push({
21229
+ type: 'close',
21230
+ message: 'Closed checkout',
21231
+ time: this.getTimeSpent()
21232
+ });
21233
+ return this.saveLog();
21234
+ },
21235
+ logError: function logError(error) {
21236
+ var message = 'Error';
21237
+
21238
+ if (error) {
21239
+ message += ": ".concat(error);
21240
+ }
21241
+
21242
+ this.log.errors += 1;
21243
+ this.log.history.push({
21244
+ type: 'error',
21245
+ message: message,
21246
+ time: this.getTimeSpent()
21247
+ });
21248
+ return this.saveLog();
21249
+ },
21250
+ saveLog: function saveLog() {
21251
+ return PreauthorizationAnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
21252
+ },
21253
+ saveIpAddress: function saveIpAddress() {
21254
+ return PreauthorizationAnalyticsAPI.saveIp(this.id, this.merchant.key);
21255
+ },
21256
+ saveReferrer: function saveReferrer(referrer) {
21257
+ return PreauthorizationAnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
21258
+ }
21259
+ };
21260
+
21043
21261
  var PreauthorizationInstance = /*#__PURE__*/function () {
21044
21262
  function PreauthorizationInstance(data) {
21045
21263
  _classCallCheck(this, PreauthorizationInstance);
@@ -21062,9 +21280,11 @@ var PreauthorizationInstance = /*#__PURE__*/function () {
21062
21280
  key: data.merchant_key
21063
21281
  };
21064
21282
  this.card = {};
21065
- loadPusher(); // TODO: Analytics
21066
- // https://paystack.atlassian.net/browse/RAILS-3070
21067
-
21283
+ loadPusher();
21284
+ this.log = null;
21285
+ Object.assign(this, AnalyticsFunctions);
21286
+ this.initializeLog(data.log);
21287
+ this.saveIpAddress();
21068
21288
  Object.assign(this, CardPreauthorization);
21069
21289
  }
21070
21290
 
@@ -21116,20 +21336,6 @@ var Preauthorization = {
21116
21336
  }
21117
21337
  }, _callee);
21118
21338
  }))();
21119
- },
21120
- verify: function verify() {// TODO: https://paystack.atlassian.net/browse/RAILS-2890
21121
-
21122
- return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
21123
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
21124
- while (1) {
21125
- switch (_context2.prev = _context2.next) {
21126
- case 0:
21127
- case "end":
21128
- return _context2.stop();
21129
- }
21130
- }
21131
- }, _callee2);
21132
- }))();
21133
21339
  }
21134
21340
  };
21135
21341
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paystack/checkout-js",
3
- "version": "1.22.0-dev.5",
3
+ "version": "1.22.0-dev.7",
4
4
  "description": "Client-side JS library for billing on Paystack",
5
5
  "main": "lib/checkout.js",
6
6
  "module": "es/checkout.js",