UNPKG

payunitjs-test

Version:

PayUnit is Seven's Payment aggregator created @SevenGroups by SevenGPS Core Engineers and tested by Silicon Valley professionals and Google experts

112 lines (102 loc) 3.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.verifySelectedGateway = verifySelectedGateway; exports.parseMakePaymentResponse = parseMakePaymentResponse; exports.errorHandler = errorHandler; exports.submitTransactionResponse = submitTransactionResponse; exports.notifyUrlHandler = notifyUrlHandler; exports.paramsParser = paramsParser; function verifySelectedGateway(data) {} function parseMakePaymentResponse(data) {} function errorHandler(error, container) { if (error.error.error && typeof error.error.error === "string") { container.textContent = error.error.error; } else { if (error.error.message && typeof error.error.message === "string") { container.textContent = error.error.message; } else { if (error.error && typeof error.error === "string") { container.textContent = error.error; } else { if (error.message && typeof error.message === "string") { container.textContent = error.message; } else { container.textContent = error; } } } } } function submitTransactionResponse() { var notify_url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; var return_url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var container = arguments[3]; // console.log("Data sent to submitTransactionResponse: ", data); window.location.href = return_url + ("?transaction_id = " + data.data.transaction_id + "&transaction_amount=" + data.amount + "&transaction_gateway=" + data.gateway + "&transaction_status=" + data.status + "&message=" + data.message); if (notify_url.length > 5) { notifyUrlHandler(notify_url, data).then(function (result) { if (result) { container.textContent = "Transaction result successfully submitted to notify_url."; } else { container.textContent = "Transaction result could not be submitted to notify_url."; } }).catch(function (error) { errorHandler(error, container); }); } } function notifyUrlHandler() { var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var notifyPromise = new Promise(function (resolve, reject) { var response = fetch(url, { method: "POST", mode: "no-cors", cache: "no-cache", credentials: "same-origin", headers: { "Content-Type": "application/json" }, redirect: "follow", referrerPolicy: "no-referrer", body: JSON.stringify(data) }); response.then(function (data) { if (data.status == 200 || data.status == 201 || data.status == 0) resolve(true); reject(false); }).catch(function (error) { resolve(false); }); }); return notifyPromise; } function paramsParser() { var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; if (typeof url !== "string") { return false; } else { var paramsArray = url.split("?")[1].split("&"); var paramObject = {}; paramsArray.forEach(function (param) { paramObject[param.split("=")[0]] = param.split("=")[1]; }); return paramObject; } } var messages = exports.messages = { payWith: "Pay via PayUnit", enterPhoneNumber: "Enter your phone number to pay with", fillFormFields: "Fill the various fields and validate your payment", selectProvider: "Select a payment method", userName: "Enter your name", clickPayBtn: "Click on the 'pay' button to pay with", paymentProcessing: "Your Payment is being Processed", errors: { selectValidMethod: "Select a valid payment method", validPhoneNumber: "Enter a valid phone number", phoneNumberOf9Digits: "Enter a Valid Phone NUmber of at most 9 digits" } };