Reference

Monetization Subscriptions

Enterprise Feature

Monetization is available as an add-on as part of an enterprise plan. If you would like to purchase this feature, please contact us at sales@zuplo.com or reach out to your account manager.

Most enterprise features can be used in a trial mode for a limited time. Feel free to use enterprise features for development and testing purposes.

You can programmatically access details of your users subscription when using Zuplo monetization. Here's an example inbound policy that logs the subscription details.

import {
  MonetizationInboundPolicy,
  ZuploContext,
  ZuploRequest,
} from "@zuplo/runtime";

export default async function policy(
  request: ZuploRequest,
  context: ZuploContext,
  options: never,
  policyName: string,
) {
  const subscription = MonetizationInboundPolicy.getSubscription(context);
  context.log.info(subscription);

  return request;
}
ts

This would log the following structure

{
  "id": "sbsc_n8y6RkUYmAthRGt4tUM8EePt",
  "planIds": ["plan_1GkE37DZRQs29J2PpXC0sTjB"],
  "planExternalIds": ["prod_PbcDg7ohd8QzCj"],
  "createdOn": "2024-02-23T21:16:59Z",
  "updatedOn": "2024-02-23T21:16:59Z",
  "quotaResetAnchor": "2024-02-23T21:16:59Z",
  "status": "active",
  "type": "periodic",
  "renewalStrategy": "monthly",
  "region": "us-central1",
  "customerKey": "0bcdec7c-ee20-439f-914a-a38f5d8256b3",
  "subscriptionExternalId": "sub_1On673I1Q9RiM35BdA28auPZ",
  "customerExternalId": "cus_PcKmSeuE3fiVAY",
  "metadata": {
    "subscriber": {
      "email": "example@example.com",
      "sub": "auth0|65d9dab23c1p7e25f84b8b09"
    }
  },
  "nextBillingCycle": "2024-03-23T00:00:00Z",
  "meters": {
    "requests": {
      "max": 10,
      "available": 10
    }
  }
}
json

If no subscription is available, getSubscription will return undefined.

Note how you can see details about the subscriber (e-mail and JWT 'sub' from the Dev Portal sign-in) and the current consumption level of the meters specified on their plan.

This information is only available in the pipeline after the MonetizationInboundPolicy has executed (this loads the subscription data).