UNPKG

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.

67 lines (66 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Payment = void 0; const api_1 = require("../api"); const RequestMethod_1 = require("../constants/enums/RequestMethod"); /** * Class {Payment} implements the IPayment interface and provides a convenient interface for making payment-related API calls. * @implements IPayment */ class Payment { /** * Initiates a payment process by creating a checkout session. * This endpoint is used to start the Clearpay payment process, utilizing * the provided order information for consumer pre-approval. * * API Reference - https://developers.clearpay.co.uk/clearpay-online/reference/create-checkout * * @param data - The payment intent data containing order details * @returns A promise that resolves with the result of the checkout session creation, * or an error object if the request fails. */ async initIntent(data) { try { const paymentIntentResult = await api_1.Api.call("v2/checkouts", RequestMethod_1.RequestMethod.POST, data); return paymentIntentResult; } catch (error) { return { hasError: true, error: error }; } } /** * Capture Full Payment. This endpoint performs a payment capture for the full value of the payment plan. * * API Reference - https://developers.clearpay.co.uk/clearpay-online/reference/capture-full-payment * * @param data - The payment capture data containing the checkout session token * @returns A promise that resolves with the result of the payment capture, or an error object if the request fails. */ async requestPayment(data) { try { const paymentCaptureResult = await api_1.Api.call("v2/payments/capture", RequestMethod_1.RequestMethod.POST, data); return paymentCaptureResult; } catch (error) { return { hasError: true, error: error }; } } /** * Get Payment By Order ID. This endpoint retrieves an individual payment along with its order details. * * API Reference - https://developers.clearpay.co.uk/clearpay-online/reference/get-payment-by-order-id * * @param data - The order ID * @returns A promise that resolves with the result of the get payment by order ID request, or an error object if the request fails. */ async getDetails(data) { try { const orderResult = await api_1.Api.call(`v2/payments/${data}`, RequestMethod_1.RequestMethod.GET); return orderResult; } catch (error) { return { hasError: true, error: error }; } } } exports.Payment = Payment;