Skip to content

Commit 9013819

Browse files
Merge pull request #26 from solid-software/coupon_resource_2
Add `CouponResource`
2 parents f2820a5 + e0dc00e commit 9013819

7 files changed

Lines changed: 150 additions & 60 deletions

File tree

lib/messages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ part 'src/messages/requests/create_price.dart';
3232
part 'src/messages/requests/create_product.dart';
3333
part 'src/messages/requests/create_refund.dart';
3434
part 'src/messages/requests/create_subscription_schedule.dart';
35+
part 'src/messages/requests/created.dart';
36+
part 'src/messages/requests/list_coupons.dart';
3537
part 'src/messages/requests/list_prices.dart';
3638
part 'src/messages/requests/list_products.dart';
3739
part 'src/messages/requests/list_promotion_codes.dart';

lib/messages.g.dart

Lines changed: 51 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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+
@JsonSerializable()
4+
class CreatedRequest {
5+
/// Minimum value to filter by (exclusive).
6+
final int? gt;
7+
8+
/// Minimum value to filter by (inclusive).
9+
final int? gte;
10+
11+
/// Maximum value to filter by (exclusive).
12+
final int? lt;
13+
14+
/// Maximum value to filter by (inclusive).
15+
final int? lte;
16+
17+
CreatedRequest({
18+
this.gt,
19+
this.gte,
20+
this.lt,
21+
this.lte,
22+
});
23+
24+
factory CreatedRequest.fromJson(Map<String, dynamic> json) =>
25+
_$CreatedRequestFromJson(json);
26+
27+
Map<String, dynamic> toJson() => _$CreatedRequestToJson(this);
28+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
part of '../../../messages.dart';
2+
3+
/// https://docs.stripe.com/api/coupons/list
4+
@JsonSerializable()
5+
class ListCouponsRequest {
6+
/// A filter on the list, based on the object created field. The value can be
7+
/// a string with an integer Unix timestamp, or it can be a dictionary with a
8+
/// number of different query options.
9+
final CreatedRequest? created;
10+
11+
/// A cursor for use in pagination. ending_before is an object ID that defines
12+
/// your place in the list. For instance, if you make a list request and
13+
/// receive 100 objects, starting with obj_bar, your subsequent call can
14+
/// include ending_before=obj_bar in order to fetch the previous page of the
15+
/// list.
16+
final String? endingBefore;
17+
18+
/// A limit on the number of objects to be returned. Limit can range between
19+
/// 1 and 100, and the default is 10.
20+
final int? limit;
21+
22+
/// A cursor for use in pagination. starting_after is an object ID that
23+
/// defines your place in the list. For instance, if you make a list request
24+
/// and receive 100 objects, ending with obj_foo, your subsequent call can
25+
/// include starting_after=obj_foo in order to fetch the next page of the
26+
/// list.
27+
final String? startingAfter;
28+
29+
ListCouponsRequest({
30+
this.created,
31+
this.endingBefore,
32+
this.limit,
33+
this.startingAfter,
34+
});
35+
36+
factory ListCouponsRequest.fromJson(Map<String, dynamic> json) =>
37+
_$ListCouponsRequestFromJson(json);
38+
39+
Map<String, dynamic> toJson() => _$ListCouponsRequestToJson(this);
40+
}

lib/src/messages/requests/list_promotion_codes.dart

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ListPromotionCodesRequest {
1515
/// A filter on the list, based on the object created field. The value can be
1616
/// a string with an integer Unix timestamp, or it can be a dictionary with a
1717
/// number of different query options.
18-
final ListPromotionCodesCreatedRequest? created;
18+
final CreatedRequest? created;
1919

2020
/// Only return promotion codes that are restricted to this customer.
2121
final String? customer;
@@ -54,33 +54,3 @@ class ListPromotionCodesRequest {
5454

5555
Map<String, dynamic> toJson() => _$ListPromotionCodesRequestToJson(this);
5656
}
57-
58-
/// https://docs.stripe.com/api/promotion_codes/list#list_promotion_code-created
59-
@JsonSerializable()
60-
class ListPromotionCodesCreatedRequest {
61-
/// Minimum value to filter by (exclusive).
62-
final int? gt;
63-
64-
/// Minimum value to filter by (inclusive).
65-
final int? gte;
66-
67-
/// Maximum value to filter by (exclusive).
68-
final int? lt;
69-
70-
/// Maximum value to filter by (inclusive).
71-
final int? lte;
72-
73-
ListPromotionCodesCreatedRequest({
74-
this.gt,
75-
this.gte,
76-
this.lt,
77-
this.lte,
78-
});
79-
80-
factory ListPromotionCodesCreatedRequest.fromJson(
81-
Map<String, dynamic> json) =>
82-
_$ListPromotionCodesCreatedRequestFromJson(json);
83-
84-
Map<String, dynamic> toJson() =>
85-
_$ListPromotionCodesCreatedRequestToJson(this);
86-
}

lib/src/resources/coupon.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'dart:async';
2+
3+
import 'package:stripe/messages.dart';
4+
5+
import '../client.dart';
6+
import '_resource.dart';
7+
8+
class CouponResource extends Resource<Coupon> {
9+
static const _resourceName = 'coupons';
10+
11+
CouponResource(Client client) : super(client);
12+
13+
Future<DataList<Coupon>> list([
14+
ListCouponsRequest? request,
15+
]) async {
16+
final map = await get(_resourceName, queryParameters: request?.toJson());
17+
return DataList<Coupon>.fromJson(
18+
map,
19+
(value) => Coupon.fromJson(value as Map<String, dynamic>),
20+
);
21+
}
22+
}

lib/stripe.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'src/client.dart';
66
import 'src/resources/balance_transaction.dart';
77
import 'src/resources/charge.dart';
88
import 'src/resources/checkout_session.dart';
9+
import 'src/resources/coupon.dart';
910
import 'src/resources/customer.dart';
1011
import 'src/resources/payment_intent.dart';
1112
import 'src/resources/portal_session.dart';
@@ -75,6 +76,9 @@ class Stripe {
7576
/// https://docs.stripe.com/api/promotion_codes
7677
final PromotionCodeResource promotionCode;
7778

79+
/// https://docs.stripe.com/api/coupons
80+
final CouponResource coupon;
81+
7882
factory Stripe(String apiKey) {
7983
final client = DioClient(apiKey: apiKey);
8084
return Stripe.withClient(client);
@@ -93,5 +97,6 @@ class Stripe {
9397
subscriptionSchedule = SubscriptionScheduleResource(client),
9498
charge = ChargeResource(client),
9599
balanceTransaction = BalanceTransactionResource(client),
96-
promotionCode = PromotionCodeResource(client);
100+
promotionCode = PromotionCodeResource(client),
101+
coupon = CouponResource(client);
97102
}

0 commit comments

Comments
 (0)