UNPKG

@liberquack/utils

Version:
43 lines (42 loc) 1.64 kB
import type { PaymentCalculatedCheckout, PaymentCheckoutExecution } from "../types.js"; export declare type ProviderClientProviderData<P extends AbstractPaymentClientProvider> = P extends AbstractPaymentClientProvider<infer PD> ? PD : never; export declare abstract class AbstractPaymentClientProvider<PD = any> { abstract provider: string; /** * Some providers require data communication between client and their services * if that's the case you will implement something like example A * * if your client side only collect data, you simple will do as example B * * @example Provider that need client actions * const data = await provider.runCustomCode() * * return { * ...checkout, * success: data.success, * externalId: data.id, * } * * @example Data collection only * return { * ...checkout, * success: false, * externalId: false, * } * * @param checkout */ abstract checkout(checkout: PaymentCalculatedCheckout): Promise<PaymentCheckoutExecution>; /** * Implement here UI elements from the provider * */ abstract buildUi(checkout: PaymentCalculatedCheckout, opts: any, sendCheckoutToServer: (checkout: PaymentCalculatedCheckout) => Promise<void>): Promise<HTMLElement>; /** * Sometimes payment providers may require 1 round trip... Internally * an error will be thrown if round trip count is greater than maxRoundTrips * * @return maxRoundTrip integer representing how many round trips are expected */ maxRoundTrips(): number; }