Skip to content

Commit 6279a5d

Browse files
Add Credit Grant resource
1 parent b0a4c31 commit 6279a5d

8 files changed

Lines changed: 783 additions & 76 deletions

File tree

lib/messages.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ part 'src/messages/billing_details.dart';
1313
part 'src/messages/charge.dart';
1414
part 'src/messages/checkout_session.dart';
1515
part 'src/messages/coupon.dart';
16+
part 'src/messages/credit_grant.dart';
1617
part 'src/messages/customer.dart';
1718
part 'src/messages/data_list.dart';
1819
part 'src/messages/discount.dart';
@@ -28,6 +29,7 @@ part 'src/messages/promotion_code.dart';
2829
part 'src/messages/refund.dart';
2930
part 'src/messages/requests/confirm_payment_intent.dart';
3031
part 'src/messages/requests/create_checkout_session.dart';
32+
part 'src/messages/requests/create_credit_grant.dart';
3133
part 'src/messages/requests/create_customer.dart';
3234
part 'src/messages/requests/create_discount.dart';
3335
part 'src/messages/requests/create_invoice_preview_request.dart';
@@ -40,13 +42,15 @@ part 'src/messages/requests/create_subscription.dart';
4042
part 'src/messages/requests/create_subscription_schedule.dart';
4143
part 'src/messages/requests/created.dart';
4244
part 'src/messages/requests/list_coupons.dart';
45+
part 'src/messages/requests/list_credit_grants.dart';
4346
part 'src/messages/requests/list_prices.dart';
4447
part 'src/messages/requests/list_products.dart';
4548
part 'src/messages/requests/list_promotion_codes.dart';
4649
part 'src/messages/requests/list_subscription_items.dart';
4750
part 'src/messages/requests/list_subscription_schedules.dart';
4851
part 'src/messages/requests/list_subscriptions.dart';
4952
part 'src/messages/requests/subscription_payment_settings.dart';
53+
part 'src/messages/requests/update_credit_grant.dart';
5054
part 'src/messages/requests/update_customer.dart';
5155
part 'src/messages/requests/update_payment_intent.dart';
5256
part 'src/messages/requests/update_subscription.dart';

lib/messages.g.dart

Lines changed: 358 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/messages/credit_grant.dart

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
part of '../../messages.dart';
2+
3+
enum _CreditGrantObject {
4+
@JsonValue('billing.credit_grant')
5+
billingCreditGrant,
6+
}
7+
8+
/// https://docs.stripe.com/api/billing/credit-grant/object
9+
@JsonSerializable()
10+
class CreditGrant extends Message {
11+
final _CreditGrantObject object;
12+
13+
/// Unique identifier for the object.
14+
final String id;
15+
16+
/// Amount of this credit grant.
17+
final CreditGrantAmount amount;
18+
19+
/// Configuration specifying what this credit grant applies to. We currently
20+
/// only support metered prices that have a Billing Meter attached to them.
21+
final CreditGrantApplicabilityConfig applicabilityConfig;
22+
23+
/// he category of this credit grant. This is for tracking purposes and isn’t
24+
/// displayed to the customer.
25+
final CreditGrantCategory category;
26+
27+
/// Time at which the object was created. Measured in seconds since the Unix
28+
/// epoch.
29+
final int created;
30+
31+
/// ID of the customer receiving the billing credits.
32+
final String customer;
33+
34+
/// Has the value true if the object exists in live mode or the value false
35+
/// if the object exists in test mode.
36+
final bool livemode;
37+
38+
/// Time at which the object was last updated. Measured in seconds since the
39+
/// Unix epoch.
40+
final int updated;
41+
42+
/// The time when the billing credits become effective-when they’re eligible
43+
/// for use.
44+
final int? effectiveAt;
45+
46+
/// The time when the billing credits expire. If not present, the billing
47+
/// credits don’t expire.
48+
final int? expiresAt;
49+
50+
/// Set of key-value pairs that you can attach to an object. This can be
51+
/// useful for storing additional information about the object in a structured
52+
/// format.
53+
final Map<String, dynamic>? metadata;
54+
55+
/// A descriptive name shown in dashboard.
56+
final String? name;
57+
58+
/// The time when this credit grant was voided. If not present, the credit
59+
/// grant hasn’t been voided.
60+
final int? voidedAt;
61+
62+
CreditGrant({
63+
required this.object,
64+
required this.id,
65+
required this.amount,
66+
required this.applicabilityConfig,
67+
required this.category,
68+
required this.created,
69+
required this.customer,
70+
required this.livemode,
71+
required this.updated,
72+
this.effectiveAt,
73+
this.expiresAt,
74+
this.metadata,
75+
this.name,
76+
this.voidedAt,
77+
});
78+
79+
factory CreditGrant.fromJson(Map<String, dynamic> json) =>
80+
_$CreditGrantFromJson(json);
81+
82+
@override
83+
Map<String, dynamic> toJson() => _$CreditGrantToJson(this);
84+
}
85+
86+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-amount
87+
@JsonSerializable()
88+
class CreditGrantAmount {
89+
/// The monetary amount.
90+
final CreditGrantAmountMonetary? monetary;
91+
92+
/// The type of this amount. We currently only support monetary billing
93+
/// credits.
94+
final CreditGrantAmountType type;
95+
96+
CreditGrantAmount({
97+
98+
required this.type,
99+
this.monetary,
100+
});
101+
102+
factory CreditGrantAmount.fromJson(Map<String, dynamic> json) =>
103+
_$CreditGrantAmountFromJson(json);
104+
105+
Map<String, dynamic> toJson() => _$CreditGrantAmountToJson(this);
106+
}
107+
108+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-amount-monetary
109+
@JsonSerializable()
110+
class CreditGrantAmountMonetary {
111+
/// Three-letter ISO currency code, in lowercase. Must be a supported
112+
/// currency.
113+
final String currency;
114+
115+
/// A positive integer representing the amount.
116+
final int value;
117+
118+
CreditGrantAmountMonetary({
119+
required this.currency,
120+
required this.value,
121+
});
122+
123+
factory CreditGrantAmountMonetary.fromJson(Map<String, dynamic> json) =>
124+
_$CreditGrantAmountMonetaryFromJson(json);
125+
126+
Map<String, dynamic> toJson() => _$CreditGrantAmountMonetaryToJson(this);
127+
}
128+
129+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-amount-type
130+
enum CreditGrantAmountType {
131+
/// The amount is a monetary amount.
132+
monetary,
133+
}
134+
135+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-applicability_config
136+
@JsonSerializable()
137+
class CreditGrantApplicabilityConfig {
138+
/// Specify the scope of this applicability config.
139+
final CreditGrantApplicabilityConfigScope scope;
140+
141+
CreditGrantApplicabilityConfig({
142+
required this.scope,
143+
});
144+
145+
factory CreditGrantApplicabilityConfig.fromJson(Map<String, dynamic> json) =>
146+
_$CreditGrantApplicabilityConfigFromJson(json);
147+
148+
Map<String, dynamic> toJson() => _$CreditGrantApplicabilityConfigToJson(this);
149+
}
150+
151+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-applicability_config-scope
152+
@JsonSerializable()
153+
class CreditGrantApplicabilityConfigScope {
154+
/// The price type that credit grants can apply to. We currently only support
155+
/// the metered price type. This refers to prices that have a Billing Meter
156+
/// attached to them. Cannot be used in combination with prices.
157+
final CreditGrantApplicabilityConfigScopePriceType? priceType;
158+
159+
CreditGrantApplicabilityConfigScope({
160+
this.priceType,
161+
});
162+
163+
factory CreditGrantApplicabilityConfigScope.fromJson(
164+
Map<String, dynamic> json) =>
165+
_$CreditGrantApplicabilityConfigScopeFromJson(json);
166+
167+
Map<String, dynamic> toJson() =>
168+
_$CreditGrantApplicabilityConfigScopeToJson(this);
169+
}
170+
171+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-applicability_config-scope-price_type
172+
enum CreditGrantApplicabilityConfigScopePriceType {
173+
/// Credit grants being created can only apply to metered prices.
174+
metered,
175+
}
176+
177+
/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-category
178+
enum CreditGrantCategory {
179+
/// The credit grant was purchased by the customer for some amount.
180+
paid,
181+
182+
/// The credit grant was given to the customer for free.
183+
promotional,
184+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
part of '../../../messages.dart';
2+
3+
/// https://docs.stripe.com/api/billing/credit-grant/create
4+
@JsonSerializable()
5+
class CreateCreditGrantRequest {
6+
/// Amount of this credit grant.
7+
final CreditGrantCreateRequestAmount amount;
8+
9+
/// Configuration specifying what this credit grant applies to. We currently
10+
/// only support metered prices that have a Billing Meter attached to them.
11+
final CreditGrantCreateRequestApplicabilityConfig applicabilityConfig;
12+
13+
/// The category of this credit grant.
14+
final CreditGrantCategory category;
15+
16+
/// ID of the customer to receive the billing credits.
17+
final String customer;
18+
19+
/// The time when the billing credits become effective-when they’re eligible
20+
/// for use. It defaults to the current timestamp if not specified.
21+
final int? effectiveAt;
22+
23+
/// The time when the billing credits expire. If not specified, the billing
24+
/// credits don’t expire.
25+
final int? expiresAt;
26+
27+
/// Set of key-value pairs that you can attach to an object. You can use this
28+
/// to store additional information about the object (for example, cost basis)
29+
/// in a structured format.
30+
final Map<String, dynamic>? metadata;
31+
32+
/// A descriptive name shown in the Dashboard.
33+
final String? name;
34+
35+
CreateCreditGrantRequest({
36+
required this.amount,
37+
required this.applicabilityConfig,
38+
required this.category,
39+
required this.customer,
40+
this.effectiveAt,
41+
this.expiresAt,
42+
this.metadata,
43+
this.name,
44+
});
45+
46+
factory CreateCreditGrantRequest.fromJson(Map<String, dynamic> json) =>
47+
_$CreateCreditGrantRequestFromJson(json);
48+
49+
Map<String, dynamic> toJson() => _$CreateCreditGrantRequestToJson(this);
50+
}
51+
52+
/// https://docs.stripe.com/api/billing/credit-grant/create#create_billing_credit_grant-amount
53+
@JsonSerializable()
54+
class CreditGrantCreateRequestAmount {
55+
/// Specify the type of this amount. We currently only support monetary
56+
/// billing credits.
57+
final CreditGrantAmountType type;
58+
59+
/// The monetary amount.
60+
final CreditGrantAmountMonetary monetary;
61+
62+
CreditGrantCreateRequestAmount({
63+
required this.type,
64+
required this.monetary,
65+
});
66+
67+
factory CreditGrantCreateRequestAmount.fromJson(Map<String, dynamic> json) =>
68+
_$CreditGrantCreateRequestAmountFromJson(json);
69+
70+
Map<String, dynamic> toJson() => _$CreditGrantCreateRequestAmountToJson(this);
71+
}
72+
73+
/// https://docs.stripe.com/api/billing/credit-grant/create#create_billing_credit_grant-applicability_config
74+
@JsonSerializable()
75+
class CreditGrantCreateRequestApplicabilityConfig {
76+
/// Specify the scope of this applicability config.
77+
final CreditGrantCreateRequestApplicabilityConfigScope scope;
78+
79+
CreditGrantCreateRequestApplicabilityConfig({
80+
required this.scope,
81+
});
82+
83+
factory CreditGrantCreateRequestApplicabilityConfig.fromJson(
84+
Map<String, dynamic> json) =>
85+
_$CreditGrantCreateRequestApplicabilityConfigFromJson(json);
86+
87+
Map<String, dynamic> toJson() =>
88+
_$CreditGrantCreateRequestApplicabilityConfigToJson(this);
89+
}
90+
91+
/// https://docs.stripe.com/api/billing/credit-grant/create#create_billing_credit_grant-applicability_config
92+
@JsonSerializable()
93+
class CreditGrantCreateRequestApplicabilityConfigScope {
94+
/// The price type that credit grants can apply to. We currently only support
95+
/// the metered price type. Cannot be used in combination with prices.
96+
final CreditGrantApplicabilityConfigScopePriceType? priceType;
97+
98+
CreditGrantCreateRequestApplicabilityConfigScope({
99+
this.priceType,
100+
});
101+
102+
factory CreditGrantCreateRequestApplicabilityConfigScope.fromJson(
103+
Map<String, dynamic> json) =>
104+
_$CreditGrantCreateRequestApplicabilityConfigScopeFromJson(json);
105+
106+
Map<String, dynamic> toJson() =>
107+
_$CreditGrantCreateRequestApplicabilityConfigScopeToJson(this);
108+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
part of '../../../messages.dart';
2+
3+
/// https://docs.stripe.com/api/billing/credit-grant/list
4+
@JsonSerializable()
5+
class ListCreditGrantsRequest {
6+
/// Only return credit grants for this customer.
7+
final String? customer;
8+
9+
/// A cursor for use in pagination. ending_before is an object ID that defines
10+
/// your place in the list. For instance, if you make a list request and
11+
/// receive 100 objects, starting with obj_bar, your subsequent call can
12+
/// include ending_before=obj_bar in order to fetch the previous page of the
13+
/// list.
14+
final String? endingBefore;
15+
16+
/// A limit on the number of objects to be returned. Limit can range between 1
17+
/// and 100, and the default is 10.
18+
final int? limit;
19+
20+
/// A cursor for use in pagination. starting_after is an object ID that
21+
/// defines your place in the list. For instance, if you make a list request
22+
/// and receive 100 objects, ending with obj_foo, your subsequent call can
23+
/// include starting_after=obj_foo in order to fetch the next page of the
24+
/// list.
25+
final String? startingAfter;
26+
27+
ListCreditGrantsRequest({
28+
this.customer,
29+
this.endingBefore,
30+
this.limit,
31+
this.startingAfter,
32+
});
33+
34+
factory ListCreditGrantsRequest.fromJson(Map<String, dynamic> json) =>
35+
_$ListCreditGrantsRequestFromJson(json);
36+
37+
Map<String, dynamic> toJson() => _$ListCreditGrantsRequestToJson(this);
38+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
part of '../../../messages.dart';
2+
3+
/// https://docs.stripe.com/api/billing/credit-grant/update
4+
@JsonSerializable()
5+
class UpdateCreditGrantRequest {
6+
/// Unique identifier for the object.
7+
final String id;
8+
9+
/// The time when the billing credits created by this credit grant expire. If
10+
/// set to empty, the billing credits never expire.
11+
final int? expiresAt;
12+
13+
/// Set of key-value pairs you can attach to an object. You can use this to
14+
/// store additional information about the object (for example, cost basis) in
15+
/// a structured format.
16+
final Map<String, dynamic>? metadata;
17+
18+
UpdateCreditGrantRequest({
19+
required this.id,
20+
this.expiresAt,
21+
this.metadata,
22+
});
23+
24+
factory UpdateCreditGrantRequest.fromJson(Map<String, dynamic> json) =>
25+
_$UpdateCreditGrantRequestFromJson(json);
26+
27+
Map<String, dynamic> toJson() => _$UpdateCreditGrantRequestToJson(this);
28+
}

0 commit comments

Comments
 (0)