UNPKG

bc-elavon-sdk

Version:

BetterCommerce's Elavon NodeJS SDK enables BC client applications to integrate with Elavon merchant API system. It publishes an interface to interact with [Elavon API](https://developer.elavon.com/products/checkout-js/v1/api-reference/) endpoints.

38 lines (37 loc) 1.91 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Api = void 0; const ElavonEnvironment_1 = require("../base/config/ElavonEnvironment"); const RequestMethod_1 = require("../constants/enums/RequestMethod"); const fetcher_1 = __importDefault(require("./util/fetcher")); /** * {Api} class provides a single interface to make REST calls to the Elavon API. * */ class Api { /** * Performs a REST call to the Elavon API. * @param {string} url - The relative url of the API endpoint. * @param {string} method - The HTTP request method. * @param {any} [params] - The request body or query string parameters. * @param {any} [cookies] - Cookies to be sent with the request. * @param {any} [headers] - Headers to be sent with the request. * @returns {Promise<any>} The response from the API. */ static async call(url, method, params, cookies, headers) { let options = { url, method, headers, cookies, baseUrl: ElavonEnvironment_1.ElavonEnvironment.baseUrl, }; if (params) { if ((method === null || method === void 0 ? void 0 : method.toUpperCase()) === RequestMethod_1.RequestMethod.GET) { options = Object.assign(Object.assign({}, options), { params: params }); } else if ((method === null || method === void 0 ? void 0 : method.toUpperCase()) === RequestMethod_1.RequestMethod.POST || (method === null || method === void 0 ? void 0 : method.toUpperCase()) === RequestMethod_1.RequestMethod.PUT) { options = Object.assign(Object.assign({}, options), { data: params }); } } return await (0, fetcher_1.default)(options); } } exports.Api = Api;