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 typeDelivers
PaymentPayment and refund notifications, such as PAYMENT_SUCCESS, PAYMENT_AUTHORIZED, and REFUND.
SubscriptionSubscription 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

  1. Open Webhooks → Webhooks and click New webhook.
  2. Select the Project that should send notifications.
  3. Fill in Token. The field is required.
  4. Enter your HTTPS endpoint in URLs. Click Add URL to add more endpoints; each notification is sent to every URL in the list.
  5. Select the Event type: Payment or Subscription.
  6. Set Max attempts: the number of delivery attempts for a notification, up to 10.
  7. Set Interval in seconds: the delay between delivery attempts, up to 600 seconds.
  8. Save the webhook.
  9. 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.

FieldsMeaning
typeEvent to handle.
transactionIdPayment identifier to match to your transaction. Present on payment events and subscription activation/renewal events.
statusPayment or refund result.
amount, currencyDecimal amount as a string and currency code, such as "19.99" and "USD".
flowTypePayment flow: SINGLE_PAY, SINGLE_PAY_RECURRENT, SUBSCRIPTION_BUY, SUBSCRIPTION_RECURRENT, or ONE_TIME.
paymentMethodType, paymentMethodDetailsPayment method and available method details. Details may be absent or null.
merchantPspIdIdentifier of the merchant PSP connection that processed this transaction. It identifies the connection actually used, independently of current routing.
legalEntityNameOptional legal entity name configured on that merchant PSP connection.
routeIdOptional identifier of the Route that processed the payment. It records the actual historical Route and does not change when routing configuration changes.
declineCodeNormalized decline reason, when available for a failed payment.
metadataYour metadata, when included.
subscriptionId, subscriptionProductPlanIdSubscription and plan identifiers on subscription events.
stateSubscription state after the event.
nextPaymentDate, nextPaymentNext payment date and amount/currency, where provided.
deactivatesAtPlanned end of paid access after a soft cancellation, where provided.
expiresAtAuthoritative paid-access cutoff carried by SUBSCRIPTION_EXPIRED.
completedAtPayment 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.

TypeStatusMeaning
PAYMENT_SUCCESSSUCCESSPayment succeeded.
PAYMENT_AUTHORIZEDAUTHORIZEDFunds are authorized, but have not yet been captured.
PAYMENT_SUCCESSCAPTUREDPreviously authorized funds have been captured.
PAYMENT_SUCCESSFAILEDPayment failed. Check declineCode when present.
PAYMENT_SUCCESSCANCELEDPayment or authorization was canceled.
REFUNDREFUND_SUCCESSRefund succeeded.
REFUNDREFUND_FAILEDRefund 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.

TypeStateMeaning
SUBSCRIPTION_ACTIVATEDACTIVE or TRIALSubscription started. TRIAL identifies the trial/intro period and does not necessarily mean it was free.
SUBSCRIPTION_RECURRENT_PAYMENTACTIVERecurring payment succeeded; use the updated nextPaymentDate.
SUBSCRIPTION_DUNNING_PERIODDUNNING_PERIODPayment recovery is in progress. Dunning dates describe the recovery window.
SUBSCRIPTION_REACTIVATEDACTIVESubscription recovered from dunning.
SUBSCRIPTION_CANCELEDCANCELLEDSubscription canceled; deactivatesAt, when provided, indicates when paid access ends.
SUBSCRIPTION_EXPIREDCANCELLEDThe soft-canceled subscription reached expiresAt; its state remains CANCELLED.
SUBSCRIPTION_DEACTIVATEDDEACTIVATEDSubscription deactivated.
SUBSCRIPTION_DEACTIVATED_BY_REFUNDDEACTIVATEDSubscription deactivated following a refund.
SUBSCRIPTION_DEACTIVATED_BY_CANCELDEACTIVATEDSubscription deactivated following cancellation.
SUBSCRIPTION_SWITCH_PLANACTIVE or TRIALSubscription plan changed.
SUBSCRIPTION_PAUSEDPAUSEDSubscription paused. Includes pausedAt and optionally pauseUntilDate.
SUBSCRIPTION_RESUMEDACTIVE, TRIAL, or DUNNING_PERIODSubscription 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.


Did this page help you?