API ReferenceSubscriptions

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

NameRequiredDescription
gatewayyesA gateway that supports subscriptions.
amountyesPer period, major units.
currencyyes
intervalyesday, week, month or year.
customeryesemail, plus optional first_name, last_name.
return_urlyes
interval_count
trial_days
billing_cycles0 means until cancelled.
sign_up_fee
product_name, plan_name
product_idShown as the SKU.
referenceYour own order ID. Shown as the Purchase ID in the dashboard.
itemsExtra one-time lines charged with the first payment.
metadata, cancel_url, test_mode, order_urlAs for Create checkout.

Responses

ResultDescription
arrayThe subscription. Save subscription_id.
WP_ErrorSee 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

ResultDescription
arraystatus is one of PENDING, INCOMPLETE, TRIAL, ACTIVE, PAST_DUE, PAUSED, UNPAID, CANCELLED, EXPIRED. active is true for TRIAL and ACTIVE.
WP_Errorpaylexer_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

ResultDescription
arrayThe updated subscription.
WP_ErrorSee 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.