Managing entitlements

Determining which user is concerned by the Event

When receiving an event on the Webhook, you can parse the nest user and the properties vendor_id and anonymous_id inside it to determine which user is concerned by the Event.

The property vendor_id will only be populated if a user identifier was set within the app, using the setUserId method of Purchasely SDK.

If the user is not signed-in inside the application, you can rely on the property anonymous_id which will be automatically populated by the Purchasely Cloud Platform.

Determining if new entitlements should be set or removed

The Event name carries the information about the event signification.

  • If the name is PURCHASE_VALIDATED, this means that a new purchase has been made. The corresponding user shall be entitled.

  • If the name is SUBSCRIPTION_EXPIRED, this means that the user subscription has expired. Entitlements shall thus be removed immediately.

  • If the name is SUBSCRIPTION_RENEWED, this means that the user subscription has been renewed. The new expire date shall be set for the existing entitlements at the value of the property expires_at.

Entitlements can be seen as an on/off switch.

Determining which entitlements shall be granted to the user

The Event is also carrying the information related to the Product and Plan purchased by the user. These object are carrying an identifier that you can set yourself in the Purchasely Console (called vendor_id)

Sample payload for a user that has purchased the PURCHASELY_PLUS_MONTHLY Plan attached to the PURCHASELY_PLUS Product.

{
"name" : "PURCHASE_VALIDATED",
"user" : {...},
"properties" : {
"product" : {
"vendor_id": "PUCHASELY_PLUS",
"plan": {
"vendor_id": "PURCHASELY_PLUS_MONTHLY",
"type": "RENEWING_SUBSCRIPTION"
}
}