@paystack/checkout-js 1.26.0-dev.13 → 1.26.0-dev.15

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
@@ -19820,154 +19820,211 @@ var Paystack = (function (exports) {
19820
19820
  }
19821
19821
  };
19822
19822
 
19823
- var isMobile_1 = isMobile;
19823
+ function validate$1(phoneNumber) {
19824
+ return new Promise(function (resolve, reject) {
19825
+ var validation = PhoneNumber.validate(phoneNumber);
19824
19826
 
19825
- function isMobile (ua) {
19826
- if (!ua && typeof navigator != 'undefined') ua = navigator.userAgent;
19827
- if (ua && ua.headers && typeof ua.headers['user-agent'] == 'string') {
19828
- ua = ua.headers['user-agent'];
19829
- }
19830
- if (typeof ua != 'string') return false;
19827
+ if (!validation.isValid) {
19828
+ var errorMessage = phoneNumber ? validation.errors[0] : 'Please start a mobile money transaction with Transaction.chargeMobileMoney()';
19829
+ reject(Error(errorMessage));
19830
+ }
19831
19831
 
19832
- 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));
19832
+ resolve(validation);
19833
+ });
19833
19834
  }
19834
19835
 
19835
- var AnalyticsUtils = {
19836
- initializeLog: function initializeLog(log) {
19837
- var _ref = log || {},
19838
- attempts = _ref.attempts,
19839
- authentication = _ref.authentication,
19840
- errors = _ref.errors,
19841
- history = _ref.history;
19836
+ var MobileMoneyCharge = {
19837
+ mobileMoneyChargeAPI: function mobileMoneyChargeAPI(params) {
19838
+ var _this = this;
19842
19839
 
19843
- return {
19844
- start_time: Math.round(Date.now() / 1000),
19845
- time_spent: 0,
19846
- attempts: attempts || 0,
19847
- authentication: authentication,
19848
- errors: errors || 0,
19849
- success: false,
19850
- mobile: isMobile_1(),
19851
- input: [],
19852
- history: history || []
19840
+ return MobileMoneyAPI.charge(params).then(function (response) {
19841
+ if (response.status === 'success') {
19842
+ _this.mobileMoney = response;
19843
+
19844
+ if (response.data && response.data.display && response.data.display.otpSentCount === 1) {
19845
+ _this.logTokenRequest('mobile money');
19846
+ }
19847
+ }
19848
+
19849
+ return response;
19850
+ });
19851
+ },
19852
+ chargeMobileMoney: function chargeMobileMoney(_ref) {
19853
+ var _this2 = this;
19854
+
19855
+ var phoneNumber = _ref.phoneNumber,
19856
+ provider = _ref.provider,
19857
+ voucher = _ref.voucher,
19858
+ registrationToken = _ref.registrationToken;
19859
+ return validate$1(phoneNumber).then(function () {
19860
+ _this2.logAttempt('mobile money');
19861
+
19862
+ var params = {
19863
+ provider: provider,
19864
+ voucher: voucher,
19865
+ registrationToken: registrationToken,
19866
+ transaction: _this2.id,
19867
+ phone: phoneNumber,
19868
+ device: _this2.deviceFingerprint,
19869
+ channel_name: "MOBILE_MONEY_".concat(_this2.id)
19870
+ };
19871
+ return _this2.mobileMoneyChargeAPI(params);
19872
+ });
19873
+ },
19874
+ chargeMpesaOffline: function chargeMpesaOffline(_ref2) {
19875
+ var provider = _ref2.provider,
19876
+ voucher = _ref2.voucher,
19877
+ registrationToken = _ref2.registrationToken;
19878
+ this.logAttempt('mobile money');
19879
+ var params = {
19880
+ provider: provider,
19881
+ voucher: voucher,
19882
+ registrationToken: registrationToken,
19883
+ transaction: this.id,
19884
+ device: this.deviceFingerprint,
19885
+ channel_name: "MOBILE_MONEY_".concat(this.id)
19853
19886
  };
19887
+ return this.mobileMoneyChargeAPI(params);
19854
19888
  },
19855
- getTimeSpent: function getTimeSpent(startTime) {
19856
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
19857
- return currentTimeInSeconds - startTime;
19858
- }
19859
- };
19889
+ authenticateMobileMoney: function authenticateMobileMoney(payload) {
19890
+ var _this3 = this;
19860
19891
 
19861
- var $ = _export;
19862
- var global$1 = global$R;
19863
- var getBuiltIn = getBuiltIn$a;
19864
- var apply = functionApply;
19865
- var uncurryThis = functionUncurryThis;
19866
- var fails = fails$t;
19892
+ var phoneNumber = payload.phoneNumber,
19893
+ provider = payload.provider,
19894
+ registrationToken = payload.registrationToken;
19895
+ return validate$1(phoneNumber).then(function () {
19896
+ _this3.logMobileMoneyActions(payload);
19867
19897
 
19868
- var Array$1 = global$1.Array;
19869
- var $stringify = getBuiltIn('JSON', 'stringify');
19870
- var exec = uncurryThis(/./.exec);
19871
- var charAt = uncurryThis(''.charAt);
19872
- var charCodeAt = uncurryThis(''.charCodeAt);
19873
- var replace = uncurryThis(''.replace);
19874
- var numberToString = uncurryThis(1.0.toString);
19898
+ var params = {
19899
+ provider: provider,
19900
+ registrationToken: registrationToken,
19901
+ transaction: _this3.id,
19902
+ phone: phoneNumber,
19903
+ device: _this3.deviceFingerprint,
19904
+ channel_name: "MOBILE_MONEY_".concat(_this3.id)
19905
+ };
19906
+ return MobileMoneyAPI.charge(params).then(function (response) {
19907
+ if (response.status === 'success') {
19908
+ _this3.mobileMoney = response;
19875
19909
 
19876
- var tester = /[\uD800-\uDFFF]/g;
19877
- var low = /^[\uD800-\uDBFF]$/;
19878
- var hi = /^[\uDC00-\uDFFF]$/;
19910
+ if (response.data && response.data.display && response.data.display.otpSentCount === 1) {
19911
+ _this3.logTokenRequest('mobile money');
19912
+ }
19913
+ } else if (response.errors && response.errors.data && response.errors.data.status === 'awaiting_registration_token') {
19914
+ _this3.logTokenAuthenticationFailure(response.message);
19915
+ } else {
19916
+ _this3.logError(response.message);
19917
+ }
19879
19918
 
19880
- var fix = function (match, offset, string) {
19881
- var prev = charAt(string, offset - 1);
19882
- var next = charAt(string, offset + 1);
19883
- if ((exec(low, match) && !exec(hi, next)) || (exec(hi, match) && !exec(low, prev))) {
19884
- return '\\u' + numberToString(charCodeAt(match, 0), 16);
19885
- } return match;
19886
- };
19919
+ return response;
19920
+ });
19921
+ });
19922
+ },
19923
+ submitMobileMoneyCode: function submitMobileMoneyCode(payload) {
19924
+ var _this4 = this;
19887
19925
 
19888
- var FORCED = fails(function () {
19889
- return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
19890
- || $stringify('\uDEAD') !== '"\\udead"';
19891
- });
19926
+ return MobileMoneyAPI.submitCode({
19927
+ code: payload.code,
19928
+ transaction: this.id
19929
+ }).then(function (response) {
19930
+ _this4.logAPIResponse(response, 'mobile_money');
19892
19931
 
19893
- if ($stringify) {
19894
- // `JSON.stringify` method
19895
- // https://tc39.es/ecma262/#sec-json.stringify
19896
- // https://github.com/tc39/proposal-well-formed-stringify
19897
- $({ target: 'JSON', stat: true, forced: FORCED }, {
19898
- // eslint-disable-next-line no-unused-vars -- required for `.length`
19899
- stringify: function stringify(it, replacer, space) {
19900
- for (var i = 0, l = arguments.length, args = Array$1(l); i < l; i++) args[i] = arguments[i];
19901
- var result = apply($stringify, null, args);
19902
- return typeof result == 'string' ? replace(result, tester, fix) : result;
19932
+ return response;
19933
+ });
19934
+ },
19935
+ listenForMobileMoneyCharge: function listenForMobileMoneyCharge(callback) {
19936
+ if (this.mobileMoney.status !== 'success') {
19937
+ return Promise.reject(Error('Please start a mobile money charge with Transaction.chargeMobileMoney()'));
19903
19938
  }
19904
- });
19905
- }
19906
19939
 
19907
- var AnalyticsAPIUtils = {
19908
- saveLog: function saveLog(url, _ref) {
19909
- var merchantKey = _ref.merchantKey,
19910
- log = _ref.log;
19940
+ var _this$mobileMoney$dat = this.mobileMoney.data,
19941
+ channel = _this$mobileMoney$dat.channel,
19942
+ channelName = _this$mobileMoney$dat.channel_name;
19943
+ var listenerOptions = {
19944
+ channel: channel || channelName,
19945
+ paymentMethod: 'mobile_money'
19946
+ };
19947
+ return this.listenForCharge(listenerOptions, callback);
19948
+ }
19949
+ };
19950
+
19951
+ var DirectDebitAPI = {
19952
+ loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
19953
+ var email = _ref.email,
19954
+ password = _ref.password;
19955
+ var params = {
19956
+ email: email,
19957
+ password: password
19958
+ };
19911
19959
  var language = getLanguage();
19912
19960
 
19913
- var headers = _objectSpread2({
19914
- Authorization: "Bearer ".concat(merchantKey)
19915
- }, language && {
19961
+ var headers = _objectSpread2({}, language && {
19916
19962
  'Accept-Language': language
19917
19963
  });
19918
19964
 
19919
- return axiosInstance.post(url, {
19920
- payload: JSON.stringify(log)
19921
- }, {
19965
+ return axiosInstance.post("".concat(configToUse.paystackApiUrl, "login"), params, {
19922
19966
  headers: headers
19923
19967
  }).then(function (response) {
19924
- return response.data;
19968
+ return ChargeResponses.parse(response.data);
19925
19969
  });
19926
19970
  },
19927
- getIp: function getIp() {
19928
- var url = 'https://api.paystack.co/decision/ip';
19971
+ charge: function charge(_ref2) {
19972
+ var accountCode = _ref2.account_code,
19973
+ transaction = _ref2.transaction,
19974
+ token = _ref2.token;
19929
19975
  var language = getLanguage();
19930
19976
 
19931
- var headers = _objectSpread2({}, language && {
19977
+ var headers = _objectSpread2({
19978
+ Authorization: "Bearer ".concat(token),
19979
+ 'jwt-auth': true
19980
+ }, language && {
19932
19981
  'Accept-Language': language
19933
19982
  });
19934
19983
 
19935
- return axiosInstance.get(url, {
19984
+ var params = {
19985
+ account_code: accountCode,
19986
+ transaction: transaction
19987
+ };
19988
+ return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/initiate"), params, {
19936
19989
  headers: headers
19937
19990
  }).then(function (response) {
19938
- return response.data.data.ip_address;
19991
+ return ChargeResponses.parse(response.data);
19939
19992
  });
19940
19993
  },
19941
- saveIp: function saveIp(url, _ref2) {
19942
- var merchantKey = _ref2.merchantKey;
19994
+ authenticate: function authenticate(_ref3) {
19995
+ var otp = _ref3.otp,
19996
+ transaction = _ref3.transaction,
19997
+ token = _ref3.token;
19943
19998
  var language = getLanguage();
19944
19999
 
19945
20000
  var headers = _objectSpread2({
19946
- Authorization: "Bearer ".concat(merchantKey)
20001
+ Authorization: "Bearer ".concat(token),
20002
+ 'jwt-auth': true
19947
20003
  }, language && {
19948
20004
  'Accept-Language': language
19949
20005
  });
19950
20006
 
19951
- return axiosInstance.post(url, null, {
20007
+ var params = {
20008
+ otp: otp,
20009
+ transaction: transaction
20010
+ };
20011
+ return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/validate"), params, {
19952
20012
  headers: headers
19953
20013
  }).then(function (response) {
19954
- return response.data;
20014
+ return ChargeResponses.parse(response.data);
19955
20015
  });
19956
20016
  },
19957
- saveReferrer: function saveReferrer(url, _ref3) {
19958
- var merchantKey = _ref3.merchantKey,
19959
- referrer = _ref3.referrer;
20017
+ getProvisionedAccounts: function getProvisionedAccounts(token) {
19960
20018
  var language = getLanguage();
19961
20019
 
19962
20020
  var headers = _objectSpread2({
19963
- Authorization: "Bearer ".concat(merchantKey)
20021
+ Authorization: "Bearer ".concat(token),
20022
+ 'jwt-auth': true
19964
20023
  }, language && {
19965
20024
  'Accept-Language': language
19966
20025
  });
19967
20026
 
19968
- return axiosInstance.post(url, {
19969
- referrer: referrer
19970
- }, {
20027
+ return axiosInstance.get("".concat(configToUse.paystackApiUrl, "directdebit/account"), {
19971
20028
  headers: headers
19972
20029
  }).then(function (response) {
19973
20030
  return response.data;
@@ -19975,632 +20032,549 @@ var Paystack = (function (exports) {
19975
20032
  }
19976
20033
  };
19977
20034
 
19978
- var AnalyticsAPI = {
19979
- saveLog: function saveLog(transactionId, merchantKey, log) {
19980
- var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
19981
- return AnalyticsAPIUtils.saveLog(url, {
19982
- merchantKey: merchantKey,
19983
- log: log
19984
- });
19985
- },
19986
- getIp: function getIp() {
19987
- return AnalyticsAPIUtils.getIp();
19988
- },
19989
- saveIp: function saveIp(transactionId, merchantKey) {
19990
- var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
19991
- return AnalyticsAPIUtils.saveIp(url, {
19992
- merchantKey: merchantKey
19993
- });
19994
- },
19995
- saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
19996
- var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
19997
- return AnalyticsAPIUtils.saveReferrer(url, {
19998
- merchantKey: merchantKey,
19999
- referrer: referrer
20000
- });
20001
- }
20002
- };
20035
+ var paymentMethod$1 = 'direct debit';
20036
+ var DirectDebitCharge = {
20037
+ loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
20038
+ var _this = this;
20003
20039
 
20004
- var AnalyticsFunctions$1 = {
20005
- initializeLog: function initializeLog(log) {
20006
- this.log = AnalyticsUtils.initializeLog(log);
20007
- },
20008
- getTimeSpent: function getTimeSpent() {
20009
- this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20010
- return this.log.time_spent;
20011
- },
20012
- logPageOpen: function logPageOpen() {
20013
- this.log.history.push({
20014
- type: 'open',
20015
- message: 'Opened checkout',
20016
- time: this.getTimeSpent()
20017
- });
20018
- return this.saveLog();
20019
- },
20020
- logChannelSwitch: function logChannelSwitch(value) {
20021
- this.log.history.push({
20022
- type: 'action',
20023
- message: "Set payment method to: ".concat(value),
20024
- time: this.getTimeSpent()
20025
- });
20026
- return this.saveLog();
20027
- },
20028
- logValidationErrors: function logValidationErrors(inputs) {
20029
- var _this = this;
20040
+ var email = _ref.email,
20041
+ password = _ref.password;
20042
+ var params = {
20043
+ email: email,
20044
+ password: password
20045
+ };
20030
20046
 
20031
- inputs.forEach(function (input) {
20032
- _this.log.history.push({
20033
- type: 'error',
20034
- message: "Invalid ".concat(input),
20035
- time: _this.getTimeSpent()
20036
- });
20037
- });
20038
- return this.saveLog();
20039
- },
20040
- logInput: function logInput(value) {
20041
- var isUpdate = this.log.history.find(function (item) {
20042
- return item.message === "Filled this field: ".concat(value);
20043
- });
20044
- this.log.history.push({
20045
- type: 'input',
20046
- message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
20047
- time: this.getTimeSpent()
20048
- });
20049
- return this.saveLog();
20050
- },
20051
- logBankSelect: function logBankSelect(value) {
20052
- this.log.history.push({
20053
- type: 'action',
20054
- message: "Selected bank: ".concat(value),
20055
- time: this.getTimeSpent()
20056
- });
20057
- return this.saveLog();
20058
- },
20059
- logSavedCardSelect: function logSavedCardSelect() {
20060
- this.log.history.push({
20061
- type: 'action',
20062
- message: 'Selected saved card',
20063
- time: this.getTimeSpent()
20064
- });
20065
- return this.saveLog();
20066
- },
20067
- logAuthWindowOpen: function logAuthWindowOpen() {
20068
- this.log.history.push({
20069
- type: 'action',
20070
- message: 'Third-party authentication window opened',
20071
- time: this.getTimeSpent()
20072
- });
20073
- return this.saveLog();
20074
- },
20075
- logAuthWindowClose: function logAuthWindowClose() {
20076
- this.log.history.push({
20077
- type: 'action',
20078
- message: 'Third-party authentication window closed',
20079
- time: this.getTimeSpent()
20080
- });
20081
- return this.saveLog();
20082
- },
20083
- logAPIResponse: function logAPIResponse(response, channel) {
20084
- switch (response.status) {
20085
- case 'success':
20086
- return this.logSuccess(channel);
20047
+ if (!isValidEmail(email)) {
20048
+ return Promise.reject(Error('Invalid email'));
20049
+ }
20087
20050
 
20088
- case 'pending':
20089
- return this.logPending(channel);
20051
+ return DirectDebitAPI.loginToDirectDebitAccount(params).then(function (response) {
20052
+ if (response.status === 'success') {
20053
+ var _response$data = response.data,
20054
+ token = _response$data.token,
20055
+ permissions = _response$data.user.permissions;
20090
20056
 
20091
- case 'failed':
20092
- return this.logError(response.message);
20057
+ if (!permissions || permissions.length < 1) {
20058
+ throw Error('You do not have the privileges to perform this action');
20059
+ }
20093
20060
 
20094
- case 'auth':
20095
- return this.logAuth(response.data.auth);
20061
+ if (permissions.find(function (permission) {
20062
+ return permission === 'directdebit-*';
20063
+ })) {
20064
+ _this.directDebit.token = token;
20065
+ return response;
20066
+ }
20096
20067
 
20097
- default:
20098
- return false;
20099
- }
20100
- },
20101
- logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20102
- var numberOfTokenRequests = _ref.numberOfTokenRequests,
20103
- registrationToken = _ref.registrationToken;
20068
+ throw Error('You do not have the privileges to perform this action');
20069
+ }
20104
20070
 
20105
- if (numberOfTokenRequests) {
20106
- this.logTokenRequest('mobile money', numberOfTokenRequests);
20107
- } else if (registrationToken) {
20108
- this.logTokenSubmitted('mobile money');
20109
- } else {
20110
- this.logAttempt('mobile money');
20111
- }
20112
- },
20113
- logAPIResponseMessage: function logAPIResponseMessage(message) {
20114
- this.log.history.push({
20115
- type: 'action',
20116
- message: message,
20117
- time: this.getTimeSpent()
20071
+ return response;
20118
20072
  });
20119
- return this.saveLog();
20120
20073
  },
20121
- logAttempt: function logAttempt(channel) {
20122
- var message = 'Attempted to pay';
20074
+ chargeDirectDebit: function chargeDirectDebit(accountCode) {
20075
+ var _this2 = this;
20123
20076
 
20124
- if (channel) {
20125
- message += " with ".concat(channel);
20077
+ if (!this.directDebit.token) {
20078
+ return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
20126
20079
  }
20127
20080
 
20128
- this.log.attempts += 1;
20129
- this.log.history.push({
20130
- type: 'action',
20131
- message: message,
20132
- time: this.getTimeSpent()
20133
- });
20134
- return this.saveLog();
20135
- },
20136
- logTokenRequest: function logTokenRequest(channel) {
20137
- var numberOfTokenRequests = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
20138
- var message = numberOfTokenRequests === 0 ? 'Waiting for customer to submit OTP' : 'Customer requested to resend OTP';
20139
- this.log.history.push({
20140
- type: 'action',
20141
- message: message,
20142
- channel: channel,
20143
- time: this.getTimeSpent()
20144
- });
20145
- return this.saveLog();
20146
- },
20147
- logTokenSubmitted: function logTokenSubmitted(channel) {
20148
- var message = 'Customer submitted OTP';
20149
- this.log.history.push({
20150
- type: 'action',
20151
- message: message,
20152
- channel: channel,
20153
- time: this.getTimeSpent()
20154
- });
20155
- return this.saveLog();
20156
- },
20157
- logTokenAuthenticationFailure: function logTokenAuthenticationFailure(error) {
20158
- var message = error ? "Error: ".concat(error) : 'Error';
20159
- this.log.errors += 1;
20160
- this.log.history.push({
20161
- type: 'error',
20162
- message: message,
20163
- authentication: 'failed',
20164
- time: this.getTimeSpent()
20165
- });
20166
- return this.saveLog();
20167
- },
20168
- logError: function logError(error) {
20169
- var message = 'Error';
20081
+ this.logAttempt(paymentMethod$1);
20082
+ var params = {
20083
+ account_code: accountCode,
20084
+ transaction: this.id,
20085
+ token: this.directDebit.token
20086
+ };
20087
+ return DirectDebitAPI.charge(params).then(function (response) {
20088
+ _this2.logAPIResponse(response, paymentMethod$1);
20170
20089
 
20171
- if (error) {
20172
- message += ": ".concat(error);
20173
- }
20090
+ if (response.status) {
20091
+ _this2.directDebit.chargeResponse = response;
20092
+ }
20174
20093
 
20175
- this.log.errors += 1;
20176
- this.log.history.push({
20177
- type: 'error',
20178
- message: message,
20179
- time: this.getTimeSpent()
20180
- });
20181
- return this.saveLog();
20182
- },
20183
- logAuth: function logAuth(value) {
20184
- this.log.authentication = value;
20185
- this.log.history.push({
20186
- type: 'auth',
20187
- message: "Authentication Required: ".concat(value),
20188
- time: this.getTimeSpent()
20094
+ return response;
20189
20095
  });
20190
- return this.saveLog();
20191
20096
  },
20192
- logSuccess: function logSuccess(channel) {
20193
- var message = 'Successfully paid';
20097
+ getProvisionedAccounts: function getProvisionedAccounts() {
20098
+ var _this3 = this;
20194
20099
 
20195
- if (channel) {
20196
- message += " with ".concat(channel);
20197
- }
20100
+ return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
20101
+ _this3.logAPIResponse(response, paymentMethod$1);
20198
20102
 
20199
- this.log.success = true;
20200
- this.log.history.push({
20201
- type: 'success',
20202
- message: message,
20203
- time: this.getTimeSpent()
20204
- });
20205
- return this.saveLog();
20206
- },
20207
- logPending: function logPending(channel) {
20208
- var message = 'Payment in progress';
20103
+ var status = response.status,
20104
+ data = response.data;
20209
20105
 
20210
- if (channel) {
20211
- message += " with ".concat(channel);
20212
- }
20106
+ if (status) {
20107
+ if (data && data.length < 1) {
20108
+ return Promise.reject(Error('You have not provisioned any bank account for Direct Debit yet'));
20109
+ }
20213
20110
 
20214
- this.log.history.push({
20215
- type: 'pending',
20216
- message: message,
20217
- time: this.getTimeSpent()
20218
- });
20219
- return this.saveLog();
20220
- },
20221
- logPageClose: function logPageClose() {
20222
- this.log.history.push({
20223
- type: 'close',
20224
- message: 'Closed checkout',
20225
- time: this.getTimeSpent()
20111
+ _this3.directDebit.accounts = response.data;
20112
+ }
20113
+
20114
+ return response;
20226
20115
  });
20227
- return this.saveLog();
20228
20116
  },
20229
- logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20230
- var currency = _ref2.currency,
20231
- _ref2$isUserAction = _ref2.isUserAction,
20232
- isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20233
- var prefix = isUserAction ? 'User switched' : 'Switched';
20234
- this.log.history.push({
20235
- type: 'action',
20236
- message: "".concat(prefix, " transaction currency to ").concat(currency),
20237
- time: this.getTimeSpent()
20117
+ authenticateAccount: function authenticateAccount(otp) {
20118
+ var _this4 = this;
20119
+
20120
+ var params = {
20121
+ otp: otp,
20122
+ transaction: this.id,
20123
+ token: this.directDebit.token
20124
+ };
20125
+ return DirectDebitAPI.authenticate(params).then(function (response) {
20126
+ _this4.logAPIResponse(response, paymentMethod$1);
20127
+
20128
+ return response;
20238
20129
  });
20239
- return this.saveLog();
20240
- },
20241
- saveLog: function saveLog() {
20242
- return AnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
20243
- },
20244
- saveIpAddress: function saveIpAddress() {
20245
- return AnalyticsAPI.saveIp(this.id, this.merchant.key);
20246
- },
20247
- saveReferrer: function saveReferrer(referrer) {
20248
- return AnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
20249
20130
  }
20250
20131
  };
20251
20132
 
20252
- function validate$1(phoneNumber) {
20253
- return new Promise(function (resolve, reject) {
20254
- var validation = PhoneNumber.validate(phoneNumber);
20255
-
20256
- if (!validation.isValid) {
20257
- var errorMessage = phoneNumber ? validation.errors[0] : 'Please start a mobile money transaction with Transaction.chargeMobileMoney()';
20258
- reject(Error(errorMessage));
20259
- }
20260
-
20261
- resolve(validation);
20262
- });
20263
- }
20264
-
20265
- var mobileMoney = {};
20266
-
20267
- function mobileMoneyChargeAPI(params) {
20268
- return MobileMoneyAPI.charge(params).then( /*#__PURE__*/function () {
20269
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(response) {
20270
- return regeneratorRuntime.wrap(function _callee$(_context) {
20271
- while (1) {
20272
- switch (_context.prev = _context.next) {
20273
- case 0:
20274
- if (!(response.status === 'success')) {
20275
- _context.next = 5;
20276
- break;
20277
- }
20278
-
20279
- mobileMoney = response;
20133
+ var ChargeFunctions = {
20134
+ get: function get(channel) {
20135
+ var chargeFunctions = {
20136
+ card: CardCharge,
20137
+ bank: BankAccountCharge,
20138
+ ussd: USSDCharge,
20139
+ qr: QRCharge,
20140
+ mobile_money: MobileMoneyCharge,
20141
+ direct_debit: DirectDebitCharge,
20142
+ bank_transfer: PayWithTransferCharge,
20143
+ eft: EFT,
20144
+ payattitude: PayattitudeCharge,
20145
+ apple_pay: ApplePayCharge,
20146
+ paypal: PayPalCharge
20147
+ };
20148
+ return chargeFunctions[channel];
20149
+ }
20150
+ };
20280
20151
 
20281
- if (!(response.data && response.data.display && response.data.display.otpSentCount === 1)) {
20282
- _context.next = 5;
20283
- break;
20284
- }
20152
+ var isMobile_1 = isMobile;
20285
20153
 
20286
- _context.next = 5;
20287
- return AnalyticsFunctions$1.logTokenRequest('mobile money');
20154
+ function isMobile (ua) {
20155
+ if (!ua && typeof navigator != 'undefined') ua = navigator.userAgent;
20156
+ if (ua && ua.headers && typeof ua.headers['user-agent'] == 'string') {
20157
+ ua = ua.headers['user-agent'];
20158
+ }
20159
+ if (typeof ua != 'string') return false;
20288
20160
 
20289
- case 5:
20290
- return _context.abrupt("return", response);
20161
+ 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));
20162
+ }
20291
20163
 
20292
- case 6:
20293
- case "end":
20294
- return _context.stop();
20295
- }
20296
- }
20297
- }, _callee);
20298
- }));
20164
+ var AnalyticsUtils = {
20165
+ initializeLog: function initializeLog(log) {
20166
+ var _ref = log || {},
20167
+ attempts = _ref.attempts,
20168
+ authentication = _ref.authentication,
20169
+ errors = _ref.errors,
20170
+ history = _ref.history;
20299
20171
 
20300
- return function (_x) {
20301
- return _ref.apply(this, arguments);
20172
+ return {
20173
+ start_time: Math.round(Date.now() / 1000),
20174
+ time_spent: 0,
20175
+ attempts: attempts || 0,
20176
+ authentication: authentication,
20177
+ errors: errors || 0,
20178
+ success: false,
20179
+ mobile: isMobile_1(),
20180
+ input: [],
20181
+ history: history || []
20302
20182
  };
20303
- }());
20304
- }
20183
+ },
20184
+ getTimeSpent: function getTimeSpent(startTime) {
20185
+ var currentTimeInSeconds = Math.round(Date.now() / 1000);
20186
+ return currentTimeInSeconds - startTime;
20187
+ }
20188
+ };
20305
20189
 
20306
- var MobileMoneyCharge = {
20307
- chargeMobileMoney: function chargeMobileMoney(_ref2) {
20308
- var _this = this;
20190
+ var $ = _export;
20191
+ var global$1 = global$R;
20192
+ var getBuiltIn = getBuiltIn$a;
20193
+ var apply = functionApply;
20194
+ var uncurryThis = functionUncurryThis;
20195
+ var fails = fails$t;
20309
20196
 
20310
- var phoneNumber = _ref2.phoneNumber,
20311
- provider = _ref2.provider,
20312
- voucher = _ref2.voucher,
20313
- registrationToken = _ref2.registrationToken;
20314
- return validate$1(phoneNumber).then(function () {
20315
- _this.logAttempt('mobile money');
20197
+ var Array$1 = global$1.Array;
20198
+ var $stringify = getBuiltIn('JSON', 'stringify');
20199
+ var exec = uncurryThis(/./.exec);
20200
+ var charAt = uncurryThis(''.charAt);
20201
+ var charCodeAt = uncurryThis(''.charCodeAt);
20202
+ var replace = uncurryThis(''.replace);
20203
+ var numberToString = uncurryThis(1.0.toString);
20204
+
20205
+ var tester = /[\uD800-\uDFFF]/g;
20206
+ var low = /^[\uD800-\uDBFF]$/;
20207
+ var hi = /^[\uDC00-\uDFFF]$/;
20316
20208
 
20317
- var params = {
20318
- provider: provider,
20319
- voucher: voucher,
20320
- registrationToken: registrationToken,
20321
- transaction: _this.id,
20322
- phone: phoneNumber,
20323
- device: _this.deviceFingerprint,
20324
- channel_name: "MOBILE_MONEY_".concat(_this.id)
20325
- };
20326
- return mobileMoneyChargeAPI(params);
20327
- });
20328
- },
20329
- chargeMpesaOffline: function chargeMpesaOffline(_ref3) {
20330
- var provider = _ref3.provider,
20331
- voucher = _ref3.voucher,
20332
- registrationToken = _ref3.registrationToken;
20333
- this.logAttempt('mobile money');
20334
- var params = {
20335
- provider: provider,
20336
- voucher: voucher,
20337
- registrationToken: registrationToken,
20338
- transaction: this.id,
20339
- device: this.deviceFingerprint,
20340
- channel_name: "MOBILE_MONEY_".concat(this.id)
20341
- };
20342
- return mobileMoneyChargeAPI(params);
20343
- },
20344
- authenticateMobileMoney: function authenticateMobileMoney(payload) {
20345
- var _this2 = this;
20209
+ var fix = function (match, offset, string) {
20210
+ var prev = charAt(string, offset - 1);
20211
+ var next = charAt(string, offset + 1);
20212
+ if ((exec(low, match) && !exec(hi, next)) || (exec(hi, match) && !exec(low, prev))) {
20213
+ return '\\u' + numberToString(charCodeAt(match, 0), 16);
20214
+ } return match;
20215
+ };
20346
20216
 
20347
- var phoneNumber = payload.phoneNumber,
20348
- provider = payload.provider,
20349
- registrationToken = payload.registrationToken;
20350
- return validate$1(phoneNumber).then(function () {
20351
- _this2.logMobileMoneyActions(payload);
20217
+ var FORCED = fails(function () {
20218
+ return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
20219
+ || $stringify('\uDEAD') !== '"\\udead"';
20220
+ });
20352
20221
 
20353
- var params = {
20354
- provider: provider,
20355
- registrationToken: registrationToken,
20356
- transaction: _this2.id,
20357
- phone: phoneNumber,
20358
- device: _this2.deviceFingerprint,
20359
- channel_name: "MOBILE_MONEY_".concat(_this2.id)
20360
- };
20361
- return MobileMoneyAPI.charge(params).then(function (response) {
20362
- if (response.status === 'success') {
20363
- mobileMoney = response;
20222
+ if ($stringify) {
20223
+ // `JSON.stringify` method
20224
+ // https://tc39.es/ecma262/#sec-json.stringify
20225
+ // https://github.com/tc39/proposal-well-formed-stringify
20226
+ $({ target: 'JSON', stat: true, forced: FORCED }, {
20227
+ // eslint-disable-next-line no-unused-vars -- required for `.length`
20228
+ stringify: function stringify(it, replacer, space) {
20229
+ for (var i = 0, l = arguments.length, args = Array$1(l); i < l; i++) args[i] = arguments[i];
20230
+ var result = apply($stringify, null, args);
20231
+ return typeof result == 'string' ? replace(result, tester, fix) : result;
20232
+ }
20233
+ });
20234
+ }
20364
20235
 
20365
- if (response.data && response.data.display && response.data.display.otpSentCount === 1) {
20366
- _this2.logTokenRequest('mobile money');
20367
- }
20368
- } else if (response.errors && response.errors.data && response.errors.data.status === 'awaiting_registration_token') {
20369
- _this2.logTokenAuthenticationFailure(response.message);
20370
- } else {
20371
- _this2.logError(response.message);
20372
- }
20236
+ var AnalyticsAPIUtils = {
20237
+ saveLog: function saveLog(url, _ref) {
20238
+ var merchantKey = _ref.merchantKey,
20239
+ log = _ref.log;
20240
+ var language = getLanguage();
20373
20241
 
20374
- return response;
20375
- });
20242
+ var headers = _objectSpread2({
20243
+ Authorization: "Bearer ".concat(merchantKey)
20244
+ }, language && {
20245
+ 'Accept-Language': language
20376
20246
  });
20377
- },
20378
- submitMobileMoneyCode: function submitMobileMoneyCode(payload) {
20379
- var _this3 = this;
20380
20247
 
20381
- return MobileMoneyAPI.submitCode({
20382
- code: payload.code,
20383
- transaction: this.id
20248
+ return axiosInstance.post(url, {
20249
+ payload: JSON.stringify(log)
20250
+ }, {
20251
+ headers: headers
20384
20252
  }).then(function (response) {
20385
- _this3.logAPIResponse(response, 'mobile_money');
20386
-
20387
- return response;
20253
+ return response.data;
20388
20254
  });
20389
20255
  },
20390
- listenForMobileMoneyCharge: function listenForMobileMoneyCharge(callback) {
20391
- if (mobileMoney.status !== 'success') {
20392
- return Promise.reject(Error('Please start a mobile money charge with Transaction.chargeMobileMoney()'));
20393
- }
20394
-
20395
- var _mobileMoney$data = mobileMoney.data,
20396
- channel = _mobileMoney$data.channel,
20397
- channelName = _mobileMoney$data.channel_name;
20398
- var listenerOptions = {
20399
- channel: channel || channelName,
20400
- paymentMethod: 'mobile_money'
20401
- };
20402
- return this.listenForCharge(listenerOptions, callback);
20403
- }
20404
- };
20405
-
20406
- var DirectDebitAPI = {
20407
- loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
20408
- var email = _ref.email,
20409
- password = _ref.password;
20410
- var params = {
20411
- email: email,
20412
- password: password
20413
- };
20256
+ getIp: function getIp() {
20257
+ var url = 'https://api.paystack.co/decision/ip';
20414
20258
  var language = getLanguage();
20415
20259
 
20416
20260
  var headers = _objectSpread2({}, language && {
20417
20261
  'Accept-Language': language
20418
20262
  });
20419
20263
 
20420
- return axiosInstance.post("".concat(configToUse.paystackApiUrl, "login"), params, {
20264
+ return axiosInstance.get(url, {
20421
20265
  headers: headers
20422
20266
  }).then(function (response) {
20423
- return ChargeResponses.parse(response.data);
20267
+ return response.data.data.ip_address;
20424
20268
  });
20425
20269
  },
20426
- charge: function charge(_ref2) {
20427
- var accountCode = _ref2.account_code,
20428
- transaction = _ref2.transaction,
20429
- token = _ref2.token;
20270
+ saveIp: function saveIp(url, _ref2) {
20271
+ var merchantKey = _ref2.merchantKey;
20430
20272
  var language = getLanguage();
20431
20273
 
20432
20274
  var headers = _objectSpread2({
20433
- Authorization: "Bearer ".concat(token),
20434
- 'jwt-auth': true
20275
+ Authorization: "Bearer ".concat(merchantKey)
20435
20276
  }, language && {
20436
20277
  'Accept-Language': language
20437
20278
  });
20438
20279
 
20439
- var params = {
20440
- account_code: accountCode,
20441
- transaction: transaction
20442
- };
20443
- return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/initiate"), params, {
20280
+ return axiosInstance.post(url, null, {
20444
20281
  headers: headers
20445
20282
  }).then(function (response) {
20446
- return ChargeResponses.parse(response.data);
20283
+ return response.data;
20447
20284
  });
20448
20285
  },
20449
- authenticate: function authenticate(_ref3) {
20450
- var otp = _ref3.otp,
20451
- transaction = _ref3.transaction,
20452
- token = _ref3.token;
20286
+ saveReferrer: function saveReferrer(url, _ref3) {
20287
+ var merchantKey = _ref3.merchantKey,
20288
+ referrer = _ref3.referrer;
20453
20289
  var language = getLanguage();
20454
20290
 
20455
20291
  var headers = _objectSpread2({
20456
- Authorization: "Bearer ".concat(token),
20457
- 'jwt-auth': true
20292
+ Authorization: "Bearer ".concat(merchantKey)
20458
20293
  }, language && {
20459
20294
  'Accept-Language': language
20460
20295
  });
20461
20296
 
20462
- var params = {
20463
- otp: otp,
20464
- transaction: transaction
20465
- };
20466
- return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/validate"), params, {
20297
+ return axiosInstance.post(url, {
20298
+ referrer: referrer
20299
+ }, {
20467
20300
  headers: headers
20468
20301
  }).then(function (response) {
20469
- return ChargeResponses.parse(response.data);
20302
+ return response.data;
20303
+ });
20304
+ }
20305
+ };
20306
+
20307
+ var AnalyticsAPI = {
20308
+ saveLog: function saveLog(transactionId, merchantKey, log) {
20309
+ var url = new URL("transaction/update_log/".concat(transactionId), configToUse.paystackApiUrl).toString();
20310
+ return AnalyticsAPIUtils.saveLog(url, {
20311
+ merchantKey: merchantKey,
20312
+ log: log
20313
+ });
20314
+ },
20315
+ getIp: function getIp() {
20316
+ return AnalyticsAPIUtils.getIp();
20317
+ },
20318
+ saveIp: function saveIp(transactionId, merchantKey) {
20319
+ var url = new URL("transaction/set_ip/".concat(transactionId), configToUse.paystackApiUrl).toString();
20320
+ return AnalyticsAPIUtils.saveIp(url, {
20321
+ merchantKey: merchantKey
20322
+ });
20323
+ },
20324
+ saveReferrer: function saveReferrer(transactionId, merchantKey, referrer) {
20325
+ var url = new URL("transaction/set_referrer/".concat(transactionId), configToUse.paystackApiUrl).toString();
20326
+ return AnalyticsAPIUtils.saveReferrer(url, {
20327
+ merchantKey: merchantKey,
20328
+ referrer: referrer
20329
+ });
20330
+ }
20331
+ };
20332
+
20333
+ var AnalyticsFunctions$1 = {
20334
+ initializeLog: function initializeLog(log) {
20335
+ this.log = AnalyticsUtils.initializeLog(log);
20336
+ },
20337
+ getTimeSpent: function getTimeSpent() {
20338
+ this.log.time_spent = AnalyticsUtils.getTimeSpent(this.log.start_time);
20339
+ return this.log.time_spent;
20340
+ },
20341
+ logPageOpen: function logPageOpen() {
20342
+ this.log.history.push({
20343
+ type: 'open',
20344
+ message: 'Opened checkout',
20345
+ time: this.getTimeSpent()
20346
+ });
20347
+ return this.saveLog();
20348
+ },
20349
+ logChannelSwitch: function logChannelSwitch(value) {
20350
+ this.log.history.push({
20351
+ type: 'action',
20352
+ message: "Set payment method to: ".concat(value),
20353
+ time: this.getTimeSpent()
20354
+ });
20355
+ return this.saveLog();
20356
+ },
20357
+ logValidationErrors: function logValidationErrors(inputs) {
20358
+ var _this = this;
20359
+
20360
+ inputs.forEach(function (input) {
20361
+ _this.log.history.push({
20362
+ type: 'error',
20363
+ message: "Invalid ".concat(input),
20364
+ time: _this.getTimeSpent()
20365
+ });
20366
+ });
20367
+ return this.saveLog();
20368
+ },
20369
+ logInput: function logInput(value) {
20370
+ var isUpdate = this.log.history.find(function (item) {
20371
+ return item.message === "Filled this field: ".concat(value);
20372
+ });
20373
+ this.log.history.push({
20374
+ type: 'input',
20375
+ message: "".concat(isUpdate ? 'Changed' : 'Filled', " this field: ").concat(value),
20376
+ time: this.getTimeSpent()
20377
+ });
20378
+ return this.saveLog();
20379
+ },
20380
+ logBankSelect: function logBankSelect(value) {
20381
+ this.log.history.push({
20382
+ type: 'action',
20383
+ message: "Selected bank: ".concat(value),
20384
+ time: this.getTimeSpent()
20385
+ });
20386
+ return this.saveLog();
20387
+ },
20388
+ logSavedCardSelect: function logSavedCardSelect() {
20389
+ this.log.history.push({
20390
+ type: 'action',
20391
+ message: 'Selected saved card',
20392
+ time: this.getTimeSpent()
20393
+ });
20394
+ return this.saveLog();
20395
+ },
20396
+ logAuthWindowOpen: function logAuthWindowOpen() {
20397
+ this.log.history.push({
20398
+ type: 'action',
20399
+ message: 'Third-party authentication window opened',
20400
+ time: this.getTimeSpent()
20401
+ });
20402
+ return this.saveLog();
20403
+ },
20404
+ logAuthWindowClose: function logAuthWindowClose() {
20405
+ this.log.history.push({
20406
+ type: 'action',
20407
+ message: 'Third-party authentication window closed',
20408
+ time: this.getTimeSpent()
20470
20409
  });
20410
+ return this.saveLog();
20471
20411
  },
20472
- getProvisionedAccounts: function getProvisionedAccounts(token) {
20473
- var language = getLanguage();
20474
-
20475
- var headers = _objectSpread2({
20476
- Authorization: "Bearer ".concat(token),
20477
- 'jwt-auth': true
20478
- }, language && {
20479
- 'Accept-Language': language
20480
- });
20412
+ logAPIResponse: function logAPIResponse(response, channel) {
20413
+ switch (response.status) {
20414
+ case 'success':
20415
+ return this.logSuccess(channel);
20481
20416
 
20482
- return axiosInstance.get("".concat(configToUse.paystackApiUrl, "directdebit/account"), {
20483
- headers: headers
20484
- }).then(function (response) {
20485
- return response.data;
20486
- });
20487
- }
20488
- };
20417
+ case 'pending':
20418
+ return this.logPending(channel);
20489
20419
 
20490
- var paymentMethod$1 = 'direct debit';
20491
- var DirectDebitCharge = {
20492
- loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
20493
- var _this = this;
20420
+ case 'failed':
20421
+ return this.logError(response.message);
20494
20422
 
20495
- var email = _ref.email,
20496
- password = _ref.password;
20497
- var params = {
20498
- email: email,
20499
- password: password
20500
- };
20423
+ case 'auth':
20424
+ return this.logAuth(response.data.auth);
20501
20425
 
20502
- if (!isValidEmail(email)) {
20503
- return Promise.reject(Error('Invalid email'));
20426
+ default:
20427
+ return false;
20504
20428
  }
20429
+ },
20430
+ logMobileMoneyActions: function logMobileMoneyActions(_ref) {
20431
+ var numberOfTokenRequests = _ref.numberOfTokenRequests,
20432
+ registrationToken = _ref.registrationToken;
20505
20433
 
20506
- return DirectDebitAPI.loginToDirectDebitAccount(params).then(function (response) {
20507
- if (response.status === 'success') {
20508
- var _response$data = response.data,
20509
- token = _response$data.token,
20510
- permissions = _response$data.user.permissions;
20511
-
20512
- if (!permissions || permissions.length < 1) {
20513
- throw Error('You do not have the privileges to perform this action');
20514
- }
20515
-
20516
- if (permissions.find(function (permission) {
20517
- return permission === 'directdebit-*';
20518
- })) {
20519
- _this.directDebit.token = token;
20520
- return response;
20521
- }
20522
-
20523
- throw Error('You do not have the privileges to perform this action');
20524
- }
20525
-
20526
- return response;
20434
+ if (numberOfTokenRequests) {
20435
+ this.logTokenRequest('mobile money', numberOfTokenRequests);
20436
+ } else if (registrationToken) {
20437
+ this.logTokenSubmitted('mobile money');
20438
+ } else {
20439
+ this.logAttempt('mobile money');
20440
+ }
20441
+ },
20442
+ logAPIResponseMessage: function logAPIResponseMessage(message) {
20443
+ this.log.history.push({
20444
+ type: 'action',
20445
+ message: message,
20446
+ time: this.getTimeSpent()
20527
20447
  });
20448
+ return this.saveLog();
20528
20449
  },
20529
- chargeDirectDebit: function chargeDirectDebit(accountCode) {
20530
- var _this2 = this;
20450
+ logAttempt: function logAttempt(channel) {
20451
+ var message = 'Attempted to pay';
20531
20452
 
20532
- if (!this.directDebit.token) {
20533
- return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
20453
+ if (channel) {
20454
+ message += " with ".concat(channel);
20534
20455
  }
20535
20456
 
20536
- this.logAttempt(paymentMethod$1);
20537
- var params = {
20538
- account_code: accountCode,
20539
- transaction: this.id,
20540
- token: this.directDebit.token
20541
- };
20542
- return DirectDebitAPI.charge(params).then(function (response) {
20543
- _this2.logAPIResponse(response, paymentMethod$1);
20544
-
20545
- if (response.status) {
20546
- _this2.directDebit.chargeResponse = response;
20547
- }
20548
-
20549
- return response;
20457
+ this.log.attempts += 1;
20458
+ this.log.history.push({
20459
+ type: 'action',
20460
+ message: message,
20461
+ time: this.getTimeSpent()
20550
20462
  });
20463
+ return this.saveLog();
20551
20464
  },
20552
- getProvisionedAccounts: function getProvisionedAccounts() {
20553
- var _this3 = this;
20554
-
20555
- return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
20556
- _this3.logAPIResponse(response, paymentMethod$1);
20465
+ logTokenRequest: function logTokenRequest(channel) {
20466
+ var numberOfTokenRequests = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
20467
+ var message = numberOfTokenRequests === 0 ? 'Waiting for customer to submit OTP' : 'Customer requested to resend OTP';
20468
+ this.log.history.push({
20469
+ type: 'action',
20470
+ message: message,
20471
+ channel: channel,
20472
+ time: this.getTimeSpent()
20473
+ });
20474
+ return this.saveLog();
20475
+ },
20476
+ logTokenSubmitted: function logTokenSubmitted(channel) {
20477
+ var message = 'Customer submitted OTP';
20478
+ this.log.history.push({
20479
+ type: 'action',
20480
+ message: message,
20481
+ channel: channel,
20482
+ time: this.getTimeSpent()
20483
+ });
20484
+ return this.saveLog();
20485
+ },
20486
+ logTokenAuthenticationFailure: function logTokenAuthenticationFailure(error) {
20487
+ var message = error ? "Error: ".concat(error) : 'Error';
20488
+ this.log.errors += 1;
20489
+ this.log.history.push({
20490
+ type: 'error',
20491
+ message: message,
20492
+ authentication: 'failed',
20493
+ time: this.getTimeSpent()
20494
+ });
20495
+ return this.saveLog();
20496
+ },
20497
+ logError: function logError(error) {
20498
+ var message = 'Error';
20557
20499
 
20558
- var status = response.status,
20559
- data = response.data;
20500
+ if (error) {
20501
+ message += ": ".concat(error);
20502
+ }
20560
20503
 
20561
- if (status) {
20562
- if (data && data.length < 1) {
20563
- return Promise.reject(Error('You have not provisioned any bank account for Direct Debit yet'));
20564
- }
20504
+ this.log.errors += 1;
20505
+ this.log.history.push({
20506
+ type: 'error',
20507
+ message: message,
20508
+ time: this.getTimeSpent()
20509
+ });
20510
+ return this.saveLog();
20511
+ },
20512
+ logAuth: function logAuth(value) {
20513
+ this.log.authentication = value;
20514
+ this.log.history.push({
20515
+ type: 'auth',
20516
+ message: "Authentication Required: ".concat(value),
20517
+ time: this.getTimeSpent()
20518
+ });
20519
+ return this.saveLog();
20520
+ },
20521
+ logSuccess: function logSuccess(channel) {
20522
+ var message = 'Successfully paid';
20565
20523
 
20566
- _this3.directDebit.accounts = response.data;
20567
- }
20524
+ if (channel) {
20525
+ message += " with ".concat(channel);
20526
+ }
20568
20527
 
20569
- return response;
20528
+ this.log.success = true;
20529
+ this.log.history.push({
20530
+ type: 'success',
20531
+ message: message,
20532
+ time: this.getTimeSpent()
20570
20533
  });
20534
+ return this.saveLog();
20571
20535
  },
20572
- authenticateAccount: function authenticateAccount(otp) {
20573
- var _this4 = this;
20536
+ logPending: function logPending(channel) {
20537
+ var message = 'Payment in progress';
20574
20538
 
20575
- var params = {
20576
- otp: otp,
20577
- transaction: this.id,
20578
- token: this.directDebit.token
20579
- };
20580
- return DirectDebitAPI.authenticate(params).then(function (response) {
20581
- _this4.logAPIResponse(response, paymentMethod$1);
20539
+ if (channel) {
20540
+ message += " with ".concat(channel);
20541
+ }
20582
20542
 
20583
- return response;
20543
+ this.log.history.push({
20544
+ type: 'pending',
20545
+ message: message,
20546
+ time: this.getTimeSpent()
20584
20547
  });
20585
- }
20586
- };
20587
-
20588
- var ChargeFunctions = {
20589
- get: function get(channel) {
20590
- var chargeFunctions = {
20591
- card: CardCharge,
20592
- bank: BankAccountCharge,
20593
- ussd: USSDCharge,
20594
- qr: QRCharge,
20595
- mobile_money: MobileMoneyCharge,
20596
- direct_debit: DirectDebitCharge,
20597
- bank_transfer: PayWithTransferCharge,
20598
- eft: EFT,
20599
- payattitude: PayattitudeCharge,
20600
- apple_pay: ApplePayCharge,
20601
- paypal: PayPalCharge
20602
- };
20603
- return chargeFunctions[channel];
20548
+ return this.saveLog();
20549
+ },
20550
+ logPageClose: function logPageClose() {
20551
+ this.log.history.push({
20552
+ type: 'close',
20553
+ message: 'Closed checkout',
20554
+ time: this.getTimeSpent()
20555
+ });
20556
+ return this.saveLog();
20557
+ },
20558
+ logTransactionCurrencySwitch: function logTransactionCurrencySwitch(_ref2) {
20559
+ var currency = _ref2.currency,
20560
+ _ref2$isUserAction = _ref2.isUserAction,
20561
+ isUserAction = _ref2$isUserAction === void 0 ? true : _ref2$isUserAction;
20562
+ var prefix = isUserAction ? 'User switched' : 'Switched';
20563
+ this.log.history.push({
20564
+ type: 'action',
20565
+ message: "".concat(prefix, " transaction currency to ").concat(currency),
20566
+ time: this.getTimeSpent()
20567
+ });
20568
+ return this.saveLog();
20569
+ },
20570
+ saveLog: function saveLog() {
20571
+ return AnalyticsAPI.saveLog(this.id, this.merchant.key, this.log);
20572
+ },
20573
+ saveIpAddress: function saveIpAddress() {
20574
+ return AnalyticsAPI.saveIp(this.id, this.merchant.key);
20575
+ },
20576
+ saveReferrer: function saveReferrer(referrer) {
20577
+ return AnalyticsAPI.saveReferrer(this.id, this.merchant.key, referrer);
20604
20578
  }
20605
20579
  };
20606
20580
 
@@ -20636,6 +20610,7 @@ var Paystack = (function (exports) {
20636
20610
  this.rememberMeEnabled = data.is_remember_me_enabled;
20637
20611
  this.card = {};
20638
20612
  this.bankAccount = {};
20613
+ this.mobileMoney = {};
20639
20614
  this.ussd = {};
20640
20615
  this.bankTransfer = {};
20641
20616
  this.qr = {};