API ReferenceWebhooks

Webhooks

Actions and event objects delivered to your plugin.

PayLexer verifies each delivery's signature, checks the tenant, drops replays and logs it before firing your hooks. Guide: Webhooks.

Init action

paylexer_init

Fired on plugins_loaded (priority 20), only while PayLexer is active. Register platforms and adapters here.

Example

add_action( 'paylexer_init', function () {
	paylexer_register_platform( 'acme-bookings', array( 'name' => 'Acme Bookings' ) );
} );

Event actions

paylexer_platform_{id}_{event}
paylexer_platform_{id}_webhook
ActionArgumentsFired
paylexer_platform_{id}_{event}array $eventOne per verified event. {event} is the event type with . replaced by _.
paylexer_platform_{id}_webhookarray $event, string $event_typeEvery verified event.

Event types

PaymentSubscription
payment_initiatedsubscription_created
payment_authorizedsubscription_activated
payment_capturedsubscription_renewed
payment_completed (fulfil here)subscription_payment_failed
payment_failedsubscription_cancelled
payment_cancelledsubscription_paused, subscription_resumed
payment_refundedsubscription_trial_started, subscription_trial_ended
payment_refund_voidedsubscription_updated

Responses

Handler outcomeDescription
ReturnsThe delivery succeeds. Return normally when the order is unknown to you.
ThrowsThe delivery answers 400 and PayLexer retries with backoff.
No platform registeredThe delivery answers 503 and is retried a limited number of times.

A late payment_failed can arrive after payment_completed, so never move a paid order back to unpaid. A retry can deliver the same event twice, so make handlers idempotent. See Writing safe handlers.

Example

add_action( 'paylexer_platform_acme-bookings_payment_completed', function ( array $event ) {
	$reference = $event['data']['orderReference'];
	// Mark your order paid.
} );

Payload

{
  "event": "payment.completed",
  "timestamp": "2026-10-01T10:00:00.000Z",
  "platform": "acme-bookings",
  "data": {
    "orderReference": "ORD-ADF79AA433405B80",
    "amount": 120,
    "currency": "USD",
    "status": "completed",
    "paymentGateway": "stripe",
    "customer": { "email": "jo@example.com", "name": "Jo Doe" }
  }
}

WebhookEvent

Passed to PlatformAdapter::on_event(). Namespace PayLexer\Integration.

FieldDescription
typeThe event type, e.g. payment.completed.
order_referenceA renewal's new order for subscription.renewed.
subscription_idThe subscription_id create_subscription() returned (data.subscriptionReference).
amount, currency, status
rawThe full payload.
refundA WebhookRefund on payment.refunded and payment.refund_voided, otherwise null.
is_own_refund( string $platform )true when the refund was sent with your own refund(), so you already recorded it. API 1.1 and later.

WebhookRefund

FieldDescription
id
amountThis refund only, major units.
total_refundedEvery succeeded refund on the order, this one included. null from older senders.
remaining_refundable
order_statusrefunded, partially_refunded, or completed after a voided refund.
sourceYour platform ID, a gateway code, dashboard or api.
reason

Set your refunded total from total_refunded, not by adding amount, so a replayed event changes nothing.