- The metric that measures what you charge for (API calls, storage GB, and so on).
- The customer’s subscription that determines their pricing plan and billing cycle.
- The actual metric usage that an event consumes. PayPal aggregates this data to calculate charges.
Prerequisites
- Ensure to create and set up all metrics that define how events are aggregated for billing.
- Ensure to register the customers to whom you want to track usage events.
- Ensure to create subscriptions that link customers to your pricing plans.
1. Send usage events to PayPal
You can send usage events using one of the following methods:Send multiple events
As and when events occur, use a valid access token and send a POST request to/v1/commerce/billing/events with all required request parameters.
Include your
billing_tier_id in the request header to enable higher rate limits for high-volume event processing.Request body parameters
| Parameter name | Description |
|---|---|
transaction_idRequired, string | Unique identifier that identifies the event. Ensure transaction_id values are unique across all events. |
metric_codeRequired, string | Unique code that identifies the metric. Use the code you provided when you created the metric. |
external_subscription_idRequired, string | Unique identifier that identifies the subscription. Use the external_id you provided when you created the subscription. |
timestampstring | ISO 8601 timestamp when the event occurred. If not provided, PayPal uses the current time. |
propertiesRequired for SUM, MAX, COUNT_DISTINCT, and LATEST aggregation types, object | Key-value pairs that specify event properties and corresponding usage amounts. The property key you use here (for example, gb for storage or minutes for compute time) must exactly match the aggregation_field value defined in your metric configuration. This ensures PayPal knows which value to aggregate for billing calculations. |
Send a batch of events
Use a valid access token and send a POST request to/v1/commerce/billing/events/batch with all required request parameters. You can send up to 100 events in a single batch request.
On successful batch submission, the PayPal server returns a status confirmation.
Request body parameters
| Parameter name | Description |
|---|---|
eventsRequired, array | Array of event objects. Each event must include the parameters below. |
events.transaction_idRequired, string | A unique identifier that identifies the event. Required for each event in the batch. Ensure transaction_id values are unique across all events. |
events.metric_codeRequired, string | Unique code that identifies the metric. Use the code you provided when you created the metric. |
events.external_subscription_idRequired, string | Unique identifier that identifies the subscription. Use the external_id you provided when you created the subscription. |
events.timestampstring | ISO 8601 timestamp when the event occurred. If not provided, PayPal uses the current time. |
events.propertiesRequired for SUM, MAX, COUNT_DISTINCT, and LATEST aggregation types, object | Key-value pairs that specify event properties and corresponding usage amounts. The property key you use here (for example, gb for storage or minutes for compute time) must exactly match the aggregation_field value defined in your metric configuration. This ensures PayPal knows which value to aggregate for billing calculations. |
2. Optional: Audit usage events
You can retrieve and audit the usage events recorded with PayPal to:- Ensure billing accuracy.
- Solve customer disputes.
- Validate that all events were saved correctly.
- Ensure that the events recorded match your own tracking systems.