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.
101 lines (100 loc) • 5.67 kB
TypeScript
import { IPaymentProcessingData } from "../models/better-commerce/IPaymentProcessingData";
import { IPaymentHookProcessingData } from "../models/better-commerce/IPaymentHookProcessingData";
import { ICommerceProvider } from "../base/contracts/ICommerceProvider";
/**
* Class {BetterCommerceOperation} is the main entry point for all the operations related to BetterCommerce.
* It contains methods for getting order details, creating orders, updating orders, getting payment methods, processing payments and more.
* @implements {ICommerceProvider}
*/
export declare class BetterCommerceOperation implements ICommerceProvider {
/**
* Retrieves the company details by user id. This method is used to get the company details which is linked to the user
* API Reference - https://api20.bettercommerce.io/swagger/ui/index#!/B2B/B2BGetCompanyDetailByUserId
* @param data - The data which contains the user id
* @returns The company details
*/
getCompanyDetails(data: any): Promise<any>;
/**
* 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
* @returns The order details response from the CommerceHub platform
*/
convertOrder(data: any): Promise<any>;
/**
* Processes a payment based on the provided payment data.
*
* This method handles different payment gateways, including PayPal, Checkout,
* Stripe, Klarna, and ClearPay. It retrieves payment method details, constructs
* the order model with payment information, and updates the payment response.
* The method also handles Cash on Delivery (COD) orders and different payment
* statuses such as authorized, paid, declined, and pending.
*
* @param data - The payment processing data, including order details, payment
* method, extras, and more.
* @returns A promise that resolves to the payment status or an error object
* if an error occurs during the payment process.
*/
processPayment(data: IPaymentProcessingData): Promise<any>;
/**
* Process the payment hook.
* @param {IPaymentHookProcessingData} data The payment hook processing data.
* @returns {Promise<any>} The promise of the processed payment hook result.
*/
processPaymentHook(data: IPaymentHookProcessingData): Promise<any>;
/**
* Retrieves the payment status for a given payment gateway and transaction data.
*
* This method interacts with specific payment gateway SDKs to obtain the order or payment status.
* It supports various payment gateways including PayPal, Checkout, Klarna, Stripe, and ClearPay.
* The method determines the payment status based on the gateway-specific response and calculates
* the purchase amount from the order details.
*
* @param gateway - The name of the payment gateway used for the transaction.
* @param data - The transaction data required to fetch the payment status from the gateway.
* @param returnOrderDetails - Flag indicating whether to return order details in the response.
* @returns A promise that resolves to an object containing the status ID, purchase amount, and
* optionally the order details if `returnOrderDetails` is true.
*/
private getPaymentStatus;
/**
* Retrieves a payment method based on the provided gateway and headers/cookies.
*
* @param gateway - The name of the payment gateway to retrieve the payment method for.
* @param { headers, cookies } - The headers and cookies to use while retrieving the payment method.
* @returns A promise that resolves to the retrieved payment method or null if the payment method could not be found.
*/
private getPaymentMethod;
/**
* Updates the payment response in the database after a successful payment hook.
* @param methodName - The name of the payment method.
* @param methodId - The id of the payment method.
* @param orderId - The id of the order.
* @param order - The order object.
* @param statusId - The id of the payment status.
* @param orderValue - The value of the order.
* @param bcOrder - The order object from the BC database.
* @param extras - Additional data that may be required for updating the payment response.
* @returns A promise that resolves to the updated payment response or null if the payment response could not be updated.
*/
private paymentHookOrderSuccessUpdate;
/**
* Handles the update of payment response in the case of a failed payment hook.
*
* This method constructs the order model with payment information for a failed
* payment and updates the payment response in the database. It checks if the
* order ID matches with the BC order ID and processes the update if the order
* amount is valid.
*
* @param methodName - The name of the payment method.
* @param methodId - The ID of the payment method.
* @param orderId - The ID of the order.
* @param order - The order object containing payment details.
* @param statusId - The ID indicating the status of the payment.
* @param orderValue - The value of the order.
* @param bcOrder - The order object from the BC database.
* @param extras - Additional data that may be required for updating the payment response.
* @returns A promise that resolves to the updated payment response or null if the update could not be processed.
*/
private paymentHookOrderFailureUpdate;
}