Subscriptions
Start, check, pause, resume and cancel recurring payments.
Declare subscriptions in supports when you register, and pick a gateway that supports them. Guide: Subscriptions.
Create subscription
paylexer_create_subscription( string $platform, array $args )
Parameters
| Name | Required | Description |
|---|---|---|
gateway | yes | A gateway that supports subscriptions. |
amount | yes | Per period, major units. |
currency | yes | |
interval | yes | day, week, month or year. |
customer | yes | email, plus optional first_name, last_name. |
return_url | yes | |
interval_count | ||
trial_days | ||
billing_cycles | 0 means until cancelled. | |
sign_up_fee | ||
product_name, plan_name | ||
product_id | Shown as the SKU. | |
reference | Your own order ID. Shown as the Purchase ID in the dashboard. | |
items | Extra one-time lines charged with the first payment. | |
metadata, cancel_url, test_mode, order_url | As for Create checkout. |
Responses
| Result | Description |
|---|---|
array | The subscription. Save subscription_id. |
WP_Error | See Errors. |
A subscription can't be confirmed from the browser, so a completed modal calls onPending. Activate it from the subscription_activated webhook.
Example
$sub = paylexer_create_subscription( 'acme-bookings', array(
'gateway' => 'stripe',
'amount' => 15.00,
'currency' => 'USD',
'interval' => 'month',
'customer' => array( 'email' => $email ),
'return_url' => $thanks_url,
'product_name' => 'Gold membership',
) );
Returns
array(
'subscription_id' => 'SUB-…',
'order_reference' => 'ORD-…',
'gateway_subscription_id' => '…',
'checkout_url' => 'https://…',
'form_post' => null,
)
Get subscription status
paylexer_get_subscription_status( string $platform, string $subscription_id )
Webhooks stay the source of truth. Use the status when the subscriber returns from checkout, or to reconcile one you think you missed.
Responses
| Result | Description |
|---|---|
array | status is one of PENDING, INCOMPLETE, TRIAL, ACTIVE, PAST_DUE, PAUSED, UNPAID, CANCELLED, EXPIRED. active is true for TRIAL and ACTIVE. |
WP_Error | paylexer_not_found for a subscription your platform didn't create. |
Example
$status = paylexer_get_subscription_status( 'acme-bookings', $subscription_id );
Returns
array(
'status' => 'ACTIVE',
'active' => true,
'current_period_end' => '2026-11-27T00:00:00.000Z',
'trial_end' => null,
'cancel_at' => null,
'billing_cycle_count' => 2,
)
Cancel, pause and resume
paylexer_cancel_subscription( $platform, $subscription_id )
paylexer_pause_subscription( … )
paylexer_resume_subscription( … )
Only subscriptions your platform created can be managed; any other ID returns paylexer_not_found.
Not every gateway can pause, and PayLexer refuses the call with a message when it can't. A subscription the shopper never completed has nothing to cancel at the gateway yet, so the gateway may refuse.
List your subscriptions with paylexer_get_orders() and type => 'subscription'. See Get orders.
Responses
| Result | Description |
|---|---|
array | The updated subscription. |
WP_Error | See Errors. |
Example
paylexer_cancel_subscription( 'acme-bookings', $subscription_id );
paylexer_pause_subscription( 'acme-bookings', $subscription_id );
paylexer_resume_subscription( 'acme-bookings', $subscription_id );
Lifecycle events: see Event types.