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.
Loading status checks…
Merge pull request #20 from solid-software/resuource-subscription_sch…
…edule add subscription schedule resource
Showing
8 changed files
with
422 additions
and
27 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
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
part of '../../messages.dart'; | ||
|
||
abstract class Message { | ||
const Message(); | ||
|
||
Map<String, dynamic> toJson(); | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/src/messages/requests/create_subscription_schedule.dart
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,18 @@ | ||
part of '../../../messages.dart'; | ||
|
||
@JsonSerializable() | ||
class CreateSubscriptionScheduleRequest extends Message { | ||
final String? fromSubscription; | ||
|
||
const CreateSubscriptionScheduleRequest({ | ||
this.fromSubscription, | ||
}); | ||
|
||
factory CreateSubscriptionScheduleRequest.fromJson( | ||
Map<String, dynamic> json) => | ||
_$CreateSubscriptionScheduleRequestFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => | ||
_$CreateSubscriptionScheduleRequestToJson(this); | ||
} |
65 changes: 65 additions & 0 deletions
65
lib/src/messages/requests/update_subscription_schedule.dart
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,65 @@ | ||
part of '../../../messages.dart'; | ||
|
||
@JsonSerializable() | ||
class UpdateSubscriptionScheduleRequest extends Message { | ||
final List<UpdateSubscriptionSchedulePhase> phases; | ||
|
||
const UpdateSubscriptionScheduleRequest({ | ||
required this.phases, | ||
}); | ||
|
||
factory UpdateSubscriptionScheduleRequest.fromJson( | ||
Map<String, dynamic> json) => | ||
_$UpdateSubscriptionScheduleRequestFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => | ||
_$UpdateSubscriptionScheduleRequestToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class UpdateSubscriptionSchedulePhase extends Message { | ||
final String id; | ||
|
||
@TimestampConverter() | ||
final DateTime? startDate; | ||
|
||
@TimestampConverter() | ||
final DateTime? endDate; | ||
|
||
final List<UpdateSubscriptionSchedulePhaseItem> items; | ||
|
||
const UpdateSubscriptionSchedulePhase({ | ||
required this.id, | ||
this.startDate, | ||
this.endDate, | ||
required this.items, | ||
}); | ||
|
||
factory UpdateSubscriptionSchedulePhase.fromJson(Map<String, dynamic> json) => | ||
_$UpdateSubscriptionSchedulePhaseFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => | ||
_$UpdateSubscriptionSchedulePhaseToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class UpdateSubscriptionSchedulePhaseItem extends Message { | ||
final String price; | ||
|
||
final int quantity; | ||
|
||
const UpdateSubscriptionSchedulePhaseItem({ | ||
required this.price, | ||
required this.quantity, | ||
}); | ||
|
||
factory UpdateSubscriptionSchedulePhaseItem.fromJson( | ||
Map<String, dynamic> json) => | ||
_$UpdateSubscriptionSchedulePhaseItemFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => | ||
_$UpdateSubscriptionSchedulePhaseItemToJson(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,77 @@ | ||
part of '../../messages.dart'; | ||
|
||
enum _SubscriptionScheduleObject { | ||
@JsonValue('subscription_schedule') | ||
subscriptionSchedule, | ||
} | ||
|
||
@JsonSerializable() | ||
class SubscriptionSchedule extends Message { | ||
final _SubscriptionScheduleObject object; | ||
|
||
final String id; | ||
|
||
final String? customer; | ||
|
||
final Map<String, dynamic>? metadata; | ||
|
||
final List<SubscriptionSchedulePhase> phases; | ||
|
||
const SubscriptionSchedule({ | ||
required this.object, | ||
required this.id, | ||
this.customer, | ||
this.metadata, | ||
required this.phases, | ||
}); | ||
|
||
factory SubscriptionSchedule.fromJson(Map<String, dynamic> json) => | ||
_$SubscriptionScheduleFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$SubscriptionScheduleToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class SubscriptionSchedulePhase extends Message { | ||
final String id; | ||
|
||
@TimestampConverter() | ||
final DateTime? startDate; | ||
|
||
@TimestampConverter() | ||
final DateTime? endDate; | ||
|
||
final List<SubscriptionSchedulePhaseItem> items; | ||
|
||
const SubscriptionSchedulePhase({ | ||
required this.id, | ||
this.startDate, | ||
this.endDate, | ||
required this.items, | ||
}); | ||
|
||
factory SubscriptionSchedulePhase.fromJson(Map<String, dynamic> json) => | ||
_$SubscriptionSchedulePhaseFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$SubscriptionSchedulePhaseToJson(this); | ||
} | ||
|
||
@JsonSerializable() | ||
class SubscriptionSchedulePhaseItem extends Message { | ||
final String price; | ||
|
||
final int quantity; | ||
|
||
const SubscriptionSchedulePhaseItem({ | ||
required this.price, | ||
required this.quantity, | ||
}); | ||
|
||
factory SubscriptionSchedulePhaseItem.fromJson(Map<String, dynamic> json) => | ||
_$SubscriptionSchedulePhaseItemFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$SubscriptionSchedulePhaseItemToJson(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,49 @@ | ||
import '../../messages.dart'; | ||
import '../client.dart'; | ||
import '_resource.dart'; | ||
|
||
class SubscriptionScheduleResource extends Resource { | ||
SubscriptionScheduleResource(Client client) : super(client); | ||
|
||
/// https://stripe.com/docs/api/subscription_schedules/retrieve | ||
Future<SubscriptionSchedule> retrieve(String id) async { | ||
final response = await get('subscription_schedules/$id'); | ||
|
||
return SubscriptionSchedule.fromJson(response); | ||
} | ||
|
||
/// https://stripe.com/docs/api/subscription_schedules/list | ||
Future<DataList<SubscriptionSchedule>> list() async { | ||
final map = await get('subscription_schedules'); | ||
|
||
return DataList<SubscriptionSchedule>.fromJson( | ||
map, | ||
(value) => SubscriptionSchedule.fromJson(value as Map<String, dynamic>), | ||
); | ||
} | ||
|
||
/// https://stripe.com/docs/api/subscription_schedules/create | ||
Future<SubscriptionSchedule> create( | ||
CreateSubscriptionScheduleRequest request, | ||
) async { | ||
final response = await post( | ||
'subscription_schedules', | ||
data: request.toJson(), | ||
); | ||
|
||
return SubscriptionSchedule.fromJson(response); | ||
} | ||
|
||
/// https://stripe.com/docs/api/subscription_schedules/update | ||
Future<SubscriptionSchedule> update( | ||
String id, | ||
UpdateSubscriptionScheduleRequest request, | ||
) async { | ||
final response = await post( | ||
'subscription_schedules/$id', | ||
data: request.toJson(), | ||
); | ||
|
||
return SubscriptionSchedule.fromJson(response); | ||
} | ||
} |
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