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

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,486 +19821,154 @@ var MobileMoneyAPI = {
19821
19821
  }
19822
19822
  };
19823
19823
 
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
- }
19832
-
19833
- resolve(validation);
19834
- });
19835
- }
19836
-
19837
- var mobileMoney = {};
19838
-
19839
- function mobileMoneyChargeAPI(params) {
19840
- var _this = this;
19841
-
19842
- return MobileMoneyAPI.charge(params).then(function (response) {
19843
- if (response.status === 'success') {
19844
- mobileMoney = response;
19824
+ var isMobile_1 = isMobile;
19845
19825
 
19846
- if (response.data && response.data.display && response.data.display.otpSentCount === 1) {
19847
- _this.logTokenRequest('mobile money');
19848
- }
19849
- }
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;
19850
19832
 
19851
- return response;
19852
- });
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));
19853
19834
  }
19854
19835
 
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');
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;
19865
19843
 
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)
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 || []
19890
19854
  };
19891
- return mobileMoneyChargeAPI(params);
19892
19855
  },
19893
- authenticateMobileMoney: function authenticateMobileMoney(payload) {
19894
- var _this3 = this;
19856
+ getTimeSpent: function getTimeSpent(startTime) {
19857
+ var currentTimeInSeconds = Math.round(Date.now() / 1000);
19858
+ return currentTimeInSeconds - startTime;
19859
+ }
19860
+ };
19895
19861
 
19896
- var phoneNumber = payload.phoneNumber,
19897
- provider = payload.provider,
19898
- registrationToken = payload.registrationToken;
19899
- return validate$1(phoneNumber).then(function () {
19900
- _this3.logMobileMoneyActions(payload);
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;
19901
19868
 
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;
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);
19913
19876
 
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
- }
19877
+ var tester = /[\uD800-\uDFFF]/g;
19878
+ var low = /^[\uD800-\uDBFF]$/;
19879
+ var hi = /^[\uDC00-\uDFFF]$/;
19922
19880
 
19923
- return response;
19924
- });
19925
- });
19926
- },
19927
- submitMobileMoneyCode: function submitMobileMoneyCode(payload) {
19928
- var _this4 = this;
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
+ };
19929
19888
 
19930
- return MobileMoneyAPI.submitCode({
19931
- code: payload.code,
19932
- transaction: this.id
19933
- }).then(function (response) {
19934
- _this4.logAPIResponse(response, 'mobile_money');
19889
+ var FORCED = fails(function () {
19890
+ return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
19891
+ || $stringify('\uDEAD') !== '"\\udead"';
19892
+ });
19935
19893
 
19936
- return response;
19937
- });
19938
- },
19939
- listenForMobileMoneyCharge: function listenForMobileMoneyCharge(callback) {
19940
- if (mobileMoney.status !== 'success') {
19941
- return Promise.reject(Error('Please start a mobile money charge with Transaction.chargeMobileMoney()'));
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;
19942
19904
  }
19905
+ });
19906
+ }
19943
19907
 
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
- };
19908
+ var AnalyticsAPIUtils = {
19909
+ saveLog: function saveLog(url, _ref) {
19910
+ var merchantKey = _ref.merchantKey,
19911
+ log = _ref.log;
19963
19912
  var language = getLanguage();
19964
19913
 
19965
- var headers = _objectSpread2({}, language && {
19914
+ var headers = _objectSpread2({
19915
+ Authorization: "Bearer ".concat(merchantKey)
19916
+ }, language && {
19966
19917
  'Accept-Language': language
19967
19918
  });
19968
19919
 
19969
- return axiosInstance.post("".concat(configToUse.paystackApiUrl, "login"), params, {
19920
+ return axiosInstance.post(url, {
19921
+ payload: JSON.stringify(log)
19922
+ }, {
19970
19923
  headers: headers
19971
19924
  }).then(function (response) {
19972
- return ChargeResponses.parse(response.data);
19925
+ return response.data;
19973
19926
  });
19974
19927
  },
19975
- charge: function charge(_ref2) {
19976
- var accountCode = _ref2.account_code,
19977
- transaction = _ref2.transaction,
19978
- token = _ref2.token;
19928
+ getIp: function getIp() {
19929
+ var url = 'https://api.paystack.co/decision/ip';
19979
19930
  var language = getLanguage();
19980
19931
 
19981
- var headers = _objectSpread2({
19982
- Authorization: "Bearer ".concat(token),
19983
- 'jwt-auth': true
19984
- }, language && {
19932
+ var headers = _objectSpread2({}, language && {
19985
19933
  'Accept-Language': language
19986
19934
  });
19987
19935
 
19988
- var params = {
19989
- account_code: accountCode,
19990
- transaction: transaction
19991
- };
19992
- return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/initiate"), params, {
19936
+ return axiosInstance.get(url, {
19993
19937
  headers: headers
19994
19938
  }).then(function (response) {
19995
- return ChargeResponses.parse(response.data);
19939
+ return response.data.data.ip_address;
19996
19940
  });
19997
19941
  },
19998
- authenticate: function authenticate(_ref3) {
19999
- var otp = _ref3.otp,
20000
- transaction = _ref3.transaction,
20001
- token = _ref3.token;
19942
+ saveIp: function saveIp(url, _ref2) {
19943
+ var merchantKey = _ref2.merchantKey;
20002
19944
  var language = getLanguage();
20003
19945
 
20004
19946
  var headers = _objectSpread2({
20005
- Authorization: "Bearer ".concat(token),
20006
- 'jwt-auth': true
19947
+ Authorization: "Bearer ".concat(merchantKey)
20007
19948
  }, language && {
20008
19949
  'Accept-Language': language
20009
19950
  });
20010
19951
 
20011
- var params = {
20012
- otp: otp,
20013
- transaction: transaction
20014
- };
20015
- return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/validate"), params, {
19952
+ return axiosInstance.post(url, null, {
20016
19953
  headers: headers
20017
19954
  }).then(function (response) {
20018
- return ChargeResponses.parse(response.data);
19955
+ return response.data;
20019
19956
  });
20020
19957
  },
20021
- getProvisionedAccounts: function getProvisionedAccounts(token) {
19958
+ saveReferrer: function saveReferrer(url, _ref3) {
19959
+ var merchantKey = _ref3.merchantKey,
19960
+ referrer = _ref3.referrer;
20022
19961
  var language = getLanguage();
20023
19962
 
20024
19963
  var headers = _objectSpread2({
20025
- Authorization: "Bearer ".concat(token),
20026
- 'jwt-auth': true
19964
+ Authorization: "Bearer ".concat(merchantKey)
20027
19965
  }, language && {
20028
19966
  'Accept-Language': language
20029
19967
  });
20030
19968
 
20031
- return axiosInstance.get("".concat(configToUse.paystackApiUrl, "directdebit/account"), {
20032
- headers: headers
20033
- }).then(function (response) {
20034
- return response.data;
20035
- });
20036
- }
20037
- };
20038
-
20039
- var paymentMethod$1 = 'direct debit';
20040
- var DirectDebitCharge = {
20041
- loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
20042
- var _this = this;
20043
-
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;
20076
- });
20077
- },
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;
20099
- });
20100
- },
20101
- getProvisionedAccounts: function getProvisionedAccounts() {
20102
- var _this3 = this;
20103
-
20104
- return DirectDebitAPI.getProvisionedAccounts(this.directDebit.token).then(function (response) {
20105
- _this3.logAPIResponse(response, paymentMethod$1);
20106
-
20107
- var status = response.status,
20108
- data = response.data;
20109
-
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
- }
20114
-
20115
- _this3.directDebit.accounts = response.data;
20116
- }
20117
-
20118
- return response;
20119
- });
20120
- },
20121
- authenticateAccount: function authenticateAccount(otp) {
20122
- var _this4 = this;
20123
-
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);
20131
-
20132
- return response;
20133
- });
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
- }
20167
-
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;
20175
-
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
- };
20187
- },
20188
- getTimeSpent: function getTimeSpent(startTime) {
20189
- var currentTimeInSeconds = Math.round(Date.now() / 1000);
20190
- return currentTimeInSeconds - startTime;
20191
- }
20192
- };
20193
-
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;
20200
-
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);
20208
-
20209
- var tester = /[\uD800-\uDFFF]/g;
20210
- var low = /^[\uD800-\uDBFF]$/;
20211
- var hi = /^[\uDC00-\uDFFF]$/;
20212
-
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;
20219
- };
20220
-
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;
20244
- var language = getLanguage();
20245
-
20246
- var headers = _objectSpread2({
20247
- Authorization: "Bearer ".concat(merchantKey)
20248
- }, language && {
20249
- 'Accept-Language': language
20250
- });
20251
-
20252
- return axiosInstance.post(url, {
20253
- payload: JSON.stringify(log)
20254
- }, {
20255
- headers: headers
20256
- }).then(function (response) {
20257
- return response.data;
20258
- });
20259
- },
20260
- getIp: function getIp() {
20261
- var url = 'https://api.paystack.co/decision/ip';
20262
- var language = getLanguage();
20263
-
20264
- var headers = _objectSpread2({}, language && {
20265
- 'Accept-Language': language
20266
- });
20267
-
20268
- return axiosInstance.get(url, {
20269
- headers: headers
20270
- }).then(function (response) {
20271
- return response.data.data.ip_address;
20272
- });
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 && {
20281
- 'Accept-Language': language
20282
- });
20283
-
20284
- return axiosInstance.post(url, null, {
20285
- headers: headers
20286
- }).then(function (response) {
20287
- return response.data;
20288
- });
20289
- },
20290
- saveReferrer: function saveReferrer(url, _ref3) {
20291
- var merchantKey = _ref3.merchantKey,
20292
- referrer = _ref3.referrer;
20293
- var language = getLanguage();
20294
-
20295
- var headers = _objectSpread2({
20296
- Authorization: "Bearer ".concat(merchantKey)
20297
- }, language && {
20298
- 'Accept-Language': language
20299
- });
20300
-
20301
- return axiosInstance.post(url, {
20302
- referrer: referrer
20303
- }, {
19969
+ return axiosInstance.post(url, {
19970
+ referrer: referrer
19971
+ }, {
20304
19972
  headers: headers
20305
19973
  }).then(function (response) {
20306
19974
  return response.data;
@@ -20582,6 +20250,361 @@ var AnalyticsFunctions$1 = {
20582
20250
  }
20583
20251
  };
20584
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 && {
20418
+ 'Accept-Language': language
20419
+ });
20420
+
20421
+ return axiosInstance.post("".concat(configToUse.paystackApiUrl, "login"), params, {
20422
+ headers: headers
20423
+ }).then(function (response) {
20424
+ return ChargeResponses.parse(response.data);
20425
+ });
20426
+ },
20427
+ charge: function charge(_ref2) {
20428
+ var accountCode = _ref2.account_code,
20429
+ transaction = _ref2.transaction,
20430
+ token = _ref2.token;
20431
+ var language = getLanguage();
20432
+
20433
+ var headers = _objectSpread2({
20434
+ Authorization: "Bearer ".concat(token),
20435
+ 'jwt-auth': true
20436
+ }, language && {
20437
+ 'Accept-Language': language
20438
+ });
20439
+
20440
+ var params = {
20441
+ account_code: accountCode,
20442
+ transaction: transaction
20443
+ };
20444
+ return axiosInstance.post("".concat(configToUse.paystackApiUrl, "directdebit/initiate"), params, {
20445
+ headers: headers
20446
+ }).then(function (response) {
20447
+ return ChargeResponses.parse(response.data);
20448
+ });
20449
+ },
20450
+ authenticate: function authenticate(_ref3) {
20451
+ var otp = _ref3.otp,
20452
+ transaction = _ref3.transaction,
20453
+ token = _ref3.token;
20454
+ var language = getLanguage();
20455
+
20456
+ var headers = _objectSpread2({
20457
+ Authorization: "Bearer ".concat(token),
20458
+ 'jwt-auth': true
20459
+ }, language && {
20460
+ 'Accept-Language': language
20461
+ });
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);
20471
+ });
20472
+ },
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;
20487
+ });
20488
+ }
20489
+ };
20490
+
20491
+ var paymentMethod$1 = 'direct debit';
20492
+ var DirectDebitCharge = {
20493
+ loginToDirectDebitAccount: function loginToDirectDebitAccount(_ref) {
20494
+ var _this = this;
20495
+
20496
+ var email = _ref.email,
20497
+ password = _ref.password;
20498
+ var params = {
20499
+ email: email,
20500
+ password: password
20501
+ };
20502
+
20503
+ if (!isValidEmail(email)) {
20504
+ return Promise.reject(Error('Invalid email'));
20505
+ }
20506
+
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;
20528
+ });
20529
+ },
20530
+ chargeDirectDebit: function chargeDirectDebit(accountCode) {
20531
+ var _this2 = this;
20532
+
20533
+ if (!this.directDebit.token) {
20534
+ return Promise.reject(Error('Please login with Transaction.loginToDirectDebitAccount() to start a Direct debit charge'));
20535
+ }
20536
+
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;
20551
+ });
20552
+ },
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);
20558
+
20559
+ var status = response.status,
20560
+ data = response.data;
20561
+
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
+ }
20566
+
20567
+ _this3.directDebit.accounts = response.data;
20568
+ }
20569
+
20570
+ return response;
20571
+ });
20572
+ },
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;
20585
+ });
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];
20605
+ }
20606
+ };
20607
+
20585
20608
  var TransactionInstance = /*#__PURE__*/function () {
20586
20609
  function TransactionInstance(data) {
20587
20610
  var _this = this;