Better Payment 0.11.1 API
    Preparing search index...

    Interface BetterPaymentPlugin

    A plugin: an object with an id and only the parts it needs.

    const auditLog = definePlugin({
    id: 'audit-log',
    events: {
    '*': (event) => console.log(event.type, event.provider, event.paymentId),
    },
    });

    const payment = betterPayment({ providers: { ... }, plugins: [auditLog] });
    interface BetterPaymentPlugin {
        $ERROR_CODES?: Record<string, string>;
        endpoints?: Record<string, PaymentEndpoint>;
        events?: PaymentEventListeners;
        hooks?: { after?: AfterHook[]; before?: BeforeHook[] };
        id: string;
        init?: (ctx: PluginContext) => Awaitable<void>;
        methods?: (ctx: PluginContext) => Record<string, unknown>;
        onResponse?: (
            response: BetterPaymentResponse,
            ctx: ResponseContext,
        ) => Awaitable<void | BetterPaymentResponse>;
        options?: unknown;
        version?: string;
    }
    Index
    $ERROR_CODES?: Record<string, string>

    The plugin's error codes and their default (English) messages

    endpoints?: Record<string, PaymentEndpoint>

    HTTP routes added to the handler

    Typed payment events (see payment.on())

    hooks?: { after?: AfterHook[]; before?: BeforeHook[] }

    Runs before and after provider operations

    id: string

    Unique id, e.g. commission-router

    init?: (ctx: PluginContext) => Awaitable<void>

    Runs once, before the first operation. Plugins run it in order.

    methods?: (ctx: PluginContext) => Record<string, unknown>

    Members added to the payment object, e.g. { router: { quote } }

    onResponse?: (
        response: BetterPaymentResponse,
        ctx: ResponseContext,
    ) => Awaitable<void | BetterPaymentResponse>

    Runs on every response of the HTTP handler (also replayed ones) and can return a replacement. If it throws, the error is logged and the response is sent unchanged.

    options?: unknown

    The options the plugin was created with, for introspection

    version?: string