UNPKG

bc-checkout-sdk

Version:

BetterCommerce's Checkout NodeJS SDK enables BC client applications to integrate with Checkout merchant API system. It publishes an interface to interact with [Checkout API](https://api-reference.checkout.com/#operation/getPaymentDetails/) endpoints.

54 lines (53 loc) 1.95 kB
"use strict"; // Package Imports Object.defineProperty(exports, "__esModule", { value: true }); exports.Payment = void 0; const api_1 = require("../api"); const RequestMethod_1 = require("../constants/enums/RequestMethod"); const app_util_1 = require("../utils/app-util"); /** * Class representing a payment. * * Provides methods to request a payment and retrieve the details of a payment. * * @class Payment * @implements {IPayment} */ class Payment { /** * Sends a payment request to the API. * The amount is sanitized before sending. * * API Reference - https://api-reference.checkout.com/#operation/requestAPaymentOrPayout * * @param data {IPaymentRequest} - The payment request data. * @returns A promise resolving to the payment request result or an error object. */ async request(data) { try { const paymentRequestResult = await api_1.Api.call(`payments`, RequestMethod_1.RequestMethod.POST, Object.assign(Object.assign({}, data), { amount: (0, app_util_1.sanitizeAmount)(data === null || data === void 0 ? void 0 : data.amount) })); return paymentRequestResult; } catch (error) { return { hasError: true, error: error }; } } /** * Retrieves the details of a payment from the API. * * API Reference - https://api-reference.checkout.com/#operation/getPaymentDetails * * @param data {String} - The payment id. * @returns A promise resolving to the payment details result or an error object. */ async getDetails(data) { try { const paymentDetailsResult = await api_1.Api.call(`payments/${data}`, RequestMethod_1.RequestMethod.GET); return paymentDetailsResult; } catch (error) { return { hasError: true, error: error }; } } } exports.Payment = Payment;