Skip to content

Commit 1b6a9f2

Browse files
author
serverpod_cloud
committed
refactor: 622f147c05e298aacb3fc86d3ca45495219b8de8
1 parent 21f321a commit 1b6a9f2

11 files changed

Lines changed: 229 additions & 108 deletions

File tree

ground_control_client/lib/src/protocol/client.dart

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ class EndpointAdminProcurement extends _i1.EndpointRef {
108108
/// If [trialPeriodOverride] is provided, it will override the trial period (number of days).
109109
/// If [overrideChecks] is true, the product availability checks are overridden.
110110
///
111+
/// Returns the subscription ID of the created subscription.
112+
///
111113
/// Throws a [NotFoundException] if the user or product is not found.
112114
/// Throws a [InvalidValueException] if the user has no owner (not fully registered).
113-
_i2.Future<void> procurePlan({
115+
_i2.Future<String> procurePlan({
114116
required String userEmail,
115117
required String planProductName,
116118
int? planProductVersion,
117119
int? trialPeriodOverride,
118120
bool? overrideChecks,
119-
}) => caller.callServerEndpoint<void>('adminProcurement', 'procurePlan', {
121+
}) => caller.callServerEndpoint<String>('adminProcurement', 'procurePlan', {
120122
'userEmail': userEmail,
121123
'planProductName': planProductName,
122124
'planProductVersion': planProductVersion,
@@ -137,8 +139,8 @@ class EndpointAdminProcurement extends _i1.EndpointRef {
137139
{'userEmail': userEmail},
138140
);
139141

140-
/// Cancels the primary plan subscription of the user
141-
/// at the end of its current term.
142+
/// Cancels a subscription of the user at the end of its current term.
143+
/// Either [subscriptionId] or [cloudProjectId] must be provided.
142144
///
143145
/// If [terminateImmediately] is true, the subscription is terminated
144146
/// immediately. If the user still has any active resource products,
@@ -149,9 +151,13 @@ class EndpointAdminProcurement extends _i1.EndpointRef {
149151
/// already been cancelled or ended.
150152
_i2.Future<void> cancelPlan({
151153
required String userEmail,
154+
String? subscriptionId,
155+
String? cloudProjectId,
152156
bool? terminateImmediately,
153157
}) => caller.callServerEndpoint<void>('adminProcurement', 'cancelPlan', {
154158
'userEmail': userEmail,
159+
'subscriptionId': subscriptionId,
160+
'cloudProjectId': cloudProjectId,
155161
'terminateImmediately': terminateImmediately,
156162
});
157163
}
@@ -967,6 +973,9 @@ class EndpointLogs extends _i1.EndpointRef {
967973
}
968974

969975
/// Endpoint for managing subscription plans.
976+
///
977+
/// - Throws [ProcurementDeniedException] if the procurement fails.
978+
/// - Throws [NotFoundException] if the plan is not found.
970979
/// {@category Endpoint}
971980
class EndpointPlans extends _i1.EndpointRef {
972981
EndpointPlans(_i1.EndpointCaller caller) : super(caller);
@@ -975,33 +984,61 @@ class EndpointPlans extends _i1.EndpointRef {
975984
String get name => 'plans';
976985

977986
/// Procures a subscription plan.
978-
_i2.Future<void> procurePlan({
987+
_i2.Future<String> procurePlan({
979988
String? planProductName,
980989
@Deprecated('Use planProductName instead') String? planName,
981-
}) => caller.callServerEndpoint<void>('plans', 'procurePlan', {
990+
}) => caller.callServerEndpoint<String>('plans', 'procurePlan', {
982991
'planProductName': planProductName,
983992
'planName': planName,
984993
});
985994

986-
/// Cancels the primary plan subscription of the user.
995+
/// Cancels a subscription of the user.
987996
///
988997
/// - Throws [ProcurementCancellationException] if the cancellation fails,
989998
/// e.g. if the subscription still has active resources or is already cancelled.
990999
/// - Throws [NoSubscriptionException] if the user has no subscription.
991-
_i2.Future<void> cancelPlan() =>
992-
caller.callServerEndpoint<void>('plans', 'cancelPlan', {});
1000+
_i2.Future<void> cancelPlan({required String subscriptionId}) =>
1001+
caller.callServerEndpoint<void>('plans', 'cancelPlan', {
1002+
'subscriptionId': subscriptionId,
1003+
});
9931004

9941005
/// Fetches the names of the procured subscription plans.
9951006
_i2.Future<List<String>> listProcuredPlanNames() => caller
9961007
.callServerEndpoint<List<String>>('plans', 'listProcuredPlanNames', {});
9971008

998-
_i2.Future<_i29.SubscriptionInfo> getSubscriptionInfo() =>
999-
caller.callServerEndpoint<_i29.SubscriptionInfo>(
1009+
/// Lists the subscriptions of the user.
1010+
_i2.Future<List<_i29.SubscriptionInfo>> listSubscriptions() =>
1011+
caller.callServerEndpoint<List<_i29.SubscriptionInfo>>(
10001012
'plans',
1001-
'getSubscriptionInfo',
1013+
'listSubscriptions',
10021014
{},
10031015
);
10041016

1017+
/// Gets the subscription info for the subscription of the given project id.
1018+
///
1019+
/// Throws [NotFoundException] if the project's subscription is not found.
1020+
_i2.Future<_i29.SubscriptionInfo> getSubscriptionInfoOfProject({
1021+
required String cloudProjectId,
1022+
}) => caller.callServerEndpoint<_i29.SubscriptionInfo>(
1023+
'plans',
1024+
'getSubscriptionInfoOfProject',
1025+
{'cloudProjectId': cloudProjectId},
1026+
);
1027+
1028+
/// Gets a subscription info.
1029+
///
1030+
/// [subscriptionId] is currently nullable for backwards compatibility,
1031+
/// in which case the first found subscription of the owner is used.
1032+
///
1033+
/// Throws [NotFoundException] if the subscription is not found.
1034+
_i2.Future<_i29.SubscriptionInfo> getSubscriptionInfo({
1035+
String? subscriptionId,
1036+
}) => caller.callServerEndpoint<_i29.SubscriptionInfo>(
1037+
'plans',
1038+
'getSubscriptionInfo',
1039+
{'subscriptionId': subscriptionId},
1040+
);
1041+
10051042
/// Checks if a plan is available for procurement.
10061043
///
10071044
/// - Throws [NotFoundException] if the product is not found.
@@ -1042,11 +1079,19 @@ class EndpointProjects extends _i1.EndpointRef {
10421079
});
10431080

10441081
/// Creates a new project with basic setup.
1082+
///
10451083
/// The [cloudProjectId] must be globally unique.
1046-
/// [underSubscriptionId] optionally specify a subscription to procure the
1047-
/// project under, or the user's primary subscription will be used.
1084+
///
1085+
/// [underSubscriptionId] optionally specifies a subscription to procure the
1086+
/// project under, or the user's first found subscription will be used.
1087+
/// In future this parameter will be mandatory.
1088+
///
10481089
/// [projectProductName] optionally specify the project product name to use,
10491090
/// defaults to the first available bundled product for the subscription plan.
1091+
///
1092+
/// Throws [InvalidValueException] if the project name is invalid.
1093+
/// Throws [NotFoundException] if the subscription or the product is not found.
1094+
/// Throws [ProcurementDeniedException] if the procurement fails.
10501095
_i2.Future<_i3.Project> createProject({
10511096
required String cloudProjectId,
10521097
String? underSubscriptionId,

ground_control_client/lib/src/protocol/domains/billing/models/owner.dart

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,29 @@ import 'package:ground_control_client/src/protocol/protocol.dart' as _i5;
1919
abstract class Owner implements _i1.SerializableModel {
2020
Owner._({
2121
_i1.UuidValue? id,
22+
DateTime? createdAt,
23+
DateTime? updatedAt,
24+
this.archivedAt,
2225
required this.externalBillingId,
2326
required this.externalPaymentId,
2427
required this.billingPortalUrl,
2528
required this.billingEmails,
26-
this.primarySubscriptionId,
2729
this.user,
2830
this.billingInfo,
2931
this.projects,
30-
}) : id = id ?? const _i1.Uuid().v4obj();
32+
}) : id = id ?? const _i1.Uuid().v4obj(),
33+
createdAt = createdAt ?? DateTime.now(),
34+
updatedAt = updatedAt ?? DateTime.now();
3135

3236
factory Owner({
3337
_i1.UuidValue? id,
38+
DateTime? createdAt,
39+
DateTime? updatedAt,
40+
DateTime? archivedAt,
3441
required String externalBillingId,
3542
required String externalPaymentId,
3643
required Uri billingPortalUrl,
3744
required List<String> billingEmails,
38-
String? primarySubscriptionId,
3945
_i2.User? user,
4046
_i3.BillingInfo? billingInfo,
4147
List<_i4.Project>? projects,
@@ -46,6 +52,15 @@ abstract class Owner implements _i1.SerializableModel {
4652
id: jsonSerialization['id'] == null
4753
? null
4854
: _i1.UuidValueJsonExtension.fromJson(jsonSerialization['id']),
55+
createdAt: jsonSerialization['createdAt'] == null
56+
? null
57+
: _i1.DateTimeJsonExtension.fromJson(jsonSerialization['createdAt']),
58+
updatedAt: jsonSerialization['updatedAt'] == null
59+
? null
60+
: _i1.DateTimeJsonExtension.fromJson(jsonSerialization['updatedAt']),
61+
archivedAt: jsonSerialization['archivedAt'] == null
62+
? null
63+
: _i1.DateTimeJsonExtension.fromJson(jsonSerialization['archivedAt']),
4964
externalBillingId: jsonSerialization['externalBillingId'] as String,
5065
externalPaymentId: jsonSerialization['externalPaymentId'] as String,
5166
billingPortalUrl: _i1.UriJsonExtension.fromJson(
@@ -54,8 +69,6 @@ abstract class Owner implements _i1.SerializableModel {
5469
billingEmails: _i5.Protocol().deserialize<List<String>>(
5570
jsonSerialization['billingEmails'],
5671
),
57-
primarySubscriptionId:
58-
jsonSerialization['primarySubscriptionId'] as String?,
5972
user: jsonSerialization['user'] == null
6073
? null
6174
: _i5.Protocol().deserialize<_i2.User>(jsonSerialization['user']),
@@ -75,6 +88,13 @@ abstract class Owner implements _i1.SerializableModel {
7588
/// The id of the object.
7689
_i1.UuidValue id;
7790

91+
DateTime createdAt;
92+
93+
DateTime updatedAt;
94+
95+
/// If non-null this Owner is archived.
96+
DateTime? archivedAt;
97+
7898
String externalBillingId;
7999

80100
String externalPaymentId;
@@ -83,10 +103,6 @@ abstract class Owner implements _i1.SerializableModel {
83103

84104
List<String> billingEmails;
85105

86-
/// The id of the primary (default) subscription of this owner.
87-
/// Null if the owner has no subscription.
88-
String? primarySubscriptionId;
89-
90106
_i2.User? user;
91107

92108
_i3.BillingInfo? billingInfo;
@@ -98,11 +114,13 @@ abstract class Owner implements _i1.SerializableModel {
98114
@_i1.useResult
99115
Owner copyWith({
100116
_i1.UuidValue? id,
117+
DateTime? createdAt,
118+
DateTime? updatedAt,
119+
DateTime? archivedAt,
101120
String? externalBillingId,
102121
String? externalPaymentId,
103122
Uri? billingPortalUrl,
104123
List<String>? billingEmails,
105-
String? primarySubscriptionId,
106124
_i2.User? user,
107125
_i3.BillingInfo? billingInfo,
108126
List<_i4.Project>? projects,
@@ -112,12 +130,13 @@ abstract class Owner implements _i1.SerializableModel {
112130
return {
113131
'__className__': 'Owner',
114132
'id': id.toJson(),
133+
'createdAt': createdAt.toJson(),
134+
'updatedAt': updatedAt.toJson(),
135+
if (archivedAt != null) 'archivedAt': archivedAt?.toJson(),
115136
'externalBillingId': externalBillingId,
116137
'externalPaymentId': externalPaymentId,
117138
'billingPortalUrl': billingPortalUrl.toJson(),
118139
'billingEmails': billingEmails.toJson(),
119-
if (primarySubscriptionId != null)
120-
'primarySubscriptionId': primarySubscriptionId,
121140
if (user != null) 'user': user?.toJson(),
122141
if (billingInfo != null) 'billingInfo': billingInfo?.toJson(),
123142
if (projects != null)
@@ -136,21 +155,25 @@ class _Undefined {}
136155
class _OwnerImpl extends Owner {
137156
_OwnerImpl({
138157
_i1.UuidValue? id,
158+
DateTime? createdAt,
159+
DateTime? updatedAt,
160+
DateTime? archivedAt,
139161
required String externalBillingId,
140162
required String externalPaymentId,
141163
required Uri billingPortalUrl,
142164
required List<String> billingEmails,
143-
String? primarySubscriptionId,
144165
_i2.User? user,
145166
_i3.BillingInfo? billingInfo,
146167
List<_i4.Project>? projects,
147168
}) : super._(
148169
id: id,
170+
createdAt: createdAt,
171+
updatedAt: updatedAt,
172+
archivedAt: archivedAt,
149173
externalBillingId: externalBillingId,
150174
externalPaymentId: externalPaymentId,
151175
billingPortalUrl: billingPortalUrl,
152176
billingEmails: billingEmails,
153-
primarySubscriptionId: primarySubscriptionId,
154177
user: user,
155178
billingInfo: billingInfo,
156179
projects: projects,
@@ -162,25 +185,27 @@ class _OwnerImpl extends Owner {
162185
@override
163186
Owner copyWith({
164187
_i1.UuidValue? id,
188+
DateTime? createdAt,
189+
DateTime? updatedAt,
190+
Object? archivedAt = _Undefined,
165191
String? externalBillingId,
166192
String? externalPaymentId,
167193
Uri? billingPortalUrl,
168194
List<String>? billingEmails,
169-
Object? primarySubscriptionId = _Undefined,
170195
Object? user = _Undefined,
171196
Object? billingInfo = _Undefined,
172197
Object? projects = _Undefined,
173198
}) {
174199
return Owner(
175200
id: id ?? this.id,
201+
createdAt: createdAt ?? this.createdAt,
202+
updatedAt: updatedAt ?? this.updatedAt,
203+
archivedAt: archivedAt is DateTime? ? archivedAt : this.archivedAt,
176204
externalBillingId: externalBillingId ?? this.externalBillingId,
177205
externalPaymentId: externalPaymentId ?? this.externalPaymentId,
178206
billingPortalUrl: billingPortalUrl ?? this.billingPortalUrl,
179207
billingEmails:
180208
billingEmails ?? this.billingEmails.map((e0) => e0).toList(),
181-
primarySubscriptionId: primarySubscriptionId is String?
182-
? primarySubscriptionId
183-
: this.primarySubscriptionId,
184209
user: user is _i2.User? ? user : this.user?.copyWith(),
185210
billingInfo: billingInfo is _i3.BillingInfo?
186211
? billingInfo

0 commit comments

Comments
 (0)