forked from enyo/stripe-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from solid-software/coupon_resource_2
Add `CouponResource`
- Loading branch information
Showing
7 changed files
with
150 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
part of '../../../messages.dart'; | ||
|
||
@JsonSerializable() | ||
class CreatedRequest { | ||
/// Minimum value to filter by (exclusive). | ||
final int? gt; | ||
|
||
/// Minimum value to filter by (inclusive). | ||
final int? gte; | ||
|
||
/// Maximum value to filter by (exclusive). | ||
final int? lt; | ||
|
||
/// Maximum value to filter by (inclusive). | ||
final int? lte; | ||
|
||
CreatedRequest({ | ||
this.gt, | ||
this.gte, | ||
this.lt, | ||
this.lte, | ||
}); | ||
|
||
factory CreatedRequest.fromJson(Map<String, dynamic> json) => | ||
_$CreatedRequestFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$CreatedRequestToJson(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
part of '../../../messages.dart'; | ||
|
||
/// https://docs.stripe.com/api/coupons/list | ||
@JsonSerializable() | ||
class ListCouponsRequest { | ||
/// A filter on the list, based on the object created field. The value can be | ||
/// a string with an integer Unix timestamp, or it can be a dictionary with a | ||
/// number of different query options. | ||
final CreatedRequest? created; | ||
|
||
/// 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; | ||
|
||
ListCouponsRequest({ | ||
this.created, | ||
this.endingBefore, | ||
this.limit, | ||
this.startingAfter, | ||
}); | ||
|
||
factory ListCouponsRequest.fromJson(Map<String, dynamic> json) => | ||
_$ListCouponsRequestFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ListCouponsRequestToJson(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:stripe/messages.dart'; | ||
|
||
import '../client.dart'; | ||
import '_resource.dart'; | ||
|
||
class CouponResource extends Resource<Coupon> { | ||
static const _resourceName = 'coupons'; | ||
|
||
CouponResource(Client client) : super(client); | ||
|
||
Future<DataList<Coupon>> list([ | ||
ListCouponsRequest? request, | ||
]) async { | ||
final map = await get(_resourceName, queryParameters: request?.toJson()); | ||
return DataList<Coupon>.fromJson( | ||
map, | ||
(value) => Coupon.fromJson(value as Map<String, dynamic>), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters