Orders
Create a hosted checkout, check its status, list orders and refund.
Declare payments (always on) and refunds in supports when you register. Guide: Payments and refunds.
Create checkout
paylexer_create_checkout( string $platform, array $order )
Creates an order and a hosted checkout for it.
Parameters
| Name | Required | Description |
|---|---|---|
gateway | yes | A code from paylexer_get_gateways(). |
amount | yes | Major units, above zero. |
currency | yes | Must be accepted by the gateway. |
customer.email | yes | Also first_name, last_name, phone, address. Some gateways require a billing address. |
return_url | yes | Where the shopper lands after paying. |
cancel_url | Defaults to return_url. | |
reference | Your order ID, shown in the PayLexer dashboard. | |
description | Line name when you pass no items. | |
items | [{ name, unit_amount, quantity?, id?, description?, metadata? }]. Without items, one line covers the amount. | |
metadata | Passed to the gateway session. | |
test_mode | true uses the gateways' sandbox. | |
merchant_name, theme_color | Hosted page branding. Defaults: site name, white. | |
order_url | Your page for this order on this site. The dashboard links the order's Purchase ID to it. URLs on other sites are ignored. |
The website and your platform ID are added by the PayLexer plugin. You can't set them.
Responses
| Result | Description |
|---|---|
array | The checkout. Save order_reference on your order. |
WP_Error | See Errors. |
Example
$checkout = paylexer_create_checkout( 'acme-bookings', array(
'gateway' => 'stripe',
'amount' => 120.00,
'currency' => 'USD',
'customer' => array( 'email' => 'jane@acme.co' ),
'return_url' => 'https://example.com/thanks',
'reference' => 'WP-42',
) );
Returns
array(
'platform' => 'acme-bookings',
'order_reference' => 'ORD-ADF79AA433405B80',
'checkout_url' => 'https://…',
'checkout' => 'redirect', // or 'modal'
'status_token' => '…',
'return_url' => 'https://…',
'cancel_url' => 'https://…',
)
Pass the array to PayLexer.openCheckout() to open it.
Don't fulfil orders from the browser. Mark orders paid only from the payment_completed webhook.
Get payment status
paylexer_get_payment_status( string $platform, string $order_reference )
PayLexer re-checks the gateway on every call. paid is true for COMPLETED, PARTIALLY_REFUNDED and REFUNDED, and also when the gateway reports succeeded (live_status) before PayLexer has processed its webhook and the charged amount covers the total.
In that window status is still PENDING, and refunds are refused.
Responses
| Result | Description |
|---|---|
array | status, paid, live_status, amount, currency, … |
WP_Error | paylexer_not_found for an order your platform didn't create. |
Example
$status = paylexer_get_payment_status( 'acme-bookings', 'ORD-ADF79AA433405B80' );
Returns
array(
'status' => 'COMPLETED',
'paid' => true,
'live_status' => 'succeeded',
'amount' => 120.0,
'currency' => 'USD',
)
Get orders
paylexer_get_orders( string $platform, array $args = [] )
Newest first, only orders your platform created.
There is deliberately no way to list the site's other orders or customers.
Parameters
| Name | Description |
|---|---|
limit | Page size. |
offset | For paging. |
type | order (default) or subscription. |
with_status | Fetch each order's live status (one gateway re-check per order). Caps limit at 20. |
Responses
| Result | Description |
|---|---|
array | List of reference, type, created_at, status. |
WP_Error | See Errors. |
Example
$orders = paylexer_get_orders( 'acme-bookings', array( 'limit' => 20, 'with_status' => true ) );
Returns
array(
array(
'reference' => 'ORD-ADF79AA433405B80',
'type' => 'order',
'created_at' => '2026-10-01 09:56:24',
'status' => array( 'status' => 'COMPLETED', 'paid' => true ),
),
)
Refund
paylexer_refund( string $platform, string $order_reference, ?float $amount = null, string $reason = '' )
Needs refunds in supports.
Omit $amount for a full refund. The gateway confirms later through the payment_refunded webhook. PayLexer refuses orders that aren't paid, gateways without refund support, and amounts above what's left to refund; the error message says which.
Responses
| Result | Description |
|---|---|
array | The refund. |
WP_Error | e.g. Order is not refundable (status: PENDING). |
Example
paylexer_refund( 'acme-bookings', 'ORD-ADF79AA433405B80' ); // full
paylexer_refund( 'acme-bookings', 'ORD-ADF79AA433405B80', 20.00, 'Late' ); // partial
Returns (failure)
WP_Error( 'paylexer_api_error', 'Order is not refundable (status: PENDING)' )
Render order details
paylexer_render_order_details( string $platform, string $order_reference, bool $with_heading = true, array $known = [] )
Prints the "PayLexer Details" box for one of your orders. Put it in the right-hand sidebar of a two-column admin screen. Prints nothing for other orders. $known (gateway, customer_email, transaction_id) fills rows PayLexer has nothing for.
Example
paylexer_render_order_details( 'acme-bookings', $order_reference );