UNPKG

cashbill

Version:

A TypeScript library for making payments through CashBill gateway.

32 lines (31 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const request = require("request-promise-native"); const BASE_URL = 'https://pay.cashbill.pl/ws/rest/'; class LibModule { constructor(getConfig) { this.getConfig = getConfig; } sendGetRequest(url, options) { return request.get(this.calculateUrl(url), options); } sendPostRequest(url, options = {}) { if (options.form) { options.form = Object.entries(options.form).reduce((prev, [key, value]) => { if (typeof value === 'object') { const nestedObjects = Object.entries(value).reduce((prevNested, [nestedKey, nestedValue]) => ({ ...prevNested, [`${key}.${nestedKey}`]: nestedValue }), {}); return { ...prev, ...nestedObjects }; } return { ...prev, [key]: value }; }, {}); } return request.post(this.calculateUrl(url), options); } parseResult(result) { return JSON.parse(result); } calculateUrl(url) { return BASE_URL + url; } } exports.LibModule = LibModule;