Transaction events
PaymentsAI dispatches transaction events whenever a payment is processed or declined. Use these events to update order status, trigger fulfillment, or initiate dunning logic server-side without polling the API.
Events
| Event type | When it fires |
|---|---|
transaction-processed | A transaction was processed by the gateway. A payment was captured or a refund was completed. |
transaction-declined | A transaction was declined by the processor or issuer. Fires for each declined attempt, including during subscription dunning. |
Payload
Both events share the same payload shape:
type Event = {
deduplicationId: string;
type: 'transaction-processed' | 'transaction-declined';
organizationId: string;
metadata: Transaction;
};
See Schemas for the full Transaction type definition.
Common use cases
- Fulfill an order: Listen for
transaction-processedwheremetadata.result === 'approved'andmetadata.type === 'sale'. - Handle a refund: Listen for
transaction-processedwheremetadata.type === 'refund'. - Dunning: Listen for
transaction-declinedon subscription payments and notify the customer to update their payment method.
Sequence in a first subscription flow
For a subscription created with a new payment instrument:
- Customer completes the hosted payment form.
transaction-processedfires for the first payment.subscription-activatedfires when the subscription moves toactive.
See Subscription events for the full sequence.