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