Class UsageRecord

All Implemented Interfaces:
HasId, StripeActiveObject, StripeObjectInterface

public class UsageRecord extends ApiResource implements HasId
Usage records allow you to report customer usage and metrics to Stripe for metered billing of subscription prices.

Related guide: Metered billing

This is our legacy usage-based billing API. See the updated usage-based billing docs.

  • Constructor Details

    • UsageRecord

      public UsageRecord()
  • Method Details

    • createOnSubscriptionItem

      public static UsageRecord createOnSubscriptionItem(String subscriptionItem, Map<String,Object> params) throws StripeException
      Creates a usage record for a specified subscription item and date, and fills it with a quantity.

      Usage records provide quantity information that Stripe uses to track how much a customer is using your service. With usage information and the pricing model set up by the metered billing plan, Stripe helps you send accurate invoices to your customers.

      The default calculation for usage is to add up all the quantity values of the usage records within a billing period. You can change this default behavior with the billing plan’s aggregate_usage parameter. When there is more than one usage record with the same timestamp, Stripe adds the quantity values together. In most cases, this is the desired resolution, however, you can change this behavior with the action parameter.

      The default pricing model for metered billing is per-unit pricing. For finer granularity, you can configure metered billing to have a tiered pricing model.

      Throws:
      StripeException
    • createOnSubscriptionItem

      public static UsageRecord createOnSubscriptionItem(String subscriptionItem, Map<String,Object> params, RequestOptions options) throws StripeException
      Creates a usage record for a specified subscription item and date, and fills it with a quantity.

      Usage records provide quantity information that Stripe uses to track how much a customer is using your service. With usage information and the pricing model set up by the metered billing plan, Stripe helps you send accurate invoices to your customers.

      The default calculation for usage is to add up all the quantity values of the usage records within a billing period. You can change this default behavior with the billing plan’s aggregate_usage parameter. When there is more than one usage record with the same timestamp, Stripe adds the quantity values together. In most cases, this is the desired resolution, however, you can change this behavior with the action parameter.

      The default pricing model for metered billing is per-unit pricing. For finer granularity, you can configure metered billing to have a tiered pricing model.

      Throws:
      StripeException
    • createOnSubscriptionItem

      public static UsageRecord createOnSubscriptionItem(String subscriptionItem, UsageRecordCreateOnSubscriptionItemParams params) throws StripeException
      Creates a usage record for a specified subscription item and date, and fills it with a quantity.

      Usage records provide quantity information that Stripe uses to track how much a customer is using your service. With usage information and the pricing model set up by the metered billing plan, Stripe helps you send accurate invoices to your customers.

      The default calculation for usage is to add up all the quantity values of the usage records within a billing period. You can change this default behavior with the billing plan’s aggregate_usage parameter. When there is more than one usage record with the same timestamp, Stripe adds the quantity values together. In most cases, this is the desired resolution, however, you can change this behavior with the action parameter.

      The default pricing model for metered billing is per-unit pricing. For finer granularity, you can configure metered billing to have a tiered pricing model.

      Throws:
      StripeException
    • createOnSubscriptionItem

      public static UsageRecord createOnSubscriptionItem(String subscriptionItem, UsageRecordCreateOnSubscriptionItemParams params, RequestOptions options) throws StripeException
      Creates a usage record for a specified subscription item and date, and fills it with a quantity.

      Usage records provide quantity information that Stripe uses to track how much a customer is using your service. With usage information and the pricing model set up by the metered billing plan, Stripe helps you send accurate invoices to your customers.

      The default calculation for usage is to add up all the quantity values of the usage records within a billing period. You can change this default behavior with the billing plan’s aggregate_usage parameter. When there is more than one usage record with the same timestamp, Stripe adds the quantity values together. In most cases, this is the desired resolution, however, you can change this behavior with the action parameter.

      The default pricing model for metered billing is per-unit pricing. For finer granularity, you can configure metered billing to have a tiered pricing model.

      Throws:
      StripeException
    • getLivemode

      public Boolean getLivemode()
      Has the value true if the object exists in live mode or the value false if the object exists in test mode.
    • getObject

      public String getObject()
      String representing the object's type. Objects of the same type share the same value.

      Equal to usage_record.

    • getQuantity

      public Long getQuantity()
      The usage quantity for the specified date.
    • getSubscriptionItem

      public String getSubscriptionItem()
      The ID of the subscription item this usage record contains data for.
    • getTimestamp

      public Long getTimestamp()
      The timestamp when this usage occurred.
    • setId

      public void setId(String id)
      Unique identifier for the object.
    • setLivemode

      public void setLivemode(Boolean livemode)
      Has the value true if the object exists in live mode or the value false if the object exists in test mode.
    • setObject

      public void setObject(String object)
      String representing the object's type. Objects of the same type share the same value.

      Equal to usage_record.

    • setQuantity

      public void setQuantity(Long quantity)
      The usage quantity for the specified date.
    • setSubscriptionItem

      public void setSubscriptionItem(String subscriptionItem)
      The ID of the subscription item this usage record contains data for.
    • setTimestamp

      public void setTimestamp(Long timestamp)
      The timestamp when this usage occurred.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getId

      public String getId()
      Unique identifier for the object.
      Specified by:
      getId in interface HasId