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
| Callback | When |
|---|---|
onSuccess | Payment confirmed server-side (modal), verified: true. Without it, the shopper goes to return_url. |
onCancel | The shopper closed the modal or cancelled. |
onError | The gateway reported a failure. |
onPending | The 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.
| Status | Description |
|---|---|
200 | { status, paid }. Cached up to 5 seconds while unpaid, a day once paid. |
403 | Wrong token, or a platform that is unknown or missing payments. |
404 | An order the platform doesn't own. |
503 | PayLexer is disconnected. |
Returns (200)
{ "status": "COMPLETED", "paid": true }