bc-clearpay-sdk
Version:
BetterCommerce's ClearPay NodeJS SDK enables BC client applications to integrate with ClearPay merchant API system. It publishes an interface to interact with [ClearPay API v2](https://developers.clearpay.co.uk/clearpay-online/reference) endpoints.
37 lines (36 loc) • 1.76 kB
JavaScript
;
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 ClearPayEnvironment_1 = require("../base/config/ClearPayEnvironment");
const RequestMethod_1 = require("../constants/enums/RequestMethod");
const fetcher_1 = __importDefault(require("./util/fetcher"));
/**
* Class {Api} is the entry point for making requests to the ClearPay API.
* This class provides a convenient interface for making API calls.
*/
class Api {
/**
* Make a request to the ClearPay API.
* @param url The endpoint to call.
* @param method The HTTP method to use.
* @param params If the method is GET, these are the query parameters. If the method is POST, these are the request body.
* @param cookies Cookies to send with the request.
* @returns The response from the ClearPay API.
*/
static async call(url, method, params, cookies) {
let options = { url, method, cookies, baseUrl: ClearPayEnvironment_1.ClearPayEnvironment.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) {
options = Object.assign(Object.assign({}, options), { data: params });
}
}
return await (0, fetcher_1.default)(options);
}
}
exports.Api = Api;