Skip to content

Commit

Permalink
Merge pull request #21 from solid-software/add-list-params-to-subscri…
Browse files Browse the repository at this point in the history
…ption_schedule

Add list params to subscription schedule, fix phases
  • Loading branch information
yurii-prykhodko-solid authored May 28, 2024
2 parents ba88f92 + 9c3975f commit 7ae50a5
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 16 deletions.
1 change: 1 addition & 0 deletions lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ part 'src/messages/requests/list_prices.dart';
part 'src/messages/requests/list_products.dart';
part 'src/messages/requests/list_subscription_items.dart';
part 'src/messages/requests/list_subscriptions.dart';
part 'src/messages/requests/list_subscription_schedules.dart';
part 'src/messages/requests/update_customer.dart';
part 'src/messages/requests/update_subscription.dart';
part 'src/messages/requests/update_subscription_item.dart';
Expand Down
44 changes: 36 additions & 8 deletions lib/messages.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions lib/src/messages/requests/list_subscription_schedules.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
part of '../../../messages.dart';

@JsonSerializable()
class ListSubscriptionSchedulesRequest extends Message {
final String? customer;

final int? limit;

const ListSubscriptionSchedulesRequest({
this.customer,
this.limit,
});

factory ListSubscriptionSchedulesRequest.fromJson(
Map<String, dynamic> json) =>
_$ListSubscriptionSchedulesRequestFromJson(json);

@override
Map<String, dynamic> toJson() =>
_$ListSubscriptionSchedulesRequestToJson(this);
}
3 changes: 0 additions & 3 deletions lib/src/messages/requests/update_subscription_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class UpdateSubscriptionScheduleRequest extends Message {

@JsonSerializable()
class UpdateSubscriptionSchedulePhase extends Message {
final String id;

@TimestampConverter()
final DateTime? startDate;

Expand All @@ -30,7 +28,6 @@ class UpdateSubscriptionSchedulePhase extends Message {
final List<UpdateSubscriptionSchedulePhaseItem> items;

const UpdateSubscriptionSchedulePhase({
required this.id,
this.startDate,
this.endDate,
required this.items,
Expand Down
22 changes: 19 additions & 3 deletions lib/src/messages/subscription_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ enum _SubscriptionScheduleObject {
subscriptionSchedule,
}

enum SubscriptionScheduleStatus {
@JsonValue('not_started')
notStarted,
@JsonValue('active')
active,
@JsonValue('completed')
completed,
@JsonValue('released')
released,
@JsonValue('canceled')
canceled,
}

@JsonSerializable()
class SubscriptionSchedule extends Message {
final _SubscriptionScheduleObject object;
Expand All @@ -17,12 +30,18 @@ class SubscriptionSchedule extends Message {

final List<SubscriptionSchedulePhase> phases;

final SubscriptionScheduleStatus status;

final String? subscription;

const SubscriptionSchedule({
required this.object,
required this.id,
this.customer,
this.metadata,
required this.phases,
required this.status,
this.subscription,
});

factory SubscriptionSchedule.fromJson(Map<String, dynamic> json) =>
Expand All @@ -34,8 +53,6 @@ class SubscriptionSchedule extends Message {

@JsonSerializable()
class SubscriptionSchedulePhase extends Message {
final String id;

@TimestampConverter()
final DateTime? startDate;

Expand All @@ -45,7 +62,6 @@ class SubscriptionSchedulePhase extends Message {
final List<SubscriptionSchedulePhaseItem> items;

const SubscriptionSchedulePhase({
required this.id,
this.startDate,
this.endDate,
required this.items,
Expand Down
9 changes: 7 additions & 2 deletions lib/src/resources/subscription_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ class SubscriptionScheduleResource extends Resource {
}

/// https://stripe.com/docs/api/subscription_schedules/list
Future<DataList<SubscriptionSchedule>> list() async {
final map = await get('subscription_schedules');
Future<DataList<SubscriptionSchedule>> list([
ListSubscriptionSchedulesRequest? request,
]) async {
final map = await get(
'subscription_schedules',
queryParameters: request?.toJson(),
);

return DataList<SubscriptionSchedule>.fromJson(
map,
Expand Down

0 comments on commit 7ae50a5

Please sign in to comment.