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.

156 lines (155 loc) 8.37 kB
import { PaymentMethodType, PaymentMethodTypeId } from "../constants"; export declare const gatewayNameToIdMap: Map<string, number>; export declare const idToGatewayNameMap: Map<number, string>; /** * Given a gateway name, returns the corresponding gateway ID. * @param gatewayName - The name of the payment gateway. * @returns The gateway ID if found, -1 otherwise. */ export declare const getGatewayId: (gatewayName: string) => -1 | PaymentMethodTypeId; /** * Given a gateway ID, returns the corresponding gateway name. * @param {number} id the gateway ID. * @returns {string} the gateway name. */ export declare const getGatewayName: (id: number) => -1 | PaymentMethodType; /** * Determines the payment transaction status based on the payment method and transaction data. * * This function evaluates the payment method ID and corresponding transaction data to ascertain * the status of a payment transaction. For the Checkout payment method, it checks the event type * and response summary to categorize the transaction as either charged or failed. For PayPal, it * assesses the event type to determine if the transaction was captured or if authentication failed. * If the conditions for a charged or failed transaction are not met, it defaults to returning a * status of 'NONE'. * * @param methodId - The ID of the payment method, used to determine the applicable gateway logic. * @param data - The transaction data containing details necessary to determine the transaction status. * @returns A string representing the transaction status, such as 'TXN_CHARGED', 'TXN_FAILED', or 'NONE'. */ export declare const getPaymentTransactionStatus: (methodId: number, data: any) => string; /** * Retrieves the order ID from the payment transaction data. * @param methodId - The ID of the payment method. * @param data - The payment transaction data. * @returns A promise that resolves to the order ID as a string. */ export declare const getPaymentTransactionOrderId: (methodId: number, data: any) => Promise<string>; /** * Retrieves the order number from the given data based on the payment method type. * * @param methodId - The payment method type identifier. * @param data - The data object containing the order number. * @param extras - The extras object containing additional information. * * @returns The order number if found, otherwise the default integer value. */ export declare const getOrderNo: (methodId: number, data: any, extras?: any) => number; /** * Retrieves the payment number from the provided data based on the payment method type. * For CHECKOUT payment method, it retrieves the payment number from the `udf4` field. * For JUSPAY payment method, it retrieves the payment number from the `udf6` field. * @param {number} methodId - The ID of the payment method. * @param {any} data - The data object containing the payment number information. * @param {any} extras - Optional additional data containing configuration or environment information. * @returns {string} The payment number corresponding to the payment method. */ export declare const getPaymentNo: (methodId: number, data: any, extras?: any) => string; /** * Retrieves the authorization code from the provided data. * * This function extracts the authorization code based on the payment method ID. * For the CHECKOUT method, it returns the transaction ID. * For the PAYPAL method, it returns the capture ID from the purchase unit. * For the JUSPAY method, it returns the transaction ID. * * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the authorization code information. * @returns {string} The authorization code corresponding to the payment method. * Returns a default string value if no relevant information is found. */ export declare const getAuthCode: (methodId: number, data: any) => string; /** * Generates a signature string necessary for payment verification. * * This function constructs a signature based on the payment method ID. * For CHECKOUT, it includes various transaction identifiers in the signature. * For PAYPAL, it returns a JSON string containing token, order ID, payer ID, and gateway. * For JUSPAY, it retrieves the EPG transaction ID from the payment gateway response. * * @param {number} methodId - The ID of the payment method. * @param {any} data - The data object containing information related to the payment. * @param {any} hookData - The hook data object containing additional resource information. * @returns {string} The signature string specific to the payment method. * Returns a default string value if no relevant information is found. */ export declare const getSignature: (methodId: number, data: any, hookData: any) => string; /** * Retrieves the PSP (Payment Service Provider) response message from the provided data. * * This function constructs a response message based on the payment method ID. * For the CHECKOUT method, it includes the transaction ID and status in the message. * For the PAYPAL method, it includes only the transaction ID in the message. * For the JUSPAY method, it retrieves the status from the transaction content. * * @param {number} methodId - The ID of the payment method. * @param {any} data - The data object containing information related to the payment. * @returns {string} The PSP response message corresponding to the payment method. * Returns a default string value if no relevant information is found. */ export declare const getPSPResponseMsg: (methodId: number, data: any) => string; /** * Retrieves a boolean indicating whether the PSP info should be saved. * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the PSP info. * @returns {boolean} A boolean indicating whether the PSP info should be saved. */ export declare const getIsSavePSPInfo: (methodId: number, data: any) => boolean; /** * Retrieves the PSP (Payment Service Provider) information from the provided data. * * This function extracts PSP-specific information based on the payment method ID. * For the CHECKOUT method, it returns a fixed value indicating 3D Secure (3ds). * For the JUSPAY method, it attempts to extract the PSP info from the `udf7` field. * * @param {number} methodId - The ID of the payment method. * @param {any} data - The data object containing information related to the payment. * @returns {string} The PSP information corresponding to the payment method. * Returns a default string value if no relevant information is found. */ export declare const getPSPInfo: (methodId: number, data: any) => string; /** * Retrieves the payment identifier from the provided data. * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the payment identifier information. * @returns {string} The payment identifier. */ export declare const getPaymentIdentifier: (methodId: number, data: any) => string; /** * Retrieves the PSP gateway information from the provided data. * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the PSP gateway information. * @returns {string} The PSP gateway information. */ export declare const getPSPGatewayInfo: (methodId: number, data: any) => string; /** * Retrieves the card type from the provided data. * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the card type information. * @returns {string} The card type name. */ export declare const getCardType: (methodId: number, data: any) => string; /** * Retrieves the card issuer from the provided data. * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the card issuer information. * @returns {string} The card issuer name. */ export declare const getCardIssuer: (methodId: number, data: any) => string; /** * Retrieves the card brand from the provided data. * @param {number} methodId - The id of the payment method. * @param {any} data - The data object containing the card brand information. * @returns {string} The card brand name. */ export declare const getCardBrand: (methodId: number, data: any) => string;