InAppify

Payment and promotional entitlement webhooks

Receive InAppify webhooks over POST with payment and gift payload examples, HMAC verification, delivery retries, and idempotent processing.

Webhooks send project events from InAppify to your backend. You create the receiving endpoint; it is not an InAppify public REST API endpoint. The JSON body contains the event directly, without a status or data wrapper.

Enable and configure the endpoint

  1. Open the project's Settings → Payment webhook and enable the webhook.
  2. Enter a public HTTPS URL such as https://api.example.com/webhook. The receiving route must accept POST requests with a JSON body.
  3. Select subscription, consumable, or non-consumable products. Trial starts require both subscriptions and the trial option. Promotional grants require Subscription and do not depend on the trial option.
  4. Copy the signing key when it is issued and store it only on your backend. Signature verification uses the complete value, including its whsec_ prefix.

The webhook signing key is separate from your REST API secret key. Incoming requests do not rely on a user session or Authorization: Bearer; authenticate them through the signature. Configure the server-to-server route so browser login or browser CSRF protection does not prevent delivery.

URLs must not contain credentials or a fragment such as #section. Local, private, and non-public destinations are rejected. Redirects are not followed; register the final HTTPS URL.

Changing the enabled state, URL, or product/trial filters starts a new delivery window at that change and discards pending deliveries associated with the previous settings. Saving unchanged settings does not reset the window. Events preceding activation are not backfilled.

Current event types

eventTypeWhen it is produced
payment.succeededAfter a successful payment commits, including a previously failed payment confirmed through inquiry or a selected trial start
entitlement.promotional_grantedAfter a promotional grant commits through the dashboard or promotional entitlement API, with subscriptions selected

Initial delivery is queued after commit without waiting for the scheduled retry cycle. Arrival depends on queue processing and server availability. The scheduled processor also recovers missed events.

An API gift extension that creates a new grant record has a new eventId. Editing/revoking access and refunds do not currently have separate events in this contract. A payment webhook does not announce later subscription state changes or final consumable delivery.

HTTP request and signature

POST /webhook HTTP/1.1
Host: api.example.com
Content-Type: application/json
X-Inappify-Timestamp: 1796121000
X-Inappify-Signature: v1=<64_HEX_CHARACTERS>

This example is sent to your backend endpoint. X-Inappify-Timestamp is the send time as a Unix timestamp in seconds. The signature is a lowercase hexadecimal HMAC-SHA256 digest:

signedPayload = X-Inappify-Timestamp + "." + rawRequestBody
signature = "v1=" + hex(HMAC-SHA256(signingKey, signedPayload))

Preserve the exact raw request body before parsing JSON. Whitespace, key order, and escaping affect the signature; do not reserialize the JSON. Compare signatures in constant time.

PHP signature verification example

The function verifies the signature before parsing the event. The five-minute replay window is a recommended policy in this example; keep your server clock synchronized. INAPPIFY_WEBHOOK_SECRET is your own backend environment variable containing the key issued in the dashboard.

function verifyInappifyWebhook(
    string $rawBody,
    string $timestamp,
    string $signature,
    string $secret
): array {
    // This example uses a five-minute replay window. Keep the server clock synchronized.
    if ($secret === '' || !ctype_digit($timestamp)
        || abs(time() - (int) $timestamp) > 300) {
        throw new RuntimeException('Invalid webhook timestamp or configuration.');
    }

    if (!preg_match('/^v1=([a-f0-9]{64})$/D', $signature, $match)) {
        throw new RuntimeException('Invalid webhook signature format.');
    }

    // Use the entire whsec_... key as stored; do not strip its prefix or decode it.
    $expected = hash_hmac('sha256', $timestamp . '.' . $rawBody, $secret);
    if (!hash_equals($expected, $match[1])) {
        throw new RuntimeException('Webhook signature mismatch.');
    }

    $event = json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR);
    if (!is_array($event) || !is_string($event['eventId'] ?? null)
        || !is_string($event['eventType'] ?? null)) {
        throw new RuntimeException('Invalid webhook payload.');
    }

    return $event;
}

$event = verifyInappifyWebhook(
    file_get_contents('php://input'),
    $_SERVER['HTTP_X_INAPPIFY_TIMESTAMP'] ?? '',
    $_SERVER['HTTP_X_INAPPIFY_SIGNATURE'] ?? '',
    getenv('INAPPIFY_WEBHOOK_SECRET') ?: ''
);

This code only authenticates and parses. Your route handler must reject authentication errors and return success only after durable event storage or a committed local transaction.

A new key is only displayed when issued. After rotation, replace it on your backend; subsequent deliveries and retries use the current signing key.

Successful payment payloads

Subscription

An example subscription payment in Iranian rial, using fictitious data:

{
  "eventId": "payment.succeeded.67890",
  "eventType": "payment.succeeded",
  "paidAt": "2026-12-01T10:30:00.000000Z",
  "paymentNumber": "PAYMENT-EXAMPLE-001",
  "amount": "100000.00",
  "paymentType": "ShareGateIRR",
  "isTrial": false,
  "appIdentifier": "app_example",
  "appUserIdentifier": "customer_565",
  "productIdentifier": "premium_monthly",
  "productType": "Subscription",
  "deliveryId": null
}

Consumable

{
  "eventId": "payment.succeeded.67891",
  "eventType": "payment.succeeded",
  "paidAt": "2026-12-01T10:30:00.000000Z",
  "paymentNumber": "PAYMENT-EXAMPLE-002",
  "amount": "100000.00",
  "paymentType": "ShareGateIRR",
  "isTrial": false,
  "appIdentifier": "app_example",
  "appUserIdentifier": "customer_565",
  "productIdentifier": "wallet_100",
  "productType": "Consumable",
  "deliveryId": 12345
}

Trial start

{
  "eventId": "payment.succeeded.67892",
  "eventType": "payment.succeeded",
  "paidAt": "2026-12-01T10:30:00.000000Z",
  "paymentNumber": "PAYMENT-EXAMPLE-003",
  "amount": "0.00",
  "paymentType": "Trial",
  "isTrial": true,
  "appIdentifier": "app_example",
  "appUserIdentifier": "customer_565",
  "productIdentifier": "premium_monthly",
  "productType": "Subscription",
  "deliveryId": null
}

A non-consumable uses productType: "NonConsumable" and normally has deliveryId: null. A trial start is the same payment.succeeded event with paymentType: "Trial" and isTrial: true; it is not a cash payment.

Payment fields

FieldTypeMeaning
eventIdstringStable event identifier; currently payment.succeeded.<paymentId>
eventTypestringAlways payment.succeeded
paidAtstringPayment success time as an ISO 8601 UTC timestamp
paymentNumberstringInAppify transaction number, distinct from the event ID and gateway reference
amountstringStored amount as a numeric string; do not convert it to a float
paymentTypestringPayment type enum name, not its numeric value
isTrialbooleanWhether this transaction represents a trial start
appIdentifierstringDashboard app identifier key, not an Android package name
appUserIdentifierstringCustomer identifier within the project
productIdentifierstringPurchased product identifier
productTypestringExactly Subscription, Consumable, or NonConsumable
deliveryIdinteger or nullAssociated consumable delivery ID, when present; its presence does not mean delivery was acknowledged

Defined customer purchase paymentType names are Trial, IranStore, ForeignStore, PersonalGateIRR, PersonalGateUSD, ShareGateIRR, and ShareGateUSD. The value depends on the purchase path.

This payload has no separate currency field. For IRR types and rial purchase paths, the amount is in rial, not toman. Do not treat USD types as rial. Match the unit to the payment type and product configuration. In the rial example, "100000.00" means 100,000 rial.

Promotional entitlement payload

{
  "eventId": "entitlement.promotional_granted.901",
  "eventType": "entitlement.promotional_granted",
  "grantedAt": "2026-12-01T10:30:00.000000Z",
  "appUserIdentifier": "customer_565",
  "entitlementIdentifier": "premium",
  "customerEntitlementId": 901,
  "expiresAt": "2026-12-11T10:30:00.000000Z",
  "periodType": "Promotional"
}
FieldTypeMeaning
eventIdstringStable event identifier; currently entitlement.promotional_granted.<customerEntitlementId>
eventTypestringAlways entitlement.promotional_granted
grantedAtstringGift record creation time as an ISO 8601 UTC timestamp
appUserIdentifierstringCustomer identifier within the project
entitlementIdentifierstringEntitlement identifier, not a product identifier
customerEntitlementIdintegerGift access record ID
expiresAtstring or nullExpiry as an ISO 8601 UTC timestamp, or null when absent
periodTypestringAlways Promotional

A gift does not create a payment. Fields such as amount, paymentNumber, appIdentifier, and productIdentifier are absent from this event. See the promotional entitlement API for granting and extending access.

Receiver response and retries

Any HTTP status from 200 through 299 marks a delivery successful, for example:

HTTP/1.1 204 No Content

Your response body is ignored; no particular JSON response is required. Network errors, timeouts, and any non-2xx code, including 3xx and 4xx, count as failures. The HTTP request timeout is five seconds and the connection timeout is two seconds.

AttemptEligible time after the preceding failure
1Initial dispatch after the event commits
22 minutes
330 minutes
464 minutes
5360 minutes

There are at most five attempts. A minute-based scheduled processor checks retries; the table specifies minimum delays rather than exact arrival times. No further automatic delivery occurs after the attempt budget is exhausted.

Retries retain the same body and eventId, while the timestamp and signature are generated again for each delivery. Event arrival order is not guaranteed. A missing webhook alone does not establish that a payment failed.

Idempotent processing and consumables

  1. Verify POST, the signature, and the timestamp. Resolve the project from the receiving route configuration and that project's signing key.
  2. Choose a handler by eventType. Tolerate additional fields; do not apply financial effects for an authenticated but unknown event type.
  3. Commit a unique (project, eventId) marker and the business effect in one local transaction, or first persist the event in your durable queue. For an already processed event, return 2xx without repeating the effect.
  4. Do not return success if durable storage or required processing fails, so a retry remains possible.

Your server may process an event while its response fails to reach InAppify. Expect duplicates. Do not replace newer state with an older event solely because of its arrival time.

For wallet top-ups from consumables, map productIdentifier to server-configured credit. Also enforce a ledger key on (project, deliveryId) so reconciliation and webhook delivery cannot credit the same purchase twice.

A webhook does not acknowledge consumable delivery. For direct web-link purchases, use deliveryId, appIdentifier, and appUserIdentifier to verify current delivery eligibility and acknowledge after your local commit. That endpoint checks the paid, unrefunded purchase within the project, app, and customer scope.

When inquiry confirms a previously failed payment, its webhook is created when success is committed. See payment inquiry.