UNPKG

papara-wrapper

Version:
765 lines (764 loc) 31.6 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var papara_http_1 = __importDefault(require("./papara-http")); var uuid_1 = require("uuid"); var Papara = /** @class */ (function () { /** * Creates an instance of papara. * @param { API_KEY, testEnv = false } */ function Papara(_a) { var API_KEY = _a.API_KEY, _b = _a.testEnv, testEnv = _b === void 0 ? false : _b, _c = _a.debug, debug = _c === void 0 ? false : _c; this.http = new papara_http_1.default({ API_KEY: API_KEY, testEnv: testEnv, debug: debug }); } /** * Returns information about the account associated with the API_KEY. * * @returns Account information. */ Papara.prototype.account = function () { return __awaiter(this, void 0, void 0, function () { var err_1; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, this.http.get("/account")]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_1 = _a.sent(); throw err_1; case 3: return [2 /*return*/]; } }); }); }; /** * Accounts ledgers * * @param { * startDate, * endDate, * page, * pageSize, * entryType, * accountNumber, * } * @returns ledgers */ Papara.prototype.accountLedgers = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var requestBody, err_2; var startDate = _b.startDate, endDate = _b.endDate, page = _b.page, pageSize = _b.pageSize, entryType = _b.entryType, accountNumber = _b.accountNumber; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); requestBody = __assign(__assign(__assign({}, (entryType !== undefined ? { entryType: entryType } : {})), (accountNumber !== undefined ? { accountNumber: accountNumber } : {})), { startDate: startDate, endDate: endDate, page: page, pageSize: pageSize }); return [4 /*yield*/, this.http.post("/account/ledgers", requestBody)]; case 1: return [2 /*return*/, _c.sent()]; case 2: err_2 = _c.sent(); throw err_2; case 3: return [2 /*return*/]; } }); }); }; /** * Accounts settlement * @param { * startDate, * endDate, * entryType, * } * @returns settlement */ Papara.prototype.accountSettlement = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var requestBody, err_3; var startDate = _b.startDate, endDate = _b.endDate, entryType = _b.entryType; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); requestBody = __assign(__assign({}, (entryType !== undefined ? { entryType: entryType } : {})), { startDate: startDate, endDate: endDate }); return [4 /*yield*/, this.http.post("/account/settlement", requestBody)]; case 1: return [2 /*return*/, _c.sent()]; case 2: err_3 = _c.sent(); throw err_3; case 3: return [2 /*return*/]; } }); }); }; /** * Payments papara * @param { * amount, * referenceId, * orderDescription, * notificationUrl, * redirectUrl, * turkishNationalId, * } * @returns */ Papara.prototype.payments = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var requestBody, err_4; var amount = _b.amount, referenceId = _b.referenceId, orderDescription = _b.orderDescription, notificationUrl = _b.notificationUrl, redirectUrl = _b.redirectUrl, turkishNationalId = _b.turkishNationalId; return __generator(this, function (_c) { switch (_c.label) { case 0: requestBody = __assign(__assign(__assign({}, (referenceId !== undefined ? { referenceId: referenceId } : { referenceId: (0, uuid_1.v4)() })), (turkishNationalId !== undefined ? { turkishNationalId: turkishNationalId } : {})), { amount: amount, orderDescription: orderDescription, notificationUrl: notificationUrl, redirectUrl: redirectUrl }); _c.label = 1; case 1: _c.trys.push([1, 3, , 4]); return [4 /*yield*/, this.http.post("/payments", requestBody)]; case 2: return [2 /*return*/, _c.sent()]; case 3: err_4 = _c.sent(); throw err_4; case 4: return [2 /*return*/]; } }); }); }; /** * Payments validation * @param id * @returns */ Papara.prototype.paymentsValidation = function (id) { return __awaiter(this, void 0, void 0, function () { var err_5; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, this.http.get("/payments?id=".concat(id))]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_5 = _a.sent(); throw err_5; case 3: return [2 /*return*/]; } }); }); }; /** * Payments refund * @param id * @returns */ Papara.prototype.paymentsRefund = function (id) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { try { return [2 /*return*/, this.http.put("/payments?id=".concat(id))]; } catch (err) { throw err; } return [2 /*return*/]; }); }); }; // This is a base method for validationBy... methods Papara.prototype.validation = function (method, credential) { return __awaiter(this, void 0, void 0, function () { var response, err_6; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, this.http.get("/validation/".concat(method, "?").concat(method, "=").concat(credential))]; case 1: response = _a.sent(); return [2 /*return*/, response]; case 2: err_6 = _a.sent(); throw err_6; case 3: return [2 /*return*/]; } }); }); }; /** * Validations by account number * @param accountNumber * @returns */ Papara.prototype.validationByAccountNumber = function (accountNumber) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.validation('accountNumber', accountNumber)]; }); }); }; /** * Validations by email * @param email * @returns */ Papara.prototype.validationByEmail = function (email) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.validation('email', email)]; }); }); }; /** * Validations by phone number * @param phoneNumber * @returns */ Papara.prototype.validationByPhoneNumber = function (phoneNumber) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.validation('phoneNumber', phoneNumber)]; }); }); }; /** * Validations by tckn * @param tckn * @returns */ Papara.prototype.validationByTCKN = function (tckn) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.validation('tckn', tckn)]; }); }); }; // This is a base method for masspaymentBy... methods Papara.prototype.masspayment = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var subPath, requestBody, url, err_7; var _c; var method = _b.method, credential = _b.credential, amount = _b.amount, turkishNationalId = _b.turkishNationalId, massPaymentId = _b.massPaymentId; return __generator(this, function (_d) { switch (_d.label) { case 0: subPath = method === 'accountNumber' ? '' : method === 'phoneNumber' ? 'phone' : 'email'; requestBody = __assign(__assign(__assign({}, (turkishNationalId !== undefined ? { turkishNationalId: turkishNationalId } : {})), (massPaymentId !== undefined ? { massPaymentId: massPaymentId } : { massPaymentId: (0, uuid_1.v4)() })), (_c = {}, _c[method] = credential, _c.amount = amount, _c)); url = "/masspayment/".concat(subPath); _d.label = 1; case 1: _d.trys.push([1, 3, , 4]); return [4 /*yield*/, this.http.post(url, requestBody)]; case 2: return [2 /*return*/, _d.sent()]; case 3: err_7 = _d.sent(); throw err_7; case 4: return [2 /*return*/]; } }); }); }; /** * Masspayments by account number * @param { * accountNumber, * amount, * turkishNationalId, * massPaymentId, * } * @returns */ Papara.prototype.masspaymentByAccountNumber = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var accountNumber = _b.accountNumber, amount = _b.amount, turkishNationalId = _b.turkishNationalId, massPaymentId = _b.massPaymentId; return __generator(this, function (_c) { return [2 /*return*/, this.masspayment({ method: 'accountNumber', credential: accountNumber, amount: amount, turkishNationalId: turkishNationalId, massPaymentId: massPaymentId, })]; }); }); }; /** * Masspayments by email * @param { * email, * amount, * turkishNationalId, * massPaymentId, * } * @returns */ Papara.prototype.masspaymentByEmail = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var email = _b.email, amount = _b.amount, turkishNationalId = _b.turkishNationalId, massPaymentId = _b.massPaymentId; return __generator(this, function (_c) { return [2 /*return*/, this.masspayment({ method: 'email', credential: email, amount: amount, turkishNationalId: turkishNationalId, massPaymentId: massPaymentId, })]; }); }); }; /** * Masspayments by phone * @param { * phoneNumber, * amount, * turkishNationalId, * massPaymentId, * } * @returns */ Papara.prototype.masspaymentByPhone = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var phoneNumber = _b.phoneNumber, amount = _b.amount, turkishNationalId = _b.turkishNationalId, massPaymentId = _b.massPaymentId; return __generator(this, function (_c) { return [2 /*return*/, this.masspayment({ method: 'phoneNumber', credential: phoneNumber, amount: amount, turkishNationalId: turkishNationalId, massPaymentId: massPaymentId, })]; }); }); }; // This is a base method for masspaymentVerificationBy... methods Papara.prototype.masspaymentVerification = function (method, credential) { return __awaiter(this, void 0, void 0, function () { var queryParam, err_8; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); queryParam = "".concat(method === 'id' ? 'id' : 'byreference', "=").concat(credential); return [4 /*yield*/, this.http.get("/masspayment".concat(queryParam))]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_8 = _a.sent(); throw err_8; case 3: return [2 /*return*/]; } }); }); }; /** * Masspayments verfication by id * @param id * @returns */ Papara.prototype.masspaymentVerficationById = function (id) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.masspaymentVerification('id', id)]; }); }); }; /** * Masspayments verfication by masspayment id * @param masspaymentId * @returns */ Papara.prototype.masspaymentVerficationByMasspaymentId = function (masspaymentId) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.masspaymentVerification('masspaymentId', masspaymentId)]; }); }); }; Papara.prototype.cashDeposit = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var subPath, requestBody, err_9; var _c; var method = _b.method, credential = _b.credential, amount = _b.amount, merchantReference = _b.merchantReference; return __generator(this, function (_d) { switch (_d.label) { case 0: _d.trys.push([0, 2, , 3]); subPath = method === 'phoneNumber' ? '' : method; requestBody = __assign(__assign({}, (merchantReference !== undefined ? { merchantReference: merchantReference } : { merchantReference: (0, uuid_1.v4)() })), (_c = { amount: amount }, _c[method] = credential, _c)); return [4 /*yield*/, this.http.post("/cashdeposit/".concat(subPath), requestBody)]; case 1: return [2 /*return*/, _d.sent()]; case 2: err_9 = _d.sent(); throw err_9; case 3: return [2 /*return*/]; } }); }); }; /** * Cashs deposit by phone number * @param phoneNumber * @param amount * @param [merchantReference] * @returns */ Papara.prototype.cashDepositByPhoneNumber = function (phoneNumber, amount, merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDeposit({ method: 'phoneNumber', credential: phoneNumber, amount: amount, merchantReference: merchantReference })]; }); }); }; /** * Cashs deposit by account number * @param accountNumber * @param amount * @param [merchantReference] * @returns */ Papara.prototype.cashDepositByAccountNumber = function (accountNumber, amount, merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDeposit({ method: 'accountnumber', credential: accountNumber, amount: amount, merchantReference: merchantReference })]; }); }); }; /** * Cashs deposit by tckn * @param tckn * @param amount * @param [merchantReference] * @returns */ Papara.prototype.cashDepositByTCKN = function (tckn, amount, merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDeposit({ method: 'tckn', credential: tckn, amount: amount, merchantReference: merchantReference })]; }); }); }; /** * Cashs deposit settlement * @param StartDate * @param EndDate * @returns */ Papara.prototype.cashDepositSettlement = function (StartDate, EndDate) { return __awaiter(this, void 0, void 0, function () { var err_10; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, this.http.post("/cashdeposit/settlement", { StartDate: StartDate, EndDate: EndDate, })]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_10 = _a.sent(); throw err_10; case 3: return [2 /*return*/]; } }); }); }; Papara.prototype.cashDepositProvision = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var subPath, requestBody, err_11; var _c; var method = _b.method, credential = _b.credential, amount = _b.amount, merchantReference = _b.merchantReference; return __generator(this, function (_d) { switch (_d.label) { case 0: _d.trys.push([0, 2, , 3]); subPath = "provision/".concat(method.toLowerCase()); requestBody = __assign(__assign({}, (merchantReference !== undefined ? { merchantReference: merchantReference } : { merchantReference: (0, uuid_1.v4)() })), (_c = { amount: amount }, _c[method] = credential, _c)); return [4 /*yield*/, this.http.post("/cashdeposit/".concat(subPath), requestBody)]; case 1: return [2 /*return*/, _d.sent()]; case 2: err_11 = _d.sent(); throw err_11; case 3: return [2 /*return*/]; } }); }); }; /** * Cashs deposit provision by phone number * @param phoneNumber * @param amount * @param [merchantReference] * @returns */ Papara.prototype.cashDepositProvisionByPhoneNumber = function (phoneNumber, amount, merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDepositProvision({ method: 'phoneNumber', credential: phoneNumber, amount: amount, merchantReference: merchantReference, })]; }); }); }; /** * Cashs deposit provision by account number * @param accountNumber * @param amount * @param [merchantReference] * @returns */ Papara.prototype.cashDepositProvisionByAccountNumber = function (accountNumber, amount, merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDepositProvision({ method: 'accountNumber', credential: accountNumber, amount: amount, merchantReference: merchantReference, })]; }); }); }; /** * Cashs deposit provision by tckn * @param tckn * @param amount * @param [merchantReference] * @returns */ Papara.prototype.cashDepositProvisionByTCKN = function (tckn, amount, merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDepositProvision({ method: 'tckn', credential: tckn, amount: amount, merchantReference: merchantReference, })]; }); }); }; /** * Cashs deposit provision complete * @param Id * @param TransactionDate * @returns */ Papara.prototype.cashDepositProvisionComplete = function (Id, TransactionDate) { return __awaiter(this, void 0, void 0, function () { var requestBody, err_12; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); requestBody = { Id: Id, TransactionDate: TransactionDate }; return [4 /*yield*/, this.http.post("/cashdeposit/provision/complete", requestBody)]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_12 = _a.sent(); throw err_12; case 3: return [2 /*return*/]; } }); }); }; /** * Cashs deposit provision settlement * @param StartDate * @param EndDate * @returns */ Papara.prototype.cashDepositProvisionSettlement = function (StartDate, EndDate) { return __awaiter(this, void 0, void 0, function () { var err_13; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, this.http.post("/cashdeposit/provision/settlement", { StartDate: StartDate, EndDate: EndDate, })]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_13 = _a.sent(); throw err_13; case 3: return [2 /*return*/]; } }); }); }; Papara.prototype.cashDepositVerification = function (method, credential) { return __awaiter(this, void 0, void 0, function () { var url, err_14; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); url = method === 'id' ? "/cashdeposit?id=".concat(credential) : "/cashdeposit/byreference?reference=".concat(credential); return [4 /*yield*/, this.http.get(url)]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_14 = _a.sent(); throw err_14; case 3: return [2 /*return*/]; } }); }); }; /** * Cashs deposit verification by id * @param id * @returns */ Papara.prototype.cashDepositVerificationById = function (id) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDepositVerification('id', id)]; }); }); }; /** * Cashs deposit verification by merchant reference * @param merchantReference * @returns */ Papara.prototype.cashDepositVerificationByMerchantReference = function (merchantReference) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.cashDepositVerification('merchantReference', merchantReference)]; }); }); }; /** * Cashs deposit verification by date * @param StartDate * @param EndDate * @param PageIndex * @param PageItemCount * @returns */ Papara.prototype.cashDepositVerificationByDate = function (StartDate, EndDate, PageIndex, PageItemCount) { return __awaiter(this, void 0, void 0, function () { var params, err_15; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); params = { StartDate: StartDate, EndDate: EndDate, PageIndex: PageIndex, PageItemCount: PageItemCount, }; return [4 /*yield*/, this.http.get("/cashdeposit/bydate", { params: params })]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_15 = _a.sent(); throw err_15; case 3: return [2 /*return*/]; } }); }); }; /** * Banks accounts * @returns */ Papara.prototype.bankAccounts = function () { return __awaiter(this, void 0, void 0, function () { var err_16; return __generator(this, function (_a) { switch (_a.label) { case 0: _a.trys.push([0, 2, , 3]); return [4 /*yield*/, this.http.get("/banking/bankaccounts")]; case 1: return [2 /*return*/, _a.sent()]; case 2: err_16 = _a.sent(); throw err_16; case 3: return [2 /*return*/]; } }); }); }; /** * Banks withdrawal * @param { bankAccountId, amount } * @returns */ Papara.prototype.bankWithdrawal = function (_a) { return __awaiter(this, arguments, void 0, function (_b) { var requestBody, err_17; var bankAccountId = _b.bankAccountId, amount = _b.amount; return __generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); requestBody = { amount: amount, bankAccountId: bankAccountId }; return [4 /*yield*/, this.http.post("/banking/withdrawal", requestBody)]; case 1: return [2 /*return*/, _c.sent()]; case 2: err_17 = _c.sent(); throw err_17; case 3: return [2 /*return*/]; } }); }); }; return Papara; }()); exports.default = Papara;