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.

55 lines (54 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PaymentContext = void 0; // Other Imports const api_1 = require("../api"); const RequestMethod_1 = require("../constants/enums/RequestMethod"); /** * Class representing a payment context. * * A payment context is a request to the Checkout.com API to perform a payment. * The request includes the payment details and the processing channel id. * * @class PaymentContext * @implements {IPaymentContext} */ class PaymentContext { /** * Sends a payment context request. * * API Reference - https://api-reference.checkout.com/#tag/Payment-Context * * @param data - The payment context data to be sent in the request. * @returns A promise that resolves with the response of the payment context request. * If the request fails, the promise resolves with an error object. */ async request(data) { try { const paymentContextRequestResult = await api_1.Api.call(`payment-contexts`, RequestMethod_1.RequestMethod.POST, data); return paymentContextRequestResult; } catch (error) { return { hasError: true, error: error }; } } /** * Gets the payment context details. * * API Reference - https://api-reference.checkout.com/#operation/getPaymentContext * * @param data - The payment context id to be used in the request. * @returns A promise that resolves with the response of the payment context details request. * If the request fails, the promise resolves with an error object. */ async getDetails(data) { try { const paymentDetailsResult = await api_1.Api.call(`payment-contexts/${data}`, RequestMethod_1.RequestMethod.GET); return paymentDetailsResult; } catch (error) { return { hasError: true, error: error }; } } } exports.PaymentContext = PaymentContext;