Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 17b7558

Browse files
authored
feat: get plan info for subscriptions (#14)
These are needed to check which plan user is subscribed to.
1 parent dcfcd44 commit 17b7558

File tree

7 files changed

+120
-0
lines changed

7 files changed

+120
-0
lines changed

src/generated/Types.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ public interface ProductCommon {
427427
}
428428

429429
public interface PurchaseCommon {
430+
/**
431+
* The current plan identifier. This is:
432+
* - On Android: the basePlanId (e.g., "premium", "premium-year")
433+
* - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
434+
* This provides a unified way to identify which specific plan/tier the user is subscribed to.
435+
*/
436+
val currentPlanId: String?
430437
val id: String
431438
val ids: List<String>?
432439
val isAutoRenewing: Boolean
@@ -445,6 +452,14 @@ public interface PurchaseCommon {
445452

446453
public data class ActiveSubscription(
447454
val autoRenewingAndroid: Boolean? = null,
455+
val basePlanIdAndroid: String? = null,
456+
/**
457+
* The current plan identifier. This is:
458+
* - On Android: the basePlanId (e.g., "premium", "premium-year")
459+
* - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
460+
* This provides a unified way to identify which specific plan/tier the user is subscribed to.
461+
*/
462+
val currentPlanId: String? = null,
448463
val daysUntilExpirationIOS: Double? = null,
449464
val environmentIOS: String? = null,
450465
val expirationDateIOS: Double? = null,
@@ -460,6 +475,8 @@ public data class ActiveSubscription(
460475
fun fromJson(json: Map<String, Any?>): ActiveSubscription {
461476
return ActiveSubscription(
462477
autoRenewingAndroid = json["autoRenewingAndroid"] as Boolean?,
478+
basePlanIdAndroid = json["basePlanIdAndroid"] as String?,
479+
currentPlanId = json["currentPlanId"] as String?,
463480
daysUntilExpirationIOS = (json["daysUntilExpirationIOS"] as Number?)?.toDouble(),
464481
environmentIOS = json["environmentIOS"] as String?,
465482
expirationDateIOS = (json["expirationDateIOS"] as Number?)?.toDouble(),
@@ -476,6 +493,8 @@ public data class ActiveSubscription(
476493
fun toJson(): Map<String, Any?> = mapOf(
477494
"__typename" to "ActiveSubscription",
478495
"autoRenewingAndroid" to autoRenewingAndroid,
496+
"basePlanIdAndroid" to basePlanIdAndroid,
497+
"currentPlanId" to currentPlanId,
479498
"daysUntilExpirationIOS" to daysUntilExpirationIOS,
480499
"environmentIOS" to environmentIOS,
481500
"expirationDateIOS" to expirationDateIOS,
@@ -1015,6 +1034,7 @@ public data class ProductSubscriptionIOS(
10151034

10161035
public data class PurchaseAndroid(
10171036
val autoRenewingAndroid: Boolean? = null,
1037+
val currentPlanId: String? = null,
10181038
val dataAndroid: String? = null,
10191039
val developerPayloadAndroid: String? = null,
10201040
val id: String,
@@ -1038,6 +1058,7 @@ public data class PurchaseAndroid(
10381058
fun fromJson(json: Map<String, Any?>): PurchaseAndroid {
10391059
return PurchaseAndroid(
10401060
autoRenewingAndroid = json["autoRenewingAndroid"] as Boolean?,
1061+
currentPlanId = json["currentPlanId"] as String?,
10411062
dataAndroid = json["dataAndroid"] as String?,
10421063
developerPayloadAndroid = json["developerPayloadAndroid"] as String?,
10431064
id = json["id"] as String,
@@ -1062,6 +1083,7 @@ public data class PurchaseAndroid(
10621083
override fun toJson(): Map<String, Any?> = mapOf(
10631084
"__typename" to "PurchaseAndroid",
10641085
"autoRenewingAndroid" to autoRenewingAndroid,
1086+
"currentPlanId" to currentPlanId,
10651087
"dataAndroid" to dataAndroid,
10661088
"developerPayloadAndroid" to developerPayloadAndroid,
10671089
"id" to id,
@@ -1112,6 +1134,7 @@ public data class PurchaseIOS(
11121134
val countryCodeIOS: String? = null,
11131135
val currencyCodeIOS: String? = null,
11141136
val currencySymbolIOS: String? = null,
1137+
val currentPlanId: String? = null,
11151138
val environmentIOS: String? = null,
11161139
val expirationDateIOS: Double? = null,
11171140
val id: String,
@@ -1148,6 +1171,7 @@ public data class PurchaseIOS(
11481171
countryCodeIOS = json["countryCodeIOS"] as String?,
11491172
currencyCodeIOS = json["currencyCodeIOS"] as String?,
11501173
currencySymbolIOS = json["currencySymbolIOS"] as String?,
1174+
currentPlanId = json["currentPlanId"] as String?,
11511175
environmentIOS = json["environmentIOS"] as String?,
11521176
expirationDateIOS = (json["expirationDateIOS"] as Number?)?.toDouble(),
11531177
id = json["id"] as String,
@@ -1185,6 +1209,7 @@ public data class PurchaseIOS(
11851209
"countryCodeIOS" to countryCodeIOS,
11861210
"currencyCodeIOS" to currencyCodeIOS,
11871211
"currencySymbolIOS" to currencySymbolIOS,
1212+
"currentPlanId" to currentPlanId,
11881213
"environmentIOS" to environmentIOS,
11891214
"expirationDateIOS" to expirationDateIOS,
11901215
"id" to id,

src/generated/Types.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ public protocol ProductCommon: Codable {
131131
}
132132

133133
public protocol PurchaseCommon: Codable {
134+
/// The current plan identifier. This is:
135+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
136+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
137+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
138+
var currentPlanId: String? { get }
134139
var id: String { get }
135140
var ids: [String]? { get }
136141
var isAutoRenewing: Bool { get }
@@ -147,6 +152,12 @@ public protocol PurchaseCommon: Codable {
147152

148153
public struct ActiveSubscription: Codable {
149154
public var autoRenewingAndroid: Bool?
155+
public var basePlanIdAndroid: String?
156+
/// The current plan identifier. This is:
157+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
158+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
159+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
160+
public var currentPlanId: String?
150161
public var daysUntilExpirationIOS: Double?
151162
public var environmentIOS: String?
152163
public var expirationDateIOS: Double?
@@ -314,6 +325,7 @@ public struct ProductSubscriptionIOS: Codable, ProductCommon {
314325

315326
public struct PurchaseAndroid: Codable, PurchaseCommon {
316327
public var autoRenewingAndroid: Bool?
328+
public var currentPlanId: String?
317329
public var dataAndroid: String?
318330
public var developerPayloadAndroid: String?
319331
public var id: String
@@ -345,6 +357,7 @@ public struct PurchaseIOS: Codable, PurchaseCommon {
345357
public var countryCodeIOS: String?
346358
public var currencyCodeIOS: String?
347359
public var currencySymbolIOS: String?
360+
public var currentPlanId: String?
348361
public var environmentIOS: String?
349362
public var expirationDateIOS: Double?
350363
public var id: String
@@ -853,6 +866,19 @@ public enum Purchase: Codable, PurchaseCommon {
853866
case purchaseAndroid(PurchaseAndroid)
854867
case purchaseIos(PurchaseIOS)
855868

869+
/// The current plan identifier. This is:
870+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
871+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
872+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
873+
public var currentPlanId: String? {
874+
switch self {
875+
case let .purchaseAndroid(value):
876+
return value.currentPlanId
877+
case let .purchaseIos(value):
878+
return value.currentPlanId
879+
}
880+
}
881+
856882
public var id: String {
857883
switch self {
858884
case let .purchaseAndroid(value):

src/generated/types.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ abstract class ProductCommon {
522522
}
523523

524524
abstract class PurchaseCommon {
525+
/// The current plan identifier. This is:
526+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
527+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
528+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
529+
String? get currentPlanId;
525530
String get id;
526531
List<String>? get ids;
527532
bool get isAutoRenewing;
@@ -539,6 +544,12 @@ abstract class PurchaseCommon {
539544
class ActiveSubscription {
540545
const ActiveSubscription({
541546
this.autoRenewingAndroid,
547+
this.basePlanIdAndroid,
548+
/// The current plan identifier. This is:
549+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
550+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
551+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
552+
this.currentPlanId,
542553
this.daysUntilExpirationIOS,
543554
this.environmentIOS,
544555
this.expirationDateIOS,
@@ -551,6 +562,12 @@ class ActiveSubscription {
551562
});
552563

553564
final bool? autoRenewingAndroid;
565+
final String? basePlanIdAndroid;
566+
/// The current plan identifier. This is:
567+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
568+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
569+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
570+
final String? currentPlanId;
554571
final double? daysUntilExpirationIOS;
555572
final String? environmentIOS;
556573
final double? expirationDateIOS;
@@ -564,6 +581,8 @@ class ActiveSubscription {
564581
factory ActiveSubscription.fromJson(Map<String, dynamic> json) {
565582
return ActiveSubscription(
566583
autoRenewingAndroid: json['autoRenewingAndroid'] as bool?,
584+
basePlanIdAndroid: json['basePlanIdAndroid'] as String?,
585+
currentPlanId: json['currentPlanId'] as String?,
567586
daysUntilExpirationIOS: (json['daysUntilExpirationIOS'] as num?)?.toDouble(),
568587
environmentIOS: json['environmentIOS'] as String?,
569588
expirationDateIOS: (json['expirationDateIOS'] as num?)?.toDouble(),
@@ -580,6 +599,8 @@ class ActiveSubscription {
580599
return {
581600
'__typename': 'ActiveSubscription',
582601
'autoRenewingAndroid': autoRenewingAndroid,
602+
'basePlanIdAndroid': basePlanIdAndroid,
603+
'currentPlanId': currentPlanId,
583604
'daysUntilExpirationIOS': daysUntilExpirationIOS,
584605
'environmentIOS': environmentIOS,
585606
'expirationDateIOS': expirationDateIOS,
@@ -1260,6 +1281,7 @@ class ProductSubscriptionIOS extends ProductSubscription implements ProductCommo
12601281
class PurchaseAndroid extends Purchase implements PurchaseCommon {
12611282
const PurchaseAndroid({
12621283
this.autoRenewingAndroid,
1284+
this.currentPlanId,
12631285
this.dataAndroid,
12641286
this.developerPayloadAndroid,
12651287
required this.id,
@@ -1281,6 +1303,7 @@ class PurchaseAndroid extends Purchase implements PurchaseCommon {
12811303
});
12821304

12831305
final bool? autoRenewingAndroid;
1306+
final String? currentPlanId;
12841307
final String? dataAndroid;
12851308
final String? developerPayloadAndroid;
12861309
final String id;
@@ -1303,6 +1326,7 @@ class PurchaseAndroid extends Purchase implements PurchaseCommon {
13031326
factory PurchaseAndroid.fromJson(Map<String, dynamic> json) {
13041327
return PurchaseAndroid(
13051328
autoRenewingAndroid: json['autoRenewingAndroid'] as bool?,
1329+
currentPlanId: json['currentPlanId'] as String?,
13061330
dataAndroid: json['dataAndroid'] as String?,
13071331
developerPayloadAndroid: json['developerPayloadAndroid'] as String?,
13081332
id: json['id'] as String,
@@ -1329,6 +1353,7 @@ class PurchaseAndroid extends Purchase implements PurchaseCommon {
13291353
return {
13301354
'__typename': 'PurchaseAndroid',
13311355
'autoRenewingAndroid': autoRenewingAndroid,
1356+
'currentPlanId': currentPlanId,
13321357
'dataAndroid': dataAndroid,
13331358
'developerPayloadAndroid': developerPayloadAndroid,
13341359
'id': id,
@@ -1387,6 +1412,7 @@ class PurchaseIOS extends Purchase implements PurchaseCommon {
13871412
this.countryCodeIOS,
13881413
this.currencyCodeIOS,
13891414
this.currencySymbolIOS,
1415+
this.currentPlanId,
13901416
this.environmentIOS,
13911417
this.expirationDateIOS,
13921418
required this.id,
@@ -1421,6 +1447,7 @@ class PurchaseIOS extends Purchase implements PurchaseCommon {
14211447
final String? countryCodeIOS;
14221448
final String? currencyCodeIOS;
14231449
final String? currencySymbolIOS;
1450+
final String? currentPlanId;
14241451
final String? environmentIOS;
14251452
final double? expirationDateIOS;
14261453
final String id;
@@ -1456,6 +1483,7 @@ class PurchaseIOS extends Purchase implements PurchaseCommon {
14561483
countryCodeIOS: json['countryCodeIOS'] as String?,
14571484
currencyCodeIOS: json['currencyCodeIOS'] as String?,
14581485
currencySymbolIOS: json['currencySymbolIOS'] as String?,
1486+
currentPlanId: json['currentPlanId'] as String?,
14591487
environmentIOS: json['environmentIOS'] as String?,
14601488
expirationDateIOS: (json['expirationDateIOS'] as num?)?.toDouble(),
14611489
id: json['id'] as String,
@@ -1495,6 +1523,7 @@ class PurchaseIOS extends Purchase implements PurchaseCommon {
14951523
'countryCodeIOS': countryCodeIOS,
14961524
'currencyCodeIOS': currencyCodeIOS,
14971525
'currencySymbolIOS': currencySymbolIOS,
1526+
'currentPlanId': currentPlanId,
14981527
'environmentIOS': environmentIOS,
14991528
'expirationDateIOS': expirationDateIOS,
15001529
'id': id,
@@ -2528,6 +2557,12 @@ sealed class Purchase implements PurchaseCommon {
25282557
throw ArgumentError('Unknown __typename for Purchase: $typeName');
25292558
}
25302559

2560+
/// The current plan identifier. This is:
2561+
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
2562+
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
2563+
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
2564+
@override
2565+
String? get currentPlanId;
25312566
@override
25322567
String get id;
25332568
@override

src/generated/types.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
export interface ActiveSubscription {
77
autoRenewingAndroid?: (boolean | null);
8+
basePlanIdAndroid?: (string | null);
9+
/**
10+
* The current plan identifier. This is:
11+
* - On Android: the basePlanId (e.g., "premium", "premium-year")
12+
* - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
13+
* This provides a unified way to identify which specific plan/tier the user is subscribed to.
14+
*/
15+
currentPlanId?: (string | null);
816
daysUntilExpirationIOS?: (number | null);
917
environmentIOS?: (string | null);
1018
expirationDateIOS?: (number | null);
@@ -381,6 +389,7 @@ export type Purchase = PurchaseAndroid | PurchaseIOS;
381389

382390
export interface PurchaseAndroid extends PurchaseCommon {
383391
autoRenewingAndroid?: (boolean | null);
392+
currentPlanId?: (string | null);
384393
dataAndroid?: (string | null);
385394
developerPayloadAndroid?: (string | null);
386395
id: string;
@@ -401,6 +410,13 @@ export interface PurchaseAndroid extends PurchaseCommon {
401410
}
402411

403412
export interface PurchaseCommon {
413+
/**
414+
* The current plan identifier. This is:
415+
* - On Android: the basePlanId (e.g., "premium", "premium-year")
416+
* - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
417+
* This provides a unified way to identify which specific plan/tier the user is subscribed to.
418+
*/
419+
currentPlanId?: (string | null);
404420
id: string;
405421
ids?: (string[] | null);
406422
isAutoRenewing: boolean;
@@ -425,6 +441,7 @@ export interface PurchaseIOS extends PurchaseCommon {
425441
countryCodeIOS?: (string | null);
426442
currencyCodeIOS?: (string | null);
427443
currencySymbolIOS?: (string | null);
444+
currentPlanId?: (string | null);
428445
environmentIOS?: (string | null);
429446
expirationDateIOS?: (number | null);
430447
id: string;

src/type-android.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type PurchaseAndroid implements PurchaseCommon {
7878
quantity: Int!
7979
purchaseState: PurchaseState!
8080
isAutoRenewing: Boolean!
81+
currentPlanId: String
8182

8283
# Android-specific fields
8384
dataAndroid: String

src/type-ios.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type PurchaseIOS implements PurchaseCommon {
132132
quantity: Int!
133133
purchaseState: PurchaseState!
134134
isAutoRenewing: Boolean!
135+
currentPlanId: String
135136

136137
# iOS-specific fields
137138
transactionId: String!

src/type.graphql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ interface PurchaseCommon {
5757
quantity: Int!
5858
purchaseState: PurchaseState!
5959
isAutoRenewing: Boolean!
60+
"""
61+
The current plan identifier. This is:
62+
- On Android: the basePlanId (e.g., "premium", "premium-year")
63+
- On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
64+
This provides a unified way to identify which specific plan/tier the user is subscribed to.
65+
"""
66+
currentPlanId: String
6067
}
6168

6269
# Unions for platform-specific types
@@ -203,6 +210,14 @@ type ActiveSubscription {
203210
transactionId: String!
204211
purchaseToken: String
205212
transactionDate: Float!
213+
basePlanIdAndroid: String
214+
"""
215+
The current plan identifier. This is:
216+
- On Android: the basePlanId (e.g., "premium", "premium-year")
217+
- On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
218+
This provides a unified way to identify which specific plan/tier the user is subscribed to.
219+
"""
220+
currentPlanId: String
206221
}
207222

208223
# Initialization configuration

0 commit comments

Comments
 (0)