-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(code_push_protocol): add subscription object to user #339
Changes from all commits
7c07364
54d5b9a
02eece5
15938fe
0a8be78
adcff9b
bbd304e
cc0c66e
4138735
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
|
||
part 'subscription.g.dart'; | ||
|
||
/// {@template subscription} | ||
/// A user's Shorebird subscription. | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class Subscription { | ||
/// {@macro subscription} | ||
Subscription({ | ||
required this.cost, | ||
required this.paidThroughDate, | ||
required this.willRenew, | ||
}); | ||
|
||
/// Creates a [Subscription] from a JSON object. | ||
factory Subscription.fromJson(Json json) => _$SubscriptionFromJson(json); | ||
|
||
/// Converts a [Subscription] to a JSON object. | ||
Json toJson() => _$SubscriptionToJson(this); | ||
|
||
/// Billing rate, in cents. | ||
final int cost; | ||
|
||
/// When the subscription will be renewed or expire. | ||
@TimestampConverter() | ||
final DateTime paidThroughDate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this is midnight UTC on that date? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not specified, but looking at some of the live subscriptions, it seems to be |
||
|
||
/// Whether this subscription will renew on [paidThroughDate]. | ||
final bool willRenew; | ||
|
||
/// Whether this subscription is currently active. | ||
bool get isActive => paidThroughDate.isAfter(DateTime.now()); | ||
bryanoltman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(Subscription, () { | ||
test('can be (de)serialized', () { | ||
final subscription = Subscription( | ||
cost: 100, | ||
paidThroughDate: DateTime.now(), | ||
willRenew: true, | ||
); | ||
expect( | ||
Subscription.fromJson(subscription.toJson()).toJson(), | ||
equals(subscription.toJson()), | ||
); | ||
}); | ||
|
||
group('isActive', () { | ||
test('returns true if paidThroughDate is in the future', () { | ||
final subscription = Subscription( | ||
cost: 100, | ||
paidThroughDate: DateTime.now().add(const Duration(days: 1)), | ||
willRenew: true, | ||
); | ||
expect(subscription.isActive, isTrue); | ||
}); | ||
|
||
test('returns false if paidThroughDate is in the past', () { | ||
final subscription = Subscription( | ||
cost: 100, | ||
paidThroughDate: DateTime.now().subtract(const Duration(days: 1)), | ||
willRenew: true, | ||
); | ||
expect(subscription.isActive, isFalse); | ||
}); | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh man. US Cents I assume. :) Someone is going to write an amazing typed "money" object someday. 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://pub.dev/packages/money2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming usd for now.
Stripe specifies
currency
on the individual price objects (https://stripe.com/docs/api/prices/object#price_object-currency), so we can get fancier if/when we need to.