@paystack/checkout-js 1.26.0-dev.12 → 1.26.0-dev.14

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