API ReferenceBrowser

Browser

Load the checkout script and open a hosted checkout.

Enqueue checkout script

paylexer_enqueue_checkout()

Returns the script handle. Load it once per page and make your own script depend on it.

Example

$handle = paylexer_enqueue_checkout();
wp_enqueue_script( 'acme-checkout', $url, array( $handle ) );

Returns

"paylexer-checkout"

Open checkout

PayLexer.openCheckout( checkout, callbacks )

checkout is the array paylexer_create_checkout() or paylexer_create_subscription() returned, as JSON. Returns a Promise<{ result, orderReference, status? }>. result is "success", "cancel", "error" or "pending".

How it opens is PayLexer's decision, carried in checkout.checkout: modal (in-page) or redirect (full page), plus a signed form POST when form_post is set. There is no option to override it.

Callbacks

CallbackWhen
onSuccessPayment confirmed server-side (modal), verified: true. Without it, the shopper goes to return_url.
onCancelThe shopper closed the modal or cancelled.
onErrorThe gateway reported a failure.
onPendingThe gateway hasn't settled yet, or the result can't be confirmed from the browser (subscriptions), verified: false. The webhook will settle it.

A subscription has no status_token, so a completed subscription checkout goes to onPending, never onSuccess. Activate it from the subscription_activated webhook.

Don't fulfil orders from the browser. Mark orders paid only from the payment_completed webhook.

Example

const result = await PayLexer.openCheckout( checkout, {
  onSuccess( r ) {},
  onCancel() {},
  onError( e ) {},
  onPending( r ) {},
} );

Returns

{ "result": "success", "orderReference": "ORD-ADF79AA433405B80" }

Payment status route

GET /wp-json/paylexer/v1/developer/payment-status?platform=&reference=&token=

Used by openCheckout(). Authenticated by the order's status_token.

StatusDescription
200{ status, paid }. Cached up to 5 seconds while unpaid, a day once paid.
403Wrong token, or a platform that is unknown or missing payments.
404An order the platform doesn't own.
503PayLexer is disconnected.

Returns (200)

{ "status": "COMPLETED", "paid": true }