API ReferenceOrders

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

NameRequiredDescription
gatewayyesA code from paylexer_get_gateways().
amountyesMajor units, above zero.
currencyyesMust be accepted by the gateway.
customer.emailyesAlso first_name, last_name, phone, address. Some gateways require a billing address.
return_urlyesWhere the shopper lands after paying.
cancel_urlDefaults to return_url.
referenceYour order ID, shown in the PayLexer dashboard.
descriptionLine name when you pass no items.
items[{ name, unit_amount, quantity?, id?, description?, metadata? }]. Without items, one line covers the amount.
metadataPassed to the gateway session.
test_modetrue uses the gateways' sandbox.
merchant_name, theme_colorHosted page branding. Defaults: site name, white.
order_urlYour 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

ResultDescription
arrayThe checkout. Save order_reference on your order.
WP_ErrorSee 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

ResultDescription
arraystatus, paid, live_status, amount, currency, …
WP_Errorpaylexer_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

NameDescription
limitPage size.
offsetFor paging.
typeorder (default) or subscription.
with_statusFetch each order's live status (one gateway re-check per order). Caps limit at 20.

Responses

ResultDescription
arrayList of reference, type, created_at, status.
WP_ErrorSee 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

ResultDescription
arrayThe refund.
WP_Errore.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 );