This repository was archived by the owner on Oct 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTypes.swift
More file actions
1489 lines (1352 loc) · 57.7 KB
/
Types.swift
File metadata and controls
1489 lines (1352 loc) · 57.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ============================================================================
// AUTO-GENERATED TYPES — DO NOT EDIT DIRECTLY
// Run `npm run generate` after updating any *.graphql schema file.
// ============================================================================
import Foundation
// MARK: - Enums
/// Alternative billing mode for Android
/// Controls which billing system is used
public enum AlternativeBillingModeAndroid: String, Codable, CaseIterable {
/// Standard Google Play billing (default)
case none = "none"
/// User choice billing - user can select between Google Play or alternative
/// Requires Google Play Billing Library 7.0+
case userChoice = "user-choice"
/// Alternative billing only - no Google Play billing option
/// Requires Google Play Billing Library 6.2+
case alternativeOnly = "alternative-only"
}
public enum ErrorCode: String, Codable, CaseIterable {
case unknown = "unknown"
case userCancelled = "user-cancelled"
case userError = "user-error"
case itemUnavailable = "item-unavailable"
case remoteError = "remote-error"
case networkError = "network-error"
case serviceError = "service-error"
case receiptFailed = "receipt-failed"
case receiptFinished = "receipt-finished"
case receiptFinishedFailed = "receipt-finished-failed"
case notPrepared = "not-prepared"
case notEnded = "not-ended"
case alreadyOwned = "already-owned"
case developerError = "developer-error"
case billingResponseJsonParseError = "billing-response-json-parse-error"
case deferredPayment = "deferred-payment"
case interrupted = "interrupted"
case iapNotAvailable = "iap-not-available"
case purchaseError = "purchase-error"
case syncError = "sync-error"
case transactionValidationFailed = "transaction-validation-failed"
case activityUnavailable = "activity-unavailable"
case alreadyPrepared = "already-prepared"
case pending = "pending"
case connectionClosed = "connection-closed"
case initConnection = "init-connection"
case serviceDisconnected = "service-disconnected"
case queryProduct = "query-product"
case skuNotFound = "sku-not-found"
case skuOfferMismatch = "sku-offer-mismatch"
case itemNotOwned = "item-not-owned"
case billingUnavailable = "billing-unavailable"
case featureNotSupported = "feature-not-supported"
case emptySkuList = "empty-sku-list"
}
/// User actions on external purchase notice sheet (iOS 18.2+)
public enum ExternalPurchaseNoticeAction: String, Codable, CaseIterable {
/// User chose to continue to external purchase
case `continue` = "continue"
/// User dismissed the notice sheet
case dismissed = "dismissed"
}
public enum IapEvent: String, Codable, CaseIterable {
case purchaseUpdated = "purchase-updated"
case purchaseError = "purchase-error"
case promotedProductIos = "promoted-product-ios"
case userChoiceBillingAndroid = "user-choice-billing-android"
}
public enum IapPlatform: String, Codable, CaseIterable {
case ios = "ios"
case android = "android"
}
public enum PaymentModeIOS: String, Codable, CaseIterable {
case empty = "empty"
case freeTrial = "free-trial"
case payAsYouGo = "pay-as-you-go"
case payUpFront = "pay-up-front"
}
public enum ProductQueryType: String, Codable, CaseIterable {
case inApp = "in-app"
case subs = "subs"
case all = "all"
}
public enum ProductType: String, Codable, CaseIterable {
case inApp = "in-app"
case subs = "subs"
}
public enum ProductTypeIOS: String, Codable, CaseIterable {
case consumable = "consumable"
case nonConsumable = "non-consumable"
case autoRenewableSubscription = "auto-renewable-subscription"
case nonRenewingSubscription = "non-renewing-subscription"
}
public enum PurchaseState: String, Codable, CaseIterable {
case pending = "pending"
case purchased = "purchased"
case failed = "failed"
case restored = "restored"
case deferred = "deferred"
case unknown = "unknown"
}
public enum SubscriptionOfferTypeIOS: String, Codable, CaseIterable {
case introductory = "introductory"
case promotional = "promotional"
}
public enum SubscriptionPeriodIOS: String, Codable, CaseIterable {
case day = "day"
case week = "week"
case month = "month"
case year = "year"
case empty = "empty"
}
// MARK: - Interfaces
public protocol ProductCommon: Codable {
var currency: String { get }
var debugDescription: String? { get }
var description: String { get }
var displayName: String? { get }
var displayPrice: String { get }
var id: String { get }
var platform: IapPlatform { get }
var price: Double? { get }
var title: String { get }
var type: ProductType { get }
}
public protocol PurchaseCommon: Codable {
/// The current plan identifier. This is:
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
var currentPlanId: String? { get }
var id: String { get }
var ids: [String]? { get }
var isAutoRenewing: Bool { get }
var platform: IapPlatform { get }
var productId: String { get }
var purchaseState: PurchaseState { get }
/// Unified purchase token (iOS JWS, Android purchaseToken)
var purchaseToken: String? { get }
var quantity: Int { get }
var transactionDate: Double { get }
}
// MARK: - Objects
public struct ActiveSubscription: Codable {
public var autoRenewingAndroid: Bool?
public var basePlanIdAndroid: String?
/// The current plan identifier. This is:
/// - On Android: the basePlanId (e.g., "premium", "premium-year")
/// - On iOS: the productId (e.g., "com.example.premium_monthly", "com.example.premium_yearly")
/// This provides a unified way to identify which specific plan/tier the user is subscribed to.
public var currentPlanId: String?
public var daysUntilExpirationIOS: Double?
public var environmentIOS: String?
public var expirationDateIOS: Double?
public var isActive: Bool
public var productId: String
public var purchaseToken: String?
/// Required for subscription upgrade/downgrade on Android
public var purchaseTokenAndroid: String?
/// Renewal information from StoreKit 2 (iOS only). Contains details about subscription renewal status,
/// pending upgrades/downgrades, and auto-renewal preferences.
public var renewalInfoIOS: RenewalInfoIOS?
public var transactionDate: Double
public var transactionId: String
public var willExpireSoon: Bool?
}
public struct AppTransaction: Codable {
public var appId: Double
public var appTransactionId: String?
public var appVersion: String
public var appVersionId: Double
public var bundleId: String
public var deviceVerification: String
public var deviceVerificationNonce: String
public var environment: String
public var originalAppVersion: String
public var originalPlatform: String?
public var originalPurchaseDate: Double
public var preorderDate: Double?
public var signedDate: Double
}
public struct DiscountIOS: Codable {
public var identifier: String
public var localizedPrice: String?
public var numberOfPeriods: Int
public var paymentMode: PaymentModeIOS
public var price: String
public var priceAmount: Double
public var subscriptionPeriod: String
public var type: String
}
public struct DiscountOfferIOS: Codable {
/// Discount identifier
public var identifier: String
/// Key identifier for validation
public var keyIdentifier: String
/// Cryptographic nonce
public var nonce: String
/// Signature for validation
public var signature: String
/// Timestamp of discount offer
public var timestamp: Double
}
public struct EntitlementIOS: Codable {
public var jsonRepresentation: String
public var sku: String
public var transactionId: String
}
/// Result of presenting an external purchase link (iOS 18.2+)
public struct ExternalPurchaseLinkResultIOS: Codable {
/// Optional error message if the presentation failed
public var error: String?
/// Whether the user completed the external purchase flow
public var success: Bool
}
/// Result of presenting external purchase notice sheet (iOS 18.2+)
public struct ExternalPurchaseNoticeResultIOS: Codable {
/// Optional error message if the presentation failed
public var error: String?
/// Notice result indicating user action
public var result: ExternalPurchaseNoticeAction
}
public enum FetchProductsResult {
case products([Product]?)
case subscriptions([ProductSubscription]?)
}
public struct PricingPhaseAndroid: Codable {
public var billingCycleCount: Int
public var billingPeriod: String
public var formattedPrice: String
public var priceAmountMicros: String
public var priceCurrencyCode: String
public var recurrenceMode: Int
}
public struct PricingPhasesAndroid: Codable {
public var pricingPhaseList: [PricingPhaseAndroid]
}
public struct ProductAndroid: Codable, ProductCommon {
public var currency: String
public var debugDescription: String?
public var description: String
public var displayName: String?
public var displayPrice: String
public var id: String
public var nameAndroid: String
public var oneTimePurchaseOfferDetailsAndroid: ProductAndroidOneTimePurchaseOfferDetail?
public var platform: IapPlatform
public var price: Double?
public var subscriptionOfferDetailsAndroid: [ProductSubscriptionAndroidOfferDetails]?
public var title: String
public var type: ProductType
}
public struct ProductAndroidOneTimePurchaseOfferDetail: Codable {
public var formattedPrice: String
public var priceAmountMicros: String
public var priceCurrencyCode: String
}
public struct ProductIOS: Codable, ProductCommon {
public var currency: String
public var debugDescription: String?
public var description: String
public var displayName: String?
public var displayNameIOS: String
public var displayPrice: String
public var id: String
public var isFamilyShareableIOS: Bool
public var jsonRepresentationIOS: String
public var platform: IapPlatform
public var price: Double?
public var subscriptionInfoIOS: SubscriptionInfoIOS?
public var title: String
public var type: ProductType
public var typeIOS: ProductTypeIOS
}
public struct ProductSubscriptionAndroid: Codable, ProductCommon {
public var currency: String
public var debugDescription: String?
public var description: String
public var displayName: String?
public var displayPrice: String
public var id: String
public var nameAndroid: String
public var oneTimePurchaseOfferDetailsAndroid: ProductAndroidOneTimePurchaseOfferDetail?
public var platform: IapPlatform
public var price: Double?
public var subscriptionOfferDetailsAndroid: [ProductSubscriptionAndroidOfferDetails]
public var title: String
public var type: ProductType
}
public struct ProductSubscriptionAndroidOfferDetails: Codable {
public var basePlanId: String
public var offerId: String?
public var offerTags: [String]
public var offerToken: String
public var pricingPhases: PricingPhasesAndroid
}
public struct ProductSubscriptionIOS: Codable, ProductCommon {
public var currency: String
public var debugDescription: String?
public var description: String
public var discountsIOS: [DiscountIOS]?
public var displayName: String?
public var displayNameIOS: String
public var displayPrice: String
public var id: String
public var introductoryPriceAsAmountIOS: String?
public var introductoryPriceIOS: String?
public var introductoryPriceNumberOfPeriodsIOS: String?
public var introductoryPricePaymentModeIOS: PaymentModeIOS?
public var introductoryPriceSubscriptionPeriodIOS: SubscriptionPeriodIOS?
public var isFamilyShareableIOS: Bool
public var jsonRepresentationIOS: String
public var platform: IapPlatform
public var price: Double?
public var subscriptionInfoIOS: SubscriptionInfoIOS?
public var subscriptionPeriodNumberIOS: String?
public var subscriptionPeriodUnitIOS: SubscriptionPeriodIOS?
public var title: String
public var type: ProductType
public var typeIOS: ProductTypeIOS
}
public struct PurchaseAndroid: Codable, PurchaseCommon {
public var autoRenewingAndroid: Bool?
public var currentPlanId: String?
public var dataAndroid: String?
public var developerPayloadAndroid: String?
public var id: String
public var ids: [String]?
public var isAcknowledgedAndroid: Bool?
public var isAutoRenewing: Bool
public var obfuscatedAccountIdAndroid: String?
public var obfuscatedProfileIdAndroid: String?
public var packageNameAndroid: String?
public var platform: IapPlatform
public var productId: String
public var purchaseState: PurchaseState
public var purchaseToken: String?
public var quantity: Int
public var signatureAndroid: String?
public var transactionDate: Double
public var transactionId: String?
}
public struct PurchaseError: Codable {
public var code: ErrorCode
public var message: String
public var productId: String?
}
public struct PurchaseIOS: Codable, PurchaseCommon {
public var appAccountToken: String?
public var appBundleIdIOS: String?
public var countryCodeIOS: String?
public var currencyCodeIOS: String?
public var currencySymbolIOS: String?
public var currentPlanId: String?
public var environmentIOS: String?
public var expirationDateIOS: Double?
public var id: String
public var ids: [String]?
public var isAutoRenewing: Bool
public var isUpgradedIOS: Bool?
public var offerIOS: PurchaseOfferIOS?
public var originalTransactionDateIOS: Double?
public var originalTransactionIdentifierIOS: String?
public var ownershipTypeIOS: String?
public var platform: IapPlatform
public var productId: String
public var purchaseState: PurchaseState
public var purchaseToken: String?
public var quantity: Int
public var quantityIOS: Int?
public var reasonIOS: String?
public var reasonStringRepresentationIOS: String?
public var renewalInfoIOS: RenewalInfoIOS?
public var revocationDateIOS: Double?
public var revocationReasonIOS: String?
public var storefrontCountryCodeIOS: String?
public var subscriptionGroupIdIOS: String?
public var transactionDate: Double
public var transactionId: String
public var transactionReasonIOS: String?
public var webOrderLineItemIdIOS: String?
}
public struct PurchaseOfferIOS: Codable {
public var id: String
public var paymentMode: String
public var type: String
}
public struct ReceiptValidationResultAndroid: Codable {
public var autoRenewing: Bool
public var betaProduct: Bool
public var cancelDate: Double?
public var cancelReason: String?
public var deferredDate: Double?
public var deferredSku: String?
public var freeTrialEndDate: Double
public var gracePeriodEndDate: Double
public var parentProductId: String
public var productId: String
public var productType: String
public var purchaseDate: Double
public var quantity: Int
public var receiptId: String
public var renewalDate: Double
public var term: String
public var termSku: String
public var testTransaction: Bool
}
public struct ReceiptValidationResultIOS: Codable {
/// Whether the receipt is valid
public var isValid: Bool
/// JWS representation
public var jwsRepresentation: String
/// Latest transaction if available
public var latestTransaction: Purchase?
/// Receipt data string
public var receiptData: String
}
public struct RefundResultIOS: Codable {
public var message: String?
public var status: String
}
/// Subscription renewal information from Product.SubscriptionInfo.RenewalInfo
/// https://developer.apple.com/documentation/storekit/product/subscriptioninfo/renewalinfo
public struct RenewalInfoIOS: Codable {
public var autoRenewPreference: String?
/// When subscription expires due to cancellation/billing issue
/// Possible values: "VOLUNTARY", "BILLING_ERROR", "DID_NOT_AGREE_TO_PRICE_INCREASE", "PRODUCT_NOT_AVAILABLE", "UNKNOWN"
public var expirationReason: String?
/// Grace period expiration date (milliseconds since epoch)
/// When set, subscription is in grace period (billing issue but still has access)
public var gracePeriodExpirationDate: Double?
/// True if subscription failed to renew due to billing issue and is retrying
/// Note: Not directly available in RenewalInfo, available in Status
public var isInBillingRetry: Bool?
public var jsonRepresentation: String?
/// Product ID that will be used on next renewal (when user upgrades/downgrades)
/// If set and different from current productId, subscription will change on expiration
public var pendingUpgradeProductId: String?
/// User's response to subscription price increase
/// Possible values: "AGREED", "PENDING", null (no price increase)
public var priceIncreaseStatus: String?
/// Expected renewal date (milliseconds since epoch)
/// For active subscriptions, when the next renewal/charge will occur
public var renewalDate: Double?
/// Offer ID applied to next renewal (promotional offer, subscription offer code, etc.)
public var renewalOfferId: String?
/// Type of offer applied to next renewal
/// Possible values: "PROMOTIONAL", "SUBSCRIPTION_OFFER_CODE", "WIN_BACK", etc.
public var renewalOfferType: String?
public var willAutoRenew: Bool
}
public enum RequestPurchaseResult {
case purchase(Purchase?)
case purchases([Purchase]?)
}
public struct SubscriptionInfoIOS: Codable {
public var introductoryOffer: SubscriptionOfferIOS?
public var promotionalOffers: [SubscriptionOfferIOS]?
public var subscriptionGroupId: String
public var subscriptionPeriod: SubscriptionPeriodValueIOS
}
public struct SubscriptionOfferIOS: Codable {
public var displayPrice: String
public var id: String
public var paymentMode: PaymentModeIOS
public var period: SubscriptionPeriodValueIOS
public var periodCount: Int
public var price: Double
public var type: SubscriptionOfferTypeIOS
}
public struct SubscriptionPeriodValueIOS: Codable {
public var unit: SubscriptionPeriodIOS
public var value: Int
}
public struct SubscriptionStatusIOS: Codable {
public var renewalInfo: RenewalInfoIOS?
public var state: String
}
/// User Choice Billing event details (Android)
/// Fired when a user selects alternative billing in the User Choice Billing dialog
public struct UserChoiceBillingDetails: Codable {
/// Token that must be reported to Google Play within 24 hours
public var externalTransactionToken: String
/// List of product IDs selected by the user
public var products: [String]
}
public typealias VoidResult = Void
// MARK: - Input Objects
public struct AndroidSubscriptionOfferInput: Codable {
/// Offer token
public var offerToken: String
/// Product SKU
public var sku: String
public init(
offerToken: String,
sku: String
) {
self.offerToken = offerToken
self.sku = sku
}
}
public struct DeepLinkOptions: Codable {
/// Android package name to target (required on Android)
public var packageNameAndroid: String?
/// Android SKU to open (required on Android)
public var skuAndroid: String?
public init(
packageNameAndroid: String? = nil,
skuAndroid: String? = nil
) {
self.packageNameAndroid = packageNameAndroid
self.skuAndroid = skuAndroid
}
}
public struct DiscountOfferInputIOS: Codable {
/// Discount identifier
public var identifier: String
/// Key identifier for validation
public var keyIdentifier: String
/// Cryptographic nonce
public var nonce: String
/// Signature for validation
public var signature: String
/// Timestamp of discount offer
public var timestamp: Double
public init(
identifier: String,
keyIdentifier: String,
nonce: String,
signature: String,
timestamp: Double
) {
self.identifier = identifier
self.keyIdentifier = keyIdentifier
self.nonce = nonce
self.signature = signature
self.timestamp = timestamp
}
}
/// Connection initialization configuration
public struct InitConnectionConfig: Codable {
/// Alternative billing mode for Android
/// If not specified, defaults to NONE (standard Google Play billing)
public var alternativeBillingModeAndroid: AlternativeBillingModeAndroid?
public init(
alternativeBillingModeAndroid: AlternativeBillingModeAndroid? = nil
) {
self.alternativeBillingModeAndroid = alternativeBillingModeAndroid
}
}
public struct ProductRequest: Codable {
public var skus: [String]
public var type: ProductQueryType?
public init(
skus: [String],
type: ProductQueryType? = nil
) {
self.skus = skus
self.type = type
}
}
public typealias PurchaseInput = Purchase
public struct PurchaseOptions: Codable {
/// Also emit results through the iOS event listeners
public var alsoPublishToEventListenerIOS: Bool?
/// Limit to currently active items on iOS
public var onlyIncludeActiveItemsIOS: Bool?
public init(
alsoPublishToEventListenerIOS: Bool? = nil,
onlyIncludeActiveItemsIOS: Bool? = nil
) {
self.alsoPublishToEventListenerIOS = alsoPublishToEventListenerIOS
self.onlyIncludeActiveItemsIOS = onlyIncludeActiveItemsIOS
}
}
public struct ReceiptValidationAndroidOptions: Codable {
public var accessToken: String
public var isSub: Bool?
public var packageName: String
public var productToken: String
public init(
accessToken: String,
isSub: Bool? = nil,
packageName: String,
productToken: String
) {
self.accessToken = accessToken
self.isSub = isSub
self.packageName = packageName
self.productToken = productToken
}
}
public struct ReceiptValidationProps: Codable {
/// Android-specific validation options
public var androidOptions: ReceiptValidationAndroidOptions?
/// Product SKU to validate
public var sku: String
public init(
androidOptions: ReceiptValidationAndroidOptions? = nil,
sku: String
) {
self.androidOptions = androidOptions
self.sku = sku
}
}
public struct RequestPurchaseAndroidProps: Codable {
/// Personalized offer flag
public var isOfferPersonalized: Bool?
/// Obfuscated account ID
public var obfuscatedAccountIdAndroid: String?
/// Obfuscated profile ID
public var obfuscatedProfileIdAndroid: String?
/// List of product SKUs
public var skus: [String]
public init(
isOfferPersonalized: Bool? = nil,
obfuscatedAccountIdAndroid: String? = nil,
obfuscatedProfileIdAndroid: String? = nil,
skus: [String]
) {
self.isOfferPersonalized = isOfferPersonalized
self.obfuscatedAccountIdAndroid = obfuscatedAccountIdAndroid
self.obfuscatedProfileIdAndroid = obfuscatedProfileIdAndroid
self.skus = skus
}
}
public struct RequestPurchaseIosProps: Codable {
/// Auto-finish transaction (dangerous)
public var andDangerouslyFinishTransactionAutomatically: Bool?
/// App account token for user tracking
public var appAccountToken: String?
/// Purchase quantity
public var quantity: Int?
/// Product SKU
public var sku: String
/// Discount offer to apply
public var withOffer: DiscountOfferInputIOS?
public init(
andDangerouslyFinishTransactionAutomatically: Bool? = nil,
appAccountToken: String? = nil,
quantity: Int? = nil,
sku: String,
withOffer: DiscountOfferInputIOS? = nil
) {
self.andDangerouslyFinishTransactionAutomatically = andDangerouslyFinishTransactionAutomatically
self.appAccountToken = appAccountToken
self.quantity = quantity
self.sku = sku
self.withOffer = withOffer
}
}
public struct RequestPurchaseProps: Codable {
public var request: Request
public var type: ProductQueryType
public var useAlternativeBilling: Bool?
public init(request: Request, type: ProductQueryType? = nil, useAlternativeBilling: Bool? = nil) {
switch request {
case .purchase:
let resolved = type ?? .inApp
precondition(resolved == .inApp, "RequestPurchaseProps.type must be .inApp when request is purchase")
self.type = resolved
case .subscription:
let resolved = type ?? .subs
precondition(resolved == .subs, "RequestPurchaseProps.type must be .subs when request is subscription")
self.type = resolved
}
self.request = request
self.useAlternativeBilling = useAlternativeBilling
}
private enum CodingKeys: String, CodingKey {
case requestPurchase
case requestSubscription
case type
case useAlternativeBilling
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let decodedType = try container.decodeIfPresent(ProductQueryType.self, forKey: .type)
self.useAlternativeBilling = try container.decodeIfPresent(Bool.self, forKey: .useAlternativeBilling)
if let purchase = try container.decodeIfPresent(RequestPurchasePropsByPlatforms.self, forKey: .requestPurchase) {
let finalType = decodedType ?? .inApp
guard finalType == .inApp else {
throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "type must be IN_APP when requestPurchase is provided")
}
self.request = .purchase(purchase)
self.type = finalType
return
}
if let subscription = try container.decodeIfPresent(RequestSubscriptionPropsByPlatforms.self, forKey: .requestSubscription) {
let finalType = decodedType ?? .subs
guard finalType == .subs else {
throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "type must be SUBS when requestSubscription is provided")
}
self.request = .subscription(subscription)
self.type = finalType
return
}
throw DecodingError.dataCorruptedError(forKey: .requestPurchase, in: container, debugDescription: "RequestPurchaseProps requires requestPurchase or requestSubscription.")
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch request {
case let .purchase(value):
try container.encode(value, forKey: .requestPurchase)
case let .subscription(value):
try container.encode(value, forKey: .requestSubscription)
}
try container.encode(type, forKey: .type)
try container.encodeIfPresent(useAlternativeBilling, forKey: .useAlternativeBilling)
}
public enum Request {
case purchase(RequestPurchasePropsByPlatforms)
case subscription(RequestSubscriptionPropsByPlatforms)
}
}
public struct RequestPurchasePropsByPlatforms: Codable {
/// Android-specific purchase parameters
public var android: RequestPurchaseAndroidProps?
/// iOS-specific purchase parameters
public var ios: RequestPurchaseIosProps?
public init(
android: RequestPurchaseAndroidProps? = nil,
ios: RequestPurchaseIosProps? = nil
) {
self.android = android
self.ios = ios
}
}
public struct RequestSubscriptionAndroidProps: Codable {
/// Personalized offer flag
public var isOfferPersonalized: Bool?
/// Obfuscated account ID
public var obfuscatedAccountIdAndroid: String?
/// Obfuscated profile ID
public var obfuscatedProfileIdAndroid: String?
/// Purchase token for upgrades/downgrades
public var purchaseTokenAndroid: String?
/// Replacement mode for subscription changes
public var replacementModeAndroid: Int?
/// List of subscription SKUs
public var skus: [String]
/// Subscription offers
public var subscriptionOffers: [AndroidSubscriptionOfferInput]?
public init(
isOfferPersonalized: Bool? = nil,
obfuscatedAccountIdAndroid: String? = nil,
obfuscatedProfileIdAndroid: String? = nil,
purchaseTokenAndroid: String? = nil,
replacementModeAndroid: Int? = nil,
skus: [String],
subscriptionOffers: [AndroidSubscriptionOfferInput]? = nil
) {
self.isOfferPersonalized = isOfferPersonalized
self.obfuscatedAccountIdAndroid = obfuscatedAccountIdAndroid
self.obfuscatedProfileIdAndroid = obfuscatedProfileIdAndroid
self.purchaseTokenAndroid = purchaseTokenAndroid
self.replacementModeAndroid = replacementModeAndroid
self.skus = skus
self.subscriptionOffers = subscriptionOffers
}
}
public struct RequestSubscriptionIosProps: Codable {
public var andDangerouslyFinishTransactionAutomatically: Bool?
public var appAccountToken: String?
public var quantity: Int?
public var sku: String
public var withOffer: DiscountOfferInputIOS?
public init(
andDangerouslyFinishTransactionAutomatically: Bool? = nil,
appAccountToken: String? = nil,
quantity: Int? = nil,
sku: String,
withOffer: DiscountOfferInputIOS? = nil
) {
self.andDangerouslyFinishTransactionAutomatically = andDangerouslyFinishTransactionAutomatically
self.appAccountToken = appAccountToken
self.quantity = quantity
self.sku = sku
self.withOffer = withOffer
}
}
public struct RequestSubscriptionPropsByPlatforms: Codable {
/// Android-specific subscription parameters
public var android: RequestSubscriptionAndroidProps?
/// iOS-specific subscription parameters
public var ios: RequestSubscriptionIosProps?
public init(
android: RequestSubscriptionAndroidProps? = nil,
ios: RequestSubscriptionIosProps? = nil
) {
self.android = android
self.ios = ios
}
}
// MARK: - Unions
public enum Product: Codable, ProductCommon {
case productAndroid(ProductAndroid)
case productIos(ProductIOS)
public var currency: String {
switch self {
case let .productAndroid(value):
return value.currency
case let .productIos(value):
return value.currency
}
}
public var debugDescription: String? {
switch self {
case let .productAndroid(value):
return value.debugDescription
case let .productIos(value):
return value.debugDescription
}
}
public var description: String {
switch self {
case let .productAndroid(value):
return value.description
case let .productIos(value):
return value.description
}
}
public var displayName: String? {
switch self {
case let .productAndroid(value):
return value.displayName
case let .productIos(value):
return value.displayName
}
}
public var displayPrice: String {
switch self {
case let .productAndroid(value):
return value.displayPrice
case let .productIos(value):
return value.displayPrice
}
}
public var id: String {
switch self {
case let .productAndroid(value):
return value.id
case let .productIos(value):
return value.id
}
}
public var platform: IapPlatform {
switch self {
case let .productAndroid(value):
return value.platform
case let .productIos(value):
return value.platform
}
}
public var price: Double? {
switch self {
case let .productAndroid(value):
return value.price
case let .productIos(value):
return value.price
}
}
public var title: String {
switch self {
case let .productAndroid(value):
return value.title
case let .productIos(value):
return value.title
}
}
public var type: ProductType {
switch self {
case let .productAndroid(value):
return value.type
case let .productIos(value):
return value.type
}
}
}
public enum ProductSubscription: Codable, ProductCommon {
case productSubscriptionAndroid(ProductSubscriptionAndroid)
case productSubscriptionIos(ProductSubscriptionIOS)
public var currency: String {
switch self {
case let .productSubscriptionAndroid(value):
return value.currency
case let .productSubscriptionIos(value):
return value.currency
}
}
public var debugDescription: String? {
switch self {
case let .productSubscriptionAndroid(value):
return value.debugDescription
case let .productSubscriptionIos(value):
return value.debugDescription
}
}
public var description: String {
switch self {