UNPKG

airpay-cordova-kit

Version:

A Cordova plugin for Android that allows users to display simple alert dialogs.

235 lines (182 loc) 6.2 kB
class AirpayKitConfig { constructor() { this.privateKey = ''; this.buyerEmail = ''; this.buyerPhone = ''; this.buyerFirstName = ''; this.buyerLastName = ''; this.buyerAddress = ''; this.buyerCity = ''; this.buyerState = ''; this.buyerCountry = ''; this.buyerPinCode = ''; this.customvar = ''; this.amount = ''; this.orderid = ''; this.uid = ''; this.checkSum = ''; this.mercid = ''; this.apyVer = ''; this.currency = ''; this.isocurrency = ''; this.merDom = ''; } } module.exports = AirpayKitConfig; class AirpayKitConfigBuilder { constructor() { this.config = new AirpayKitConfig(); } setPrivateKey(privateKey) { this.config.privateKey = privateKey; return this; } setBuyerEmail(buyerEmail) { this.config.buyerEmail = buyerEmail; return this; } setBuyerPhone(buyerPhone) { this.config.buyerPhone = buyerPhone; return this; } setBuyerFirstName(buyerFirstName) { this.config.buyerFirstName = buyerFirstName; return this; } setBuyerLastName(buyerLastName) { this.config.buyerLastName = buyerLastName; return this; } setBuyerAddress(buyerAddress) { this.config.buyerAddress = buyerAddress; return this; } setBuyerCity(buyerCity) { this.config.buyerCity = buyerCity; return this; } setBuyerState(buyerState) { this.config.buyerState = buyerState; return this; } setBuyerCountry(buyerCountry) { this.config.buyerCountry = buyerCountry; return this; } setBuyerPinCode(buyerPinCode) { this.config.buyerPinCode = buyerPinCode; return this; } setCustomvar(customvar) { this.config.customvar = customvar; return this; } setAmount(amount) { this.config.amount = amount; return this; } setOrderid(orderid) { this.config.orderid = orderid; return this; } setUid(uid) { this.config.uid = uid; return this; } setCheckSum(checkSum) { this.config.checkSum = checkSum; return this; } setMercid(mercid) { this.config.mercid = mercid; return this; } setApyVer(apyVer) { this.config.apyVer = apyVer; return this; } setCurrency(currency) { this.config.currency = currency; return this; } setIsocurrency(isocurrency) { this.config.isocurrency = isocurrency; return this; } setMerDom(merDom) { this.config.merDom = merDom; return this; } build(callback) { // if (!this.config.privateKey || !this.config.buyerEmail || !this.config.buyerPhone || // !this.config.buyerFirstName || !this.config.buyerLastName || !this.config.buyerAddress || // !this.config.buyerCity || !this.config.buyerState || !this.config.buyerCountry || // !this.config.buyerPinCode || !this.config.customvar|| !this.config.amount || !this.config.orderid || // !this.config.uid || !this.config.checkSum || !this.config.mercid || // !this.config.apyVer || !this.config.currency || !this.config.isocurrency || // !this.config.merDom) { // throw new Error('All fields are required.'); // } if (!this.config.privateKey || !this.config.buyerEmail || !this.config.buyerPhone || !this.config.amount || !this.config.orderid || !this.config.checkSum || !this.config.mercid || !this.config.merDom ) { throw new Error('All fields are required.'); } const jsonString = JSON.stringify(this.config); const parsedConfig = JSON.parse(jsonString); console.log('Plugin Config jsonString :', jsonString); console.log('Plugin Config parsedConfig :', parsedConfig); console.log('Plugin Config privatekey :', parsedConfig.privateKey); var data = [{ "privatekey": parsedConfig.privateKey, "buyerEmail": parsedConfig.buyerEmail, "buyerPhone": parsedConfig.buyerPhone, "buyerFirstName": parsedConfig.buyerFirstName, "buyerLastName": parsedConfig.buyerLastName, "buyerAddress": parsedConfig.buyerAddress, "buyerCity": parsedConfig.buyerCity, "buyerState": parsedConfig.buyerState, "buyerCountry": parsedConfig.buyerCountry, "buyerPinCode": parsedConfig.buyerPinCode, "customvar": parsedConfig.customvar, "amount": parsedConfig.amount, "orderid": parsedConfig.orderid, "uid": parsedConfig.uid, "checksum": parsedConfig.checkSum, "mercid": parsedConfig.mercid, "apyVer": parsedConfig.apyVer, "currency": parsedConfig.currency, "isocurrency": parsedConfig.isocurrency, "mer_dom": parsedConfig.merDom } ] localStorage.setItem('formDataArray', data); submitForm(data) callback(this.config); } } module.exports = AirpayKitConfigBuilder; var AirpayKit = { AirpayKitConfigBuilder: AirpayKitConfigBuilder }; module.exports = AirpayKit; function submitForm(config) { console.log('Plugin Config build submitForm :', config); secret = 'RbVqe3xTjiwvlYCB'; // Use your actual secret key here // console.log('checksum:', checksum); // Prepare form data const form = document.createElement('form'); form.action = "https://payments.airpay.ninja/pay/index.php"; // Payment gateway URL form.method = "POST"; form.target = "_self"; for (const key in config[0]) { const input = document.createElement('input'); input.type = 'hidden'; input.name = key; input.value = config[0][key]; form.appendChild(input); } document.body.appendChild(form); form.submit(); }