UNPKG

@hoxhaolsi/cloud-sdk

Version:

LiquidCommerce Cloud SDK

63 lines (62 loc) 2.9 kB
import type { PaymentProviderService } from '../core'; import type { ILiquidPaymentConfig, ILiquidPaymentError, ILiquidPaymentToken, IPaymentElementEventMap } from '../interfaces'; /** * The PaymentService class provides methods for interacting with payment functionality. */ export declare class PaymentService { private paymentProvider; constructor(paymentProvider: PaymentProviderService); /** * Injects a payment element using the provided configuration. * * @param config - The configuration object to be used for injecting the payment element. * @returns A Promise that resolves when the payment element has been successfully injected. * @throws If a failure occurs while injecting the payment element. */ mount(config: ILiquidPaymentConfig): Promise<void>; /** * Generates a payment token. * * @return {Promise<ILiquidPaymentToken | ILiquidPaymentError>} - A promise that resolves to either a payment token or an error. */ generateToken(): Promise<ILiquidPaymentToken | ILiquidPaymentError>; /** * Subscribes a handler function to a specific event type in the payment element. * * @param eventType - The type of event to subscribe to. Must be one of the keys in IPaymentElementEventMap. * @param handler - The handler function to be called when the specified event occurs. * @return void */ subscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler: (event: IPaymentElementEventMap[K]) => void): void; /** * Unsubscribes a handler function from a specific event type for the payment element. * * @param eventType - The event type to unsubscribe from. * @param handler - Optional. The handler function to unsubscribe. If provided, only the specific handler will be unsubscribed. If not provided, all handlers for the event type will be unsubscribed. * @return void */ unsubscribe<K extends keyof IPaymentElementEventMap>(eventType: K, handler?: (event: IPaymentElementEventMap[K]) => void): void; /** * Collapses the payment element if it has been initialized. * Throws an error if the payment element has not been initialized. * * @return {void} * @throws {Error} Will throw an error if the payment element has not been initialized. */ collapse: () => void; /** * Unmounts the payment element from the DOM. * Throws an error if the payment element has not been initialized. * * @return {void} * @throws {Error} Will throw an error if the payment element has not been initialized. */ unmount: () => void; /** * Destroys the payment element if it has been initialized. * * @return {void} No return value. * @throws {Error} Will throw an error if the payment element has not been initialized. */ destroy: () => void; }