UNPKG

bc-payments-sdk

Version:

BetterCommerce's Payments NodeJS SDK is a complete solution for storefront clients that integrate payments. `bc-payments-sdk` is a single point interface for storefront clients for interacting with payment gateways.

42 lines (41 loc) 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Checkout = void 0; const api_1 = require("./api"); const RequestMethod_1 = require("../../constants/enums/RequestMethod"); /** * Class {Checkout} contains methods that can be used to interact with the Checkout * module on the CommerceHub platform. * * The methods in this class can be used to convert a basket into an order, * update the payment response for a given order, and more. */ class Checkout { /** * Converts a basket into an order on the CommerceHub platform. * API Reference - https://api20.bettercommerce.io/swagger/ui/index#!/Checkout/CheckoutConvertBasket * @param data - The data which contains the basket id * @param {Object} options - The options object that contains headers and cookies * @returns The order details response from the CommerceHub platform */ static async convertOrder(data, { headers, cookies }) { console.log("createOrderInput", Object.assign(Object.assign({}, data), { headers, cookies })); const createOrderResult = await api_1.Api.call(`api/v2/commerce/checkout/${data === null || data === void 0 ? void 0 : data.basketId}/convert`, RequestMethod_1.RequestMethod.POST, data, headers, cookies); console.log("createOrderResult", createOrderResult); return createOrderResult; } /** * Updates the payment response in the database based on the payment response data. * API Reference - https://api20.bettercommerce.io/swagger/ui/index#!/Checkout/CheckoutUpdatePaymentResponse * @param data - The data which contains the payment response data * @param {Object} options - The options object that contains headers and cookies * @returns The payment response result from the CommerceHub platform */ static async updatePaymentResponse(data, { headers, cookies }) { console.log("paymentResponseInput", Object.assign(Object.assign({}, data), { headers, cookies })); const { model: paymentResponsePayload } = data; const paymentResponseResult = await api_1.Api.call(`api/v2/commerce/checkout/${data === null || data === void 0 ? void 0 : data.orderId}/payment-response`, RequestMethod_1.RequestMethod.PUT, paymentResponsePayload, headers, cookies); return paymentResponseResult; } } exports.Checkout = Checkout;