Receiving and understanding messages

Request

Sample header

Accept: application/json
X-PURCHASELY-SIGNATURE: ea909...ba5a6,
X-PURCHASELY-TIMESTAMP: 1580...929

To ensure that events are indeed coming from Purchasely Cloud Platform, you can authentify event using informations contained in the HEADER of the HTTP request :

  • X-PURCHASELY-SIGNATURE : message signature

  • X-PURCHASELY-TIMESTAMP : request timestamp to avoid replay attacks

This verification is optionnal.

The timestamp correspond to the query time and (UTC) and it can be ignored if the query is too old (more than 15 minutes ?)

The signature relies on a shared secret that you can find in your Purchasely Console (client_webhook_shared_secret) Purchasely Console > Applications > [YOUR APP] > Application settings

Sample code for signature verification (NodeJS) :

const crypto = require("crypto");

// Request headers
// ---------------
const xPurchaselyTimestamp = "1580909929";
const xPurchaselySignature = "ea909b88098b63ef93711cd14542403e5efe1a23c07d94a764bd4db55abba5a6";

// Signature verification
// ----------------------
const webhookSharedSecret = "foobar";
const dataToSign = webhookSharedSecret + xPurchaselyTimestamp;
const computedSignature = crypto
                          .createHmac("sha256", webhookSharedSecret)
                          .update(dataToSign)
                          .digest("hex");

if (computedSignature === xPurchaselySignature) {
  // request authenticated
}

Body

Sample body

{
  "plan": "<plan vendorID defined in the Purchasely console>",
  "store": "APPLE_APP_STORE",
  "product": "<product vendorID define in the Purchasely console>",
  "user_id": "<user id you provided through the sdk>",
  "event_name": "SUBSCRIPTION_STARTED",
  "offer_type": "NONE",
  "api_version": 3,
  "environment": "SANDBOX",
  "purchased_at": "2021-11-07T17:41:17.000Z",
  "store_country": "FR",
  "next_renewal_at": "2021-11-07T17:44:17.000Z",
  "purchased_at_ms": 1636306877000,
  "event_created_at": "2021-11-07T17:41:34.188Z",
  "is_family_shared": false,
  "store_product_id": "<store product id defined in the store console>",
  "next_renewal_at_ms": 1636307057000,
  "event_created_at_ms": 1636306894188,
  "store_app_bundle_id": "<app bundle id defined in the store console>",
  "subscription_status": "AUTO_RENEWING",
  "store_transaction_id": "100000099999999",
  "original_purchased_at": "2021-11-07T17:41:18.000Z",
  "original_purchased_at_ms": 1636306878000,
  "effective_next_renewal_at": "2021-11-07T17:44:17.000Z",
  "purchasely_subscription_id": "subs_XFJFJEBFFU757FUJH",
  "effective_next_renewal_at_ms": 1636307057000,
  "store_original_transaction_id": "10000009999999"
}

Model

Event

  • name : Event Name Possible values : ACTIVATE| DEACTIVATE | RENEWAL_DISABLED … (full list) See Events repository to understand the exact meaning for each Event, when and why use them.

Attributes

Attributes are meant to give you all the context needed to handle and deeply understand you subscriber lifecycle. Such as store, product, plan, purchased_at, is_family_shared...

See the full list to understand the exact meaning for each Attribute.

Response

When called by Purchasely Cloud Platform, client backend should respond with a HTTP code :

  • HTTP 200 ⇒ the Event has been well received and processed (eg: the subscription has been activated)

  • Other than HTTP 200 or no response (timeout) ⇒ an error has occured and the Event could not be processed :

    • The user is warned through the SDK that something did not work

    • Purchasely Cloud Platform will retry several times to send the Event (max 25 times) in the following hours (except for HTTP 404).

This response from the client backend to the Purchasely Console is mandatory particularly for purchase events (e.g. new subscriptions) coming from the SDK, to ensure that the client backend has granted the user with the entitlements corresponding to the new purchase, and unlocked the access to the premium contents or features.

This response from the client backend is forwarded to the mobile SDK and an error message is displayed to the user, if it is different from HTTP 200.

Last updated

© Purchasely 2020-2023