- The metric that measures what you charge for (API calls, storage GB).
- 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
- Create and set up all metrics that define how events are aggregated for billing.
- Register the customers to whom you want to track usage events.
- 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
Use a valid access token and make a POST call to the/v1/commerce/billing/events endpoint with all required request parameters.
On successful event creation, the PayPal server returns an event ID.
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) needs to 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 make a POST call to the/v1/commerce/billing/events/batch endpoint 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. |
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) needs to 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.
- Resolve customer disputes.
- Validate that all events were saved correctly.
- Ensure that the events recorded match your own tracking systems.