diff --git a/lib/messages.dart b/lib/messages.dart index a8eb3a1..d13795a 100644 --- a/lib/messages.dart +++ b/lib/messages.dart @@ -13,6 +13,7 @@ part 'src/messages/billing_details.dart'; part 'src/messages/charge.dart'; part 'src/messages/checkout_session.dart'; part 'src/messages/coupon.dart'; +part 'src/messages/credit_grant.dart'; part 'src/messages/customer.dart'; part 'src/messages/data_list.dart'; part 'src/messages/discount.dart'; @@ -28,6 +29,7 @@ part 'src/messages/promotion_code.dart'; part 'src/messages/refund.dart'; part 'src/messages/requests/confirm_payment_intent.dart'; part 'src/messages/requests/create_checkout_session.dart'; +part 'src/messages/requests/create_credit_grant.dart'; part 'src/messages/requests/create_customer.dart'; part 'src/messages/requests/create_discount.dart'; part 'src/messages/requests/create_invoice_preview_request.dart'; @@ -40,6 +42,7 @@ part 'src/messages/requests/create_subscription.dart'; part 'src/messages/requests/create_subscription_schedule.dart'; part 'src/messages/requests/created.dart'; part 'src/messages/requests/list_coupons.dart'; +part 'src/messages/requests/list_credit_grants.dart'; part 'src/messages/requests/list_prices.dart'; part 'src/messages/requests/list_products.dart'; part 'src/messages/requests/list_promotion_codes.dart'; @@ -47,6 +50,7 @@ part 'src/messages/requests/list_subscription_items.dart'; part 'src/messages/requests/list_subscription_schedules.dart'; part 'src/messages/requests/list_subscriptions.dart'; part 'src/messages/requests/subscription_payment_settings.dart'; +part 'src/messages/requests/update_credit_grant.dart'; part 'src/messages/requests/update_customer.dart'; part 'src/messages/requests/update_payment_intent.dart'; part 'src/messages/requests/update_subscription.dart'; diff --git a/lib/messages.g.dart b/lib/messages.g.dart index 832c635..9634780 100644 --- a/lib/messages.g.dart +++ b/lib/messages.g.dart @@ -348,6 +348,144 @@ const _$CouponDurationEnumMap = { CouponDuration.repeating: 'repeating', }; +CreditGrant _$CreditGrantFromJson(Map json) => CreditGrant( + object: $enumDecode(_$_CreditGrantObjectEnumMap, json['object']), + id: json['id'] as String, + amount: + CreditGrantAmount.fromJson(json['amount'] as Map), + applicabilityConfig: CreditGrantApplicabilityConfig.fromJson( + json['applicability_config'] as Map), + category: $enumDecode(_$CreditGrantCategoryEnumMap, json['category']), + created: (json['created'] as num).toInt(), + customer: json['customer'] as String, + livemode: json['livemode'] as bool, + updated: (json['updated'] as num).toInt(), + effectiveAt: (json['effective_at'] as num?)?.toInt(), + expiresAt: (json['expires_at'] as num?)?.toInt(), + metadata: json['metadata'] as Map?, + name: json['name'] as String?, + voidedAt: (json['voided_at'] as num?)?.toInt(), + ); + +Map _$CreditGrantToJson(CreditGrant instance) { + final val = { + 'object': _$_CreditGrantObjectEnumMap[instance.object]!, + 'id': instance.id, + 'amount': instance.amount.toJson(), + 'applicability_config': instance.applicabilityConfig.toJson(), + 'category': _$CreditGrantCategoryEnumMap[instance.category]!, + 'created': instance.created, + 'customer': instance.customer, + 'livemode': instance.livemode, + 'updated': instance.updated, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('effective_at', instance.effectiveAt); + writeNotNull('expires_at', instance.expiresAt); + writeNotNull('metadata', instance.metadata); + writeNotNull('name', instance.name); + writeNotNull('voided_at', instance.voidedAt); + return val; +} + +const _$_CreditGrantObjectEnumMap = { + _CreditGrantObject.billingCreditGrant: 'billing.credit_grant', +}; + +const _$CreditGrantCategoryEnumMap = { + CreditGrantCategory.paid: 'paid', + CreditGrantCategory.promotional: 'promotional', +}; + +CreditGrantAmount _$CreditGrantAmountFromJson(Map json) => + CreditGrantAmount( + type: $enumDecode(_$CreditGrantAmountTypeEnumMap, json['type']), + monetary: json['monetary'] == null + ? null + : CreditGrantAmountMonetary.fromJson( + json['monetary'] as Map), + ); + +Map _$CreditGrantAmountToJson(CreditGrantAmount instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('monetary', instance.monetary?.toJson()); + val['type'] = _$CreditGrantAmountTypeEnumMap[instance.type]!; + return val; +} + +const _$CreditGrantAmountTypeEnumMap = { + CreditGrantAmountType.monetary: 'monetary', +}; + +CreditGrantAmountMonetary _$CreditGrantAmountMonetaryFromJson( + Map json) => + CreditGrantAmountMonetary( + currency: json['currency'] as String, + value: (json['value'] as num).toInt(), + ); + +Map _$CreditGrantAmountMonetaryToJson( + CreditGrantAmountMonetary instance) => + { + 'currency': instance.currency, + 'value': instance.value, + }; + +CreditGrantApplicabilityConfig _$CreditGrantApplicabilityConfigFromJson( + Map json) => + CreditGrantApplicabilityConfig( + scope: CreditGrantApplicabilityConfigScope.fromJson( + json['scope'] as Map), + ); + +Map _$CreditGrantApplicabilityConfigToJson( + CreditGrantApplicabilityConfig instance) => + { + 'scope': instance.scope.toJson(), + }; + +CreditGrantApplicabilityConfigScope + _$CreditGrantApplicabilityConfigScopeFromJson(Map json) => + CreditGrantApplicabilityConfigScope( + priceType: $enumDecodeNullable( + _$CreditGrantApplicabilityConfigScopePriceTypeEnumMap, + json['price_type']), + ); + +Map _$CreditGrantApplicabilityConfigScopeToJson( + CreditGrantApplicabilityConfigScope instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'price_type', + _$CreditGrantApplicabilityConfigScopePriceTypeEnumMap[ + instance.priceType]); + return val; +} + +const _$CreditGrantApplicabilityConfigScopePriceTypeEnumMap = { + CreditGrantApplicabilityConfigScopePriceType.metered: 'metered', +}; + Customer _$CustomerFromJson(Map json) => Customer( object: $enumDecode(_$_CustomerObjectEnumMap, json['object']), id: json['id'] as String, @@ -1528,6 +1666,98 @@ Map _$SubscriptionDataToJson(SubscriptionData instance) { return val; } +CreateCreditGrantRequest _$CreateCreditGrantRequestFromJson( + Map json) => + CreateCreditGrantRequest( + amount: CreateCreditGrantRequestAmount.fromJson( + json['amount'] as Map), + applicabilityConfig: CreateCreditGrantRequestApplicabilityConfig.fromJson( + json['applicability_config'] as Map), + category: $enumDecode(_$CreditGrantCategoryEnumMap, json['category']), + customer: json['customer'] as String, + effectiveAt: (json['effective_at'] as num?)?.toInt(), + expiresAt: (json['expires_at'] as num?)?.toInt(), + metadata: json['metadata'] as Map?, + name: json['name'] as String?, + ); + +Map _$CreateCreditGrantRequestToJson( + CreateCreditGrantRequest instance) { + final val = { + 'amount': instance.amount.toJson(), + 'applicability_config': instance.applicabilityConfig.toJson(), + 'category': _$CreditGrantCategoryEnumMap[instance.category]!, + 'customer': instance.customer, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('effective_at', instance.effectiveAt); + writeNotNull('expires_at', instance.expiresAt); + writeNotNull('metadata', instance.metadata); + writeNotNull('name', instance.name); + return val; +} + +CreateCreditGrantRequestAmount _$CreateCreditGrantRequestAmountFromJson( + Map json) => + CreateCreditGrantRequestAmount( + type: $enumDecode(_$CreditGrantAmountTypeEnumMap, json['type']), + monetary: CreditGrantAmountMonetary.fromJson( + json['monetary'] as Map), + ); + +Map _$CreateCreditGrantRequestAmountToJson( + CreateCreditGrantRequestAmount instance) => + { + 'type': _$CreditGrantAmountTypeEnumMap[instance.type]!, + 'monetary': instance.monetary.toJson(), + }; + +CreateCreditGrantRequestApplicabilityConfig + _$CreateCreditGrantRequestApplicabilityConfigFromJson( + Map json) => + CreateCreditGrantRequestApplicabilityConfig( + scope: CreateCreditGrantRequestApplicabilityConfigScope.fromJson( + json['scope'] as Map), + ); + +Map _$CreateCreditGrantRequestApplicabilityConfigToJson( + CreateCreditGrantRequestApplicabilityConfig instance) => + { + 'scope': instance.scope.toJson(), + }; + +CreateCreditGrantRequestApplicabilityConfigScope + _$CreateCreditGrantRequestApplicabilityConfigScopeFromJson( + Map json) => + CreateCreditGrantRequestApplicabilityConfigScope( + priceType: $enumDecodeNullable( + _$CreditGrantApplicabilityConfigScopePriceTypeEnumMap, + json['price_type']), + ); + +Map _$CreateCreditGrantRequestApplicabilityConfigScopeToJson( + CreateCreditGrantRequestApplicabilityConfigScope instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull( + 'price_type', + _$CreditGrantApplicabilityConfigScopePriceTypeEnumMap[ + instance.priceType]); + return val; +} + CreateCustomerRequest _$CreateCustomerRequestFromJson( Map json) => CreateCustomerRequest( @@ -2234,6 +2464,32 @@ Map _$ListCouponsRequestToJson(ListCouponsRequest instance) { return val; } +ListCreditGrantsRequest _$ListCreditGrantsRequestFromJson( + Map json) => + ListCreditGrantsRequest( + customer: json['customer'] as String?, + endingBefore: json['ending_before'] as String?, + limit: (json['limit'] as num?)?.toInt(), + startingAfter: json['starting_after'] as String?, + ); + +Map _$ListCreditGrantsRequestToJson( + ListCreditGrantsRequest instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('customer', instance.customer); + writeNotNull('ending_before', instance.endingBefore); + writeNotNull('limit', instance.limit); + writeNotNull('starting_after', instance.startingAfter); + return val; +} + ListPricesRequest _$ListPricesRequestFromJson(Map json) => ListPricesRequest( active: json['active'] as bool?, @@ -2428,6 +2684,31 @@ Map _$SubscriptionPaymentSettingsRequestToJson( return val; } +UpdateCreditGrantRequest _$UpdateCreditGrantRequestFromJson( + Map json) => + UpdateCreditGrantRequest( + id: json['id'] as String, + expiresAt: (json['expires_at'] as num?)?.toInt(), + metadata: json['metadata'] as Map?, + ); + +Map _$UpdateCreditGrantRequestToJson( + UpdateCreditGrantRequest instance) { + final val = { + 'id': instance.id, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('expires_at', instance.expiresAt); + writeNotNull('metadata', instance.metadata); + return val; +} + UpdateCustomerRequest _$UpdateCustomerRequestFromJson( Map json) => UpdateCustomerRequest( diff --git a/lib/src/messages/credit_grant.dart b/lib/src/messages/credit_grant.dart new file mode 100644 index 0000000..0621eca --- /dev/null +++ b/lib/src/messages/credit_grant.dart @@ -0,0 +1,184 @@ +part of '../../messages.dart'; + +enum _CreditGrantObject { + @JsonValue('billing.credit_grant') + billingCreditGrant, +} + +/// https://docs.stripe.com/api/billing/credit-grant/object +@JsonSerializable() +class CreditGrant extends Message { + final _CreditGrantObject object; + + /// Unique identifier for the object. + final String id; + + /// Amount of this credit grant. + final CreditGrantAmount amount; + + /// Configuration specifying what this credit grant applies to. We currently + /// only support metered prices that have a Billing Meter attached to them. + final CreditGrantApplicabilityConfig applicabilityConfig; + + /// he category of this credit grant. This is for tracking purposes and isn’t + /// displayed to the customer. + final CreditGrantCategory category; + + /// Time at which the object was created. Measured in seconds since the Unix + /// epoch. + final int created; + + /// ID of the customer receiving the billing credits. + final String customer; + + /// Has the value true if the object exists in live mode or the value false + /// if the object exists in test mode. + final bool livemode; + + /// Time at which the object was last updated. Measured in seconds since the + /// Unix epoch. + final int updated; + + /// The time when the billing credits become effective-when they’re eligible + /// for use. + final int? effectiveAt; + + /// The time when the billing credits expire. If not present, the billing + /// credits don’t expire. + final int? expiresAt; + + /// Set of key-value pairs that you can attach to an object. This can be + /// useful for storing additional information about the object in a structured + /// format. + final Map? metadata; + + /// A descriptive name shown in dashboard. + final String? name; + + /// The time when this credit grant was voided. If not present, the credit + /// grant hasn’t been voided. + final int? voidedAt; + + CreditGrant({ + required this.object, + required this.id, + required this.amount, + required this.applicabilityConfig, + required this.category, + required this.created, + required this.customer, + required this.livemode, + required this.updated, + this.effectiveAt, + this.expiresAt, + this.metadata, + this.name, + this.voidedAt, + }); + + factory CreditGrant.fromJson(Map json) => + _$CreditGrantFromJson(json); + + @override + Map toJson() => _$CreditGrantToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-amount +@JsonSerializable() +class CreditGrantAmount { + /// The monetary amount. + final CreditGrantAmountMonetary? monetary; + + /// The type of this amount. We currently only support monetary billing + /// credits. + final CreditGrantAmountType type; + + CreditGrantAmount({ + + required this.type, + this.monetary, + }); + + factory CreditGrantAmount.fromJson(Map json) => + _$CreditGrantAmountFromJson(json); + + Map toJson() => _$CreditGrantAmountToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-amount-monetary +@JsonSerializable() +class CreditGrantAmountMonetary { + /// Three-letter ISO currency code, in lowercase. Must be a supported + /// currency. + final String currency; + + /// A positive integer representing the amount. + final int value; + + CreditGrantAmountMonetary({ + required this.currency, + required this.value, + }); + + factory CreditGrantAmountMonetary.fromJson(Map json) => + _$CreditGrantAmountMonetaryFromJson(json); + + Map toJson() => _$CreditGrantAmountMonetaryToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-amount-type +enum CreditGrantAmountType { + /// The amount is a monetary amount. + monetary, +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-applicability_config +@JsonSerializable() +class CreditGrantApplicabilityConfig { + /// Specify the scope of this applicability config. + final CreditGrantApplicabilityConfigScope scope; + + CreditGrantApplicabilityConfig({ + required this.scope, + }); + + factory CreditGrantApplicabilityConfig.fromJson(Map json) => + _$CreditGrantApplicabilityConfigFromJson(json); + + Map toJson() => _$CreditGrantApplicabilityConfigToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-applicability_config-scope +@JsonSerializable() +class CreditGrantApplicabilityConfigScope { + /// The price type that credit grants can apply to. We currently only support + /// the metered price type. This refers to prices that have a Billing Meter + /// attached to them. Cannot be used in combination with prices. + final CreditGrantApplicabilityConfigScopePriceType? priceType; + + CreditGrantApplicabilityConfigScope({ + this.priceType, + }); + + factory CreditGrantApplicabilityConfigScope.fromJson( + Map json) => + _$CreditGrantApplicabilityConfigScopeFromJson(json); + + Map toJson() => + _$CreditGrantApplicabilityConfigScopeToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-applicability_config-scope-price_type +enum CreditGrantApplicabilityConfigScopePriceType { + /// Credit grants being created can only apply to metered prices. + metered, +} + +/// https://docs.stripe.com/api/billing/credit-grant/object#billing_credit_grant_object-category +enum CreditGrantCategory { + /// The credit grant was purchased by the customer for some amount. + paid, + + /// The credit grant was given to the customer for free. + promotional, +} diff --git a/lib/src/messages/requests/create_credit_grant.dart b/lib/src/messages/requests/create_credit_grant.dart new file mode 100644 index 0000000..e5dee20 --- /dev/null +++ b/lib/src/messages/requests/create_credit_grant.dart @@ -0,0 +1,108 @@ +part of '../../../messages.dart'; + +/// https://docs.stripe.com/api/billing/credit-grant/create +@JsonSerializable() +class CreateCreditGrantRequest { + /// Amount of this credit grant. + final CreateCreditGrantRequestAmount amount; + + /// Configuration specifying what this credit grant applies to. We currently + /// only support metered prices that have a Billing Meter attached to them. + final CreateCreditGrantRequestApplicabilityConfig applicabilityConfig; + + /// The category of this credit grant. + final CreditGrantCategory category; + + /// ID of the customer to receive the billing credits. + final String customer; + + /// The time when the billing credits become effective-when they’re eligible + /// for use. It defaults to the current timestamp if not specified. + final int? effectiveAt; + + /// The time when the billing credits expire. If not specified, the billing + /// credits don’t expire. + final int? expiresAt; + + /// Set of key-value pairs that you can attach to an object. You can use this + /// to store additional information about the object (for example, cost basis) + /// in a structured format. + final Map? metadata; + + /// A descriptive name shown in the Dashboard. + final String? name; + + CreateCreditGrantRequest({ + required this.amount, + required this.applicabilityConfig, + required this.category, + required this.customer, + this.effectiveAt, + this.expiresAt, + this.metadata, + this.name, + }); + + factory CreateCreditGrantRequest.fromJson(Map json) => + _$CreateCreditGrantRequestFromJson(json); + + Map toJson() => _$CreateCreditGrantRequestToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/create#create_billing_credit_grant-amount +@JsonSerializable() +class CreateCreditGrantRequestAmount { + /// Specify the type of this amount. We currently only support monetary + /// billing credits. + final CreditGrantAmountType type; + + /// The monetary amount. + final CreditGrantAmountMonetary monetary; + + CreateCreditGrantRequestAmount({ + required this.type, + required this.monetary, + }); + + factory CreateCreditGrantRequestAmount.fromJson(Map json) => + _$CreateCreditGrantRequestAmountFromJson(json); + + Map toJson() => _$CreateCreditGrantRequestAmountToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/create#create_billing_credit_grant-applicability_config +@JsonSerializable() +class CreateCreditGrantRequestApplicabilityConfig { + /// Specify the scope of this applicability config. + final CreateCreditGrantRequestApplicabilityConfigScope scope; + + CreateCreditGrantRequestApplicabilityConfig({ + required this.scope, + }); + + factory CreateCreditGrantRequestApplicabilityConfig.fromJson( + Map json) => + _$CreateCreditGrantRequestApplicabilityConfigFromJson(json); + + Map toJson() => + _$CreateCreditGrantRequestApplicabilityConfigToJson(this); +} + +/// https://docs.stripe.com/api/billing/credit-grant/create#create_billing_credit_grant-applicability_config +@JsonSerializable() +class CreateCreditGrantRequestApplicabilityConfigScope { + /// The price type that credit grants can apply to. We currently only support + /// the metered price type. Cannot be used in combination with prices. + final CreditGrantApplicabilityConfigScopePriceType? priceType; + + CreateCreditGrantRequestApplicabilityConfigScope({ + this.priceType, + }); + + factory CreateCreditGrantRequestApplicabilityConfigScope.fromJson( + Map json) => + _$CreateCreditGrantRequestApplicabilityConfigScopeFromJson(json); + + Map toJson() => + _$CreateCreditGrantRequestApplicabilityConfigScopeToJson(this); +} diff --git a/lib/src/messages/requests/list_credit_grants.dart b/lib/src/messages/requests/list_credit_grants.dart new file mode 100644 index 0000000..7799b40 --- /dev/null +++ b/lib/src/messages/requests/list_credit_grants.dart @@ -0,0 +1,38 @@ +part of '../../../messages.dart'; + +/// https://docs.stripe.com/api/billing/credit-grant/list +@JsonSerializable() +class ListCreditGrantsRequest { + /// Only return credit grants for this customer. + final String? customer; + + /// A cursor for use in pagination. ending_before is an object ID that defines + /// your place in the list. For instance, if you make a list request and + /// receive 100 objects, starting with obj_bar, your subsequent call can + /// include ending_before=obj_bar in order to fetch the previous page of the + /// list. + final String? endingBefore; + + /// A limit on the number of objects to be returned. Limit can range between 1 + /// and 100, and the default is 10. + final int? limit; + + /// A cursor for use in pagination. starting_after is an object ID that + /// defines your place in the list. For instance, if you make a list request + /// and receive 100 objects, ending with obj_foo, your subsequent call can + /// include starting_after=obj_foo in order to fetch the next page of the + /// list. + final String? startingAfter; + + ListCreditGrantsRequest({ + this.customer, + this.endingBefore, + this.limit, + this.startingAfter, + }); + + factory ListCreditGrantsRequest.fromJson(Map json) => + _$ListCreditGrantsRequestFromJson(json); + + Map toJson() => _$ListCreditGrantsRequestToJson(this); +} diff --git a/lib/src/messages/requests/update_credit_grant.dart b/lib/src/messages/requests/update_credit_grant.dart new file mode 100644 index 0000000..9039503 --- /dev/null +++ b/lib/src/messages/requests/update_credit_grant.dart @@ -0,0 +1,28 @@ +part of '../../../messages.dart'; + +/// https://docs.stripe.com/api/billing/credit-grant/update +@JsonSerializable() +class UpdateCreditGrantRequest { + /// Unique identifier for the object. + final String id; + + /// The time when the billing credits created by this credit grant expire. If + /// set to empty, the billing credits never expire. + final int? expiresAt; + + /// Set of key-value pairs you can attach to an object. You can use this to + /// store additional information about the object (for example, cost basis) in + /// a structured format. + final Map? metadata; + + UpdateCreditGrantRequest({ + required this.id, + this.expiresAt, + this.metadata, + }); + + factory UpdateCreditGrantRequest.fromJson(Map json) => + _$UpdateCreditGrantRequestFromJson(json); + + Map toJson() => _$UpdateCreditGrantRequestToJson(this); +} diff --git a/lib/src/resources/credit_grant.dart b/lib/src/resources/credit_grant.dart new file mode 100644 index 0000000..06c24be --- /dev/null +++ b/lib/src/resources/credit_grant.dart @@ -0,0 +1,57 @@ +import 'package:stripe/messages.dart'; +import 'package:stripe/src/client.dart'; + +import '_resource.dart'; + +/// https://docs.stripe.com/api/billing/credit-grant +class CreditGrantResource extends Resource { + static const _resourceName = 'billing/credit_grants'; + + CreditGrantResource(Client client) : super(client); + + /// https://docs.stripe.com/api/billing/credit-grant/create + Future create(CreateCreditGrantRequest request) async { + final map = await post(_resourceName, data: request.toJson()); + + return CreditGrant.fromJson(map); + } + + /// https://docs.stripe.com/api/billing/credit-grant/update + Future update(UpdateCreditGrantRequest request) async { + final map = + await post('$_resourceName/${request.id}', data: request.toJson()); + + return CreditGrant.fromJson(map); + } + + /// https://docs.stripe.com/api/billing/credit-grant/retrieve + Future retrieve(String creditGrantId) async { + final map = await get('$_resourceName/$creditGrantId'); + + return CreditGrant.fromJson(map); + } + + /// https://docs.stripe.com/api/billing/credit-grant/list + Future> list([ListCreditGrantsRequest? request]) async { + final map = await get(_resourceName, queryParameters: request?.toJson()); + + return DataList.fromJson( + map, + (value) => CreditGrant.fromJson(value as Map), + ); + } + + /// https://docs.stripe.com/api/billing/credit-grant/expire + Future expire(String creditGrantId) async { + final map = await post('$_resourceName/$creditGrantId/expire'); + + return CreditGrant.fromJson(map); + } + + /// https://docs.stripe.com/api/billing/credit-grant/void + Future voidCreditGrant(String creditGrantId) async { + final map = await post('$_resourceName/$creditGrantId/void'); + + return CreditGrant.fromJson(map); + } +} diff --git a/lib/stripe.dart b/lib/stripe.dart index 9d4e620..b27133f 100644 --- a/lib/stripe.dart +++ b/lib/stripe.dart @@ -7,6 +7,7 @@ import 'src/resources/balance_transaction.dart'; import 'src/resources/charge.dart'; import 'src/resources/checkout_session.dart'; import 'src/resources/coupon.dart'; +import 'src/resources/credit_grant.dart'; import 'src/resources/customer.dart'; import 'src/resources/invoice.dart'; import 'src/resources/payment_intent.dart'; @@ -83,6 +84,9 @@ class Stripe { /// https://docs.stripe.com/api/invoices final InvoiceResource invoice; + /// https://docs.stripe.com/api/billing/credit-grant + final CreditGrantResource creditGrant; + factory Stripe(String apiKey) { final client = DioClient(apiKey: apiKey); return Stripe.withClient(client); @@ -103,5 +107,6 @@ class Stripe { balanceTransaction = BalanceTransactionResource(client), promotionCode = PromotionCodeResource(client), coupon = CouponResource(client), - invoice = InvoiceResource(client); + invoice = InvoiceResource(client), + creditGrant = CreditGrantResource(client); }