• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-java / #14623

pending completion
#14623

Pull #1596

github-actions

web-flow
Merge 2db1cc836 into 0adfd1352
Pull Request #1596: Add StripeClient

10149 of 10149 new or added lines in 282 files covered. (100.0%)

14798 of 78436 relevant lines covered (18.87%)

0.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.15
/src/main/java/com/stripe/model/UsageRecord.java
1
// File generated from our OpenAPI spec
2
package com.stripe.model;
3

4
import com.google.gson.annotations.SerializedName;
5
import com.stripe.exception.StripeException;
6
import com.stripe.net.ApiMode;
7
import com.stripe.net.ApiRequestParams;
8
import com.stripe.net.ApiResource;
9
import com.stripe.net.BaseAddress;
10
import com.stripe.net.RequestOptions;
11
import com.stripe.param.UsageRecordCreateOnSubscriptionItemParams;
12
import java.util.Map;
13
import lombok.EqualsAndHashCode;
14
import lombok.Getter;
15
import lombok.Setter;
16

17
/**
18
 * Usage records allow you to report customer usage and metrics to Stripe for metered billing of
19
 * subscription prices.
20
 *
21
 * <p>Related guide: <a href="https://stripe.com/docs/billing/subscriptions/metered-billing">Metered
22
 * billing</a>
23
 */
24
@Getter
25
@Setter
26
@EqualsAndHashCode(callSuper = false)
27
public class UsageRecord extends ApiResource implements HasId {
1✔
28
  /** Unique identifier for the object. */
29
  @Getter(onMethod_ = {@Override})
30
  @SerializedName("id")
31
  String id;
32

33
  /**
34
   * Has the value {@code true} if the object exists in live mode or the value {@code false} if the
35
   * object exists in test mode.
36
   */
37
  @SerializedName("livemode")
38
  Boolean livemode;
39

40
  /**
41
   * String representing the object's type. Objects of the same type share the same value.
42
   *
43
   * <p>Equal to {@code usage_record}.
44
   */
45
  @SerializedName("object")
46
  String object;
47

48
  /** The usage quantity for the specified date. */
49
  @SerializedName("quantity")
50
  Long quantity;
51

52
  /** The ID of the subscription item this usage record contains data for. */
53
  @SerializedName("subscription_item")
54
  String subscriptionItem;
55

56
  /** The timestamp when this usage occurred. */
57
  @SerializedName("timestamp")
58
  Long timestamp;
59

60
  /**
61
   * Creates a usage record for a specified subscription item and date, and fills it with a
62
   * quantity.
63
   *
64
   * <p>Usage records provide {@code quantity} information that Stripe uses to track how much a
65
   * customer is using your service. With usage information and the pricing model set up by the <a
66
   * href="https://stripe.com/docs/billing/subscriptions/metered-billing">metered billing</a> plan,
67
   * Stripe helps you send accurate invoices to your customers.
68
   *
69
   * <p>The default calculation for usage is to add up all the {@code quantity} values of the usage
70
   * records within a billing period. You can change this default behavior with the billing plan’s
71
   * {@code aggregate_usage} <a
72
   * href="https://stripe.com/docs/api/plans/create#create_plan-aggregate_usage">parameter</a>. When
73
   * there is more than one usage record with the same timestamp, Stripe adds the {@code quantity}
74
   * values together. In most cases, this is the desired resolution, however, you can change this
75
   * behavior with the {@code action} parameter.
76
   *
77
   * <p>The default pricing model for metered billing is <a
78
   * href="https://stripe.com/docs/api/plans/object#plan_object-billing_scheme">per-unit
79
   * pricing</a>. For finer granularity, you can configure metered billing to have a <a
80
   * href="https://stripe.com/docs/billing/subscriptions/tiers">tiered pricing</a> model.
81
   */
82
  public static UsageRecord createOnSubscriptionItem(
83
      String subscriptionItem, Map<String, Object> params, RequestOptions options)
84
      throws StripeException {
85
    String url =
1✔
86
        String.format(
1✔
87
            "/v1/subscription_items/%s/usage_records", ApiResource.urlEncodeId(subscriptionItem));
1✔
88
    return getGlobalResponseGetter()
1✔
89
        .request(
1✔
90
            BaseAddress.API,
91
            ApiResource.RequestMethod.POST,
92
            url,
93
            params,
94
            UsageRecord.class,
95
            options,
96
            ApiMode.V1);
97
  }
98

99
  /**
100
   * Creates a usage record for a specified subscription item and date, and fills it with a
101
   * quantity.
102
   *
103
   * <p>Usage records provide {@code quantity} information that Stripe uses to track how much a
104
   * customer is using your service. With usage information and the pricing model set up by the <a
105
   * href="https://stripe.com/docs/billing/subscriptions/metered-billing">metered billing</a> plan,
106
   * Stripe helps you send accurate invoices to your customers.
107
   *
108
   * <p>The default calculation for usage is to add up all the {@code quantity} values of the usage
109
   * records within a billing period. You can change this default behavior with the billing plan’s
110
   * {@code aggregate_usage} <a
111
   * href="https://stripe.com/docs/api/plans/create#create_plan-aggregate_usage">parameter</a>. When
112
   * there is more than one usage record with the same timestamp, Stripe adds the {@code quantity}
113
   * values together. In most cases, this is the desired resolution, however, you can change this
114
   * behavior with the {@code action} parameter.
115
   *
116
   * <p>The default pricing model for metered billing is <a
117
   * href="https://stripe.com/docs/api/plans/object#plan_object-billing_scheme">per-unit
118
   * pricing</a>. For finer granularity, you can configure metered billing to have a <a
119
   * href="https://stripe.com/docs/billing/subscriptions/tiers">tiered pricing</a> model.
120
   */
121
  public static UsageRecord createOnSubscriptionItem(
122
      String subscriptionItem,
123
      UsageRecordCreateOnSubscriptionItemParams params,
124
      RequestOptions options)
125
      throws StripeException {
126
    String url =
×
127
        String.format(
×
128
            "/v1/subscription_items/%s/usage_records", ApiResource.urlEncodeId(subscriptionItem));
×
129
    ApiResource.checkNullTypedParams(url, params);
×
130
    return getGlobalResponseGetter()
×
131
        .request(
×
132
            BaseAddress.API,
133
            ApiResource.RequestMethod.POST,
134
            url,
135
            ApiRequestParams.paramsToMap(params),
×
136
            UsageRecord.class,
137
            options,
138
            ApiMode.V1);
139
  }
140
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc