Webhooks
Truegate sends JSON notifications to your backend by HTTP POST. Use them to confirm payment outcomes and update subscription access, even if the customer closes checkout.
Configure delivery
Webhooks are configured per project and per event type. A new project does not inherit webhooks from your other projects: until you create webhooks for it, notifications for that project are not delivered anywhere.
There are two event types:
| Event type | Delivers |
|---|---|
| Payment | Payment and refund notifications, such as PAYMENT_SUCCESS, PAYMENT_AUTHORIZED, and REFUND. |
| Subscription | Subscription lifecycle notifications, such as SUBSCRIPTION_ACTIVATED and SUBSCRIPTION_CANCELED. |
To receive both, create two webhooks for the project: one with the Payment event type and one with Subscription.
Create a webhook in the dashboard
- Open Webhooks → Webhooks and click New webhook.
- Select the Project that should send notifications.
- Fill in Token. The field is required.
- Enter your HTTPS endpoint in URLs. Click Add URL to add more endpoints; each notification is sent to every URL in the list.
- Select the Event type: Payment or Subscription.
- Set Max attempts: the number of delivery attempts for a notification, up to 10.
- Set Interval in seconds: the delay between delivery attempts, up to 600 seconds.
- Save the webhook.
- Repeat these steps for the other event type, and for every other project that should send notifications.
To change an endpoint or retry settings later, open the webhook in the Webhooks list and update it.
Rules and limits
- A project can have only one webhook per event type. To change it, update the existing webhook instead of creating a new one.
- A webhook can have up to 10 URLs. Each URL can be up to 255 characters long and must not contain a comma.
- Each project signs its notifications with its own webhook signing secret. Verify notifications from a project with that project's secret; a secret from another project does not match. See Verify the signature.
- Retries follow the webhook's Max attempts and Interval in seconds. See Acknowledge and handle duplicates.
SUBSCRIPTION_EXPIRED is included in the subscription events group (SUBSCRIPTION_EVENT) and uses its existing delivery URLs and signing secret. No separate configuration is required for this event. If your integration already receives subscription events, make sure your handler accepts this type too.
SUBSCRIPTION_EXPIRED is included in the subscription events group (SUBSCRIPTION_EVENT) and uses its existing delivery URLs and signing secret. No separate configuration is required for this event. If your integration already receives subscription events, make sure your handler accepts this type too.
A successful /start response only creates a transaction. An SDK callback or a return to your website should not be the sole basis for fulfilling an order.
What you receive
Every notification contains type, projectId, externalUserId, and createdAt. Dates are ISO 8601 strings. createdAt is when the notification was created or recorded; event-specific fields such as completedAt, deactivatesAt, and expiresAt carry the business-effective time. Other fields depend on the event.
| Fields | Meaning |
|---|---|
type | Event to handle. |
transactionId | Payment identifier to match to your transaction. Present on payment events and subscription activation/renewal events. |
status | Payment or refund result. |
amount, currency | Decimal amount as a string and currency code, such as "19.99" and "USD". |
flowType | Payment flow: SINGLE_PAY, SINGLE_PAY_RECURRENT, SUBSCRIPTION_BUY, SUBSCRIPTION_RECURRENT, or ONE_TIME. |
paymentMethodType, paymentMethodDetails | Payment method and available method details. Details may be absent or null. |
merchantPspId | Identifier of the merchant PSP connection that processed this transaction. It identifies the connection actually used, independently of current routing. |
legalEntityName | Optional legal entity name configured on that merchant PSP connection. |
routeId | Optional identifier of the Route that processed the payment. It records the actual historical Route and does not change when routing configuration changes. |
declineCode | Normalized decline reason, when available for a failed payment. |
metadata | Your metadata, when included. |
subscriptionId, subscriptionProductPlanId | Subscription and plan identifiers on subscription events. |
state | Subscription state after the event. |
nextPaymentDate, nextPayment | Next payment date and amount/currency, where provided. |
deactivatesAt | Planned end of paid access after a soft cancellation, where provided. |
expiresAt | Authoritative paid-access cutoff carried by SUBSCRIPTION_EXPIRED. |
completedAt | Payment completion time, where available; may be null. |
transactionDetails is a legacy field; prefer paymentMethodDetails for new integrations. Optional processor details such as paymentProcessor and rawPspResponse are diagnostic data, not the basis for order fulfillment.
Newly constructed payment and refund notifications include merchantPspId. The webhook contract still permits it to be absent when replaying legacy payloads. legalEntityName belongs to the merchant PSP connection, so the same name applies across all projects using that connection. It is omitted—not sent as null—when the connection has no configured name.
routeId identifies the Route actually used for the payment, independently of later routing changes or the merchant PSP connection. It is optional because older transactions may not have a recorded Route. When unavailable, it is omitted rather than sent as null.
Payment events and statuses
Always inspect both type and status. Despite its name, PAYMENT_SUCCESS can also carry a failed or canceled result.
| Type | Status | Meaning |
|---|---|---|
PAYMENT_SUCCESS | SUCCESS | Payment succeeded. |
PAYMENT_AUTHORIZED | AUTHORIZED | Funds are authorized, but have not yet been captured. |
PAYMENT_SUCCESS | CAPTURED | Previously authorized funds have been captured. |
PAYMENT_SUCCESS | FAILED | Payment failed. Check declineCode when present. |
PAYMENT_SUCCESS | CANCELED | Payment or authorization was canceled. |
REFUND | REFUND_SUCCESS | Refund succeeded. |
REFUND | REFUND_FAILED | Refund failed. |
For an order requiring collected funds, fulfill it after SUCCESS or CAPTURED. AUTHORIZED alone does not confirm capture. Refunds use their own event and statuses; there is no REFUNDED payment status.
REFUND_CREATED announces a refund request, not a completed refund. TRANSACTION_FEES provides fee details and should not trigger fulfillment again.
Subscription events and states
Subscription events use state, rather than payment status.
| Type | State | Meaning |
|---|---|---|
SUBSCRIPTION_ACTIVATED | ACTIVE or TRIAL | Subscription started. TRIAL identifies the trial/intro period and does not necessarily mean it was free. |
SUBSCRIPTION_RECURRENT_PAYMENT | ACTIVE | Recurring payment succeeded; use the updated nextPaymentDate. |
SUBSCRIPTION_DUNNING_PERIOD | DUNNING_PERIOD | Payment recovery is in progress. Dunning dates describe the recovery window. |
SUBSCRIPTION_REACTIVATED | ACTIVE | Subscription recovered from dunning. |
SUBSCRIPTION_CANCELED | CANCELLED | Subscription canceled; deactivatesAt, when provided, indicates when paid access ends. |
SUBSCRIPTION_EXPIRED | CANCELLED | The soft-canceled subscription reached expiresAt; its state remains CANCELLED. |
SUBSCRIPTION_DEACTIVATED | DEACTIVATED | Subscription deactivated. |
SUBSCRIPTION_DEACTIVATED_BY_REFUND | DEACTIVATED | Subscription deactivated following a refund. |
SUBSCRIPTION_DEACTIVATED_BY_CANCEL | DEACTIVATED | Subscription deactivated following cancellation. |
SUBSCRIPTION_SWITCH_PLAN | ACTIVE or TRIAL | Subscription plan changed. |
SUBSCRIPTION_PAUSED | PAUSED | Subscription paused. Includes pausedAt and optionally pauseUntilDate. |
SUBSCRIPTION_RESUMED | ACTIVE, TRIAL, or DUNNING_PERIOD | Subscription resumed. Check state; resumption alone does not mean a new successful payment. |
Treat cancellation and expiration as separate lifecycle notifications. Cancellation can arrive before access ends; expiration confirms that the paid-access cutoff has been reached. Use expiresAt, not webhook arrival time or createdAt, when removing entitlement.
The expiration event also covers non-renewing subscriptions when their final access period ends. It does not contain a payment transactionId; identify the subscription using subscriptionId and subscriptionProductPlanId. See Subscription expired for eligibility and examples.
A payment and a subscription notification can describe the same purchase. Handle payment accounting and subscription access separately to avoid fulfilling it twice.
Verify the signature
The x-signature HTTP header contains a hexadecimal HMAC-SHA-256 signature of the complete JSON request body, using your project's webhook signing secret.
Keep the raw request body before JSON parsing. Compute the HMAC from those exact bytes and compare it with the header using a timing-safe comparison. Do not reorder fields, reformat JSON, or use the field-order algorithm for outgoing API requests.
TypeScript
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verifyWebhook(
rawBody: Buffer,
signature: string,
secret: string,
): boolean {
if (!/^[a-f0-9]{64}$/i.test(signature)) return false;
const expected = createHmac('sha256', secret).update(rawBody).digest();
const received = Buffer.from(signature, 'hex');
return timingSafeEqual(expected, received);
}PHP
<?php
function verifyWebhook(string $rawBody, string $signature, string $secret): bool
{
if (!preg_match('/\A[a-f0-9]{64}\z/i', $signature)) {
return false;
}
$expected = hash_hmac('sha256', $rawBody, $secret, true);
$received = hex2bin($signature);
return hash_equals($expected, $received);
}Read the raw body with file_get_contents('php://input') and the signature with $_SERVER['HTTP_X_SIGNATURE'] ?? ''.
Go
package webhooks
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
)
func VerifyWebhook(rawBody []byte, signature string, secret string) bool {
received, err := hex.DecodeString(signature)
if err != nil {
return false
}
if len(received) != sha256.Size {
return false
}
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(rawBody)
return hmac.Equal(mac.Sum(nil), received)
}Read the raw body with io.ReadAll(r.Body) and check its error before verification. Read the signature with r.Header.Get("x-signature").
Pass the unmodified request body, the x-signature header (or an empty string if missing), and your webhook secret. Process the event only after verification succeeds. Keep the secret on your backend.
Acknowledge and handle duplicates
Return HTTP 200 after you have durably recorded the notification for processing. Non-2xx responses and delivery failures trigger retries according to your project's configured attempt limit and interval.
Make handling idempotent: receiving the same notification again must not issue another purchase or repeat a subscription transition. Do not deduplicate solely by transactionId: authorization, capture, and refund can refer to the same payment. Keep an event-processing record and account for the event type and result. Return 200 for an already processed notification too.
Updated about 9 hours ago