Skip to content

collana pay JS Docs v0.1.0


collana pay JS Docs / CallbackHandlers

Interface: CallbackHandlers

Defined in: types.ts:1177

Callback functions that the integrator must supply to handle payment lifecycle events.

Remarks

These callbacks are invoked by the SDK at various stages of the payment flow. Each provider wraps them with telemetry before calling.

Example

ts
const callbacks: CallbackHandlers = {
  onClick: async (identity, paymentMethodData) => {
    const order = await fetch('/api/orders', {
      method: 'POST',
      body: JSON.stringify({ provider: identity, paymentMethodData }),
    }).then(r => r.json());
    return { orderId: order.id, checkoutData: { id: order.checkoutId } };
  },
  onApprove: (data) => {
    window.location.href = `/confirmation?order=${data.orderId}`;
  },
  onCancel: (identity) => {
    console.log('Payment cancelled', identity);
  },
  onError: (error) => {
    console.error(`[${error.code}] ${error.message}`);
  },
};

Extended by

Properties

onApprove

onApprove: (data) => void

Defined in: types.ts:1196

Called when the payment is approved by the shopper.

Parameters

data

ApprovalData

Approval details including order ID and optional payer info.

Returns

void


onCancel

onCancel: (identity) => void

Defined in: types.ts:1202

Called when the shopper cancels the payment flow.

Parameters

identity

ProviderIdentity

Identifies which provider was cancelled.

Returns

void


onClick

onClick: (identity, paymentMethodData?) => Promise<OrderResult>

Defined in: types.ts:1190

Called when the shopper clicks a payment button.

Parameters

identity

ProviderIdentity

Identifies which provider button was clicked.

paymentMethodData?

unknown

Provider-specific payment method data (Adyen state.data).

Returns

Promise<OrderResult>

A promise resolving to the created order result.

Remarks

The integrator should create an order on their backend and return an OrderResult. For Adyen providers, paymentMethodData contains the Adyen state.data which should be forwarded to the backend API call.


onError

onError: (error) => void

Defined in: types.ts:1213

Called when an error occurs during the payment flow.

Parameters

error

PaymentError

Structured error with code, message, and provider identity.

Returns

void

Remarks

Provider rendering uses Promise.allSettled, so one provider's failure does not prevent other providers from rendering. Each failure triggers a separate onError call.

CollanaPay SDK Documentation