-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathRnIap.nitro.ts
More file actions
1369 lines (1225 loc) · 51.8 KB
/
Copy pathRnIap.nitro.ts
File metadata and controls
1369 lines (1225 loc) · 51.8 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
import type {HybridObject} from 'react-native-nitro-modules';
// ╔══════════════════════════════════════════════════════════════════════════╗
// ║ NITRO MODULE CONSTRAINTS ║
// ╠══════════════════════════════════════════════════════════════════════════╣
// ║ Nitro Modules (react-native-nitro-modules) has specific limitations ║
// ║ when generating C++/Swift/Kotlin bridge code from TypeScript types: ║
// ║ ║
// ║ 1. UNION TYPES REQUIRE 2+ VALUES ║
// ║ - Single-value unions like `type Foo = 'bar'` cause codegen errors ║
// ║ - Error: "String literal 'x' cannot be represented in C++ because ║
// ║ it is ambiguous between a string and a discriminating union enum" ║
// ║ - Solution: Add a fallback value (e.g., 'unspecified') to make 2+ ║
// ║ ║
// ║ 2. TYPES MUST BE DEFINED IN THIS FILE OR IMPORTED AS `type` ║
// ║ - Nitro codegen reads this file to generate native bridge code ║
// ║ - Interface types from types.ts can be imported and used directly ║
// ║ - Union types with 2+ values can be imported from types.ts ║
// ║ - Single-value unions must be redefined locally with extra values ║
// ╚══════════════════════════════════════════════════════════════════════════╝
// NOTE: This Nitro spec re-exports types from the generated schema (src/types.ts)
// via type aliases to avoid duplicating structure. Nitro's codegen expects the
// canonical `Nitro*` names defined here, so we keep the aliases rather than
// removing the types entirely.
import type {
ActiveSubscription,
AndroidSubscriptionOfferInput,
DeepLinkOptions,
InitConnectionConfig,
ExternalPurchaseCustomLinkNoticeResultIOS,
ExternalPurchaseCustomLinkTokenResultIOS,
// ExternalPurchaseCustomLinkTokenTypeIOS has 2 values ('acquisition' | 'services')
// so it can be imported directly from types.ts
ExternalPurchaseCustomLinkTokenTypeIOS,
ExternalPurchaseLinkResultIOS,
ExternalPurchaseNoticeResultIOS,
DeveloperBillingOptionParamsAndroid,
DeveloperProvidedBillingDetailsAndroid,
MutationFinishTransactionArgs,
ProductCommon,
PromotionalOfferJwsInputIOS,
PurchaseCommon,
PurchaseOptions,
PurchaseUpdatedListenerOptions,
VerifyPurchaseAppleOptions,
VerifyPurchaseGoogleOptions,
VerifyPurchaseHorizonOptions,
VerifyPurchaseResultAndroid,
RequestPurchaseIosProps,
RequestPurchaseResult,
RequestSubscriptionAndroidProps,
RequestSubscriptionIosProps,
UserChoiceBillingDetails,
PaymentModeIOS,
SubscriptionProductReplacementParamsAndroid,
SubResponseCodeAndroid,
WinBackOfferInputIOS,
} from '../types';
// ╔══════════════════════════════════════════════════════════════════════════╗
// ║ LOCAL TYPE DEFINITIONS FOR NITRO ║
// ╠══════════════════════════════════════════════════════════════════════════╣
// ║ Types below are defined locally because: ║
// ║ - GQL-generated type has only 1 value (Nitro requires 2+), OR ║
// ║ - Nitro codegen needs the type defined in this file for bridge gen ║
// ╚══════════════════════════════════════════════════════════════════════════╝
// ExternalPurchaseCustomLinkNoticeTypeIOS (iOS 18.1+)
// GQL type: 'browser' (1 value) → Nitro requires 2+ values
// Added 'unspecified' as fallback to satisfy Nitro constraint
export type ExternalPurchaseCustomLinkNoticeTypeIOS = 'browser' | 'unspecified';
// Platform identifier for cross-platform purchase/product data
// Defined locally for Nitro codegen (not in GQL schema)
export type IapPlatform = 'ios' | 'android';
// IAPKit purchase state enum for receipt verification
// Defined locally for Nitro codegen (IAPKit-specific, not in GQL schema)
export type IapkitPurchaseState =
| 'entitled'
| 'pending-acknowledgment'
| 'pending'
| 'canceled'
| 'expired'
| 'ready-to-consume'
| 'consumed'
| 'unknown'
| 'inauthentic';
// Store identifier for purchase origin
// Defined locally for Nitro codegen (not in GQL schema)
export type IapStore = 'unknown' | 'apple' | 'google' | 'horizon' | 'amazon';
// Purchase verification provider selection
// Defined locally for Nitro codegen (not in GQL schema)
export type PurchaseVerificationProvider = 'iapkit' | 'none';
// Billing Programs API (Android)
// GQL type exists but defined locally for Nitro codegen consistency
// Android 8.2.0+, 8.3.0+ for external-payments, 9.1.0+ for billing-choice,
// 7.0+ for user-choice-billing
export type BillingProgramAndroid =
| 'unspecified'
| 'external-content-link'
| 'external-offer'
| 'external-payments'
| 'user-choice-billing'
| 'billing-choice';
export type BillingChoiceImageLayoutAndroid =
| 'rectangular-four-by-one'
| 'rectangular-three-by-one'
| 'rectangular-two-by-two';
export type BillingChoiceScreenTypeAndroid =
| 'unspecified'
| 'developer-rendered'
| 'google-rendered';
export type DeveloperBillingTypeAndroid =
| 'developer-billing-type-unspecified'
| 'in-app'
| 'external-link';
export type InAppMessageCategoryAndroid =
| 'unknown-in-app-message-category-id'
| 'transactional';
export type InAppMessageResponseCodeAndroid =
| 'no-action-needed'
| 'subscription-status-updated';
// Developer Billing Launch Mode (Android 8.3.0+)
// Defined locally for Nitro codegen
export type DeveloperBillingLaunchModeAndroid =
| 'unspecified'
| 'launch-in-external-browser-or-app'
| 'caller-will-launch-link';
// External Link Launch Mode (Android 8.2.0+)
// Defined locally for Nitro codegen
export type ExternalLinkLaunchModeAndroid =
| 'unspecified'
| 'launch-in-external-browser-or-app'
| 'caller-will-launch-link';
// External Link Type (Android 8.2.0+)
// Defined locally for Nitro codegen
export type ExternalLinkTypeAndroid =
| 'unspecified'
| 'link-to-digital-content-offer'
| 'link-to-app-download';
// ╔══════════════════════════════════════════════════════════════════════════╗
// ║ PARAMS ║
// ╚══════════════════════════════════════════════════════════════════════════╝
// Receipt validation parameters (platform-specific)
export interface NitroReceiptValidationAppleOptions {
sku: VerifyPurchaseAppleOptions['sku'];
}
export interface NitroReceiptValidationGoogleOptions {
accessToken: VerifyPurchaseGoogleOptions['accessToken'];
isSub?: VerifyPurchaseGoogleOptions['isSub'];
packageName: VerifyPurchaseGoogleOptions['packageName'];
purchaseToken: VerifyPurchaseGoogleOptions['purchaseToken'];
sku: VerifyPurchaseGoogleOptions['sku'];
}
export interface NitroReceiptValidationHorizonOptions {
accessToken: VerifyPurchaseHorizonOptions['accessToken'];
sku: VerifyPurchaseHorizonOptions['sku'];
userId: VerifyPurchaseHorizonOptions['userId'];
}
export type NitroPurchaseUpdatedListenerOptions =
PurchaseUpdatedListenerOptions;
export interface NitroReceiptValidationParams {
apple?: NitroReceiptValidationAppleOptions | null;
google?: NitroReceiptValidationGoogleOptions | null;
horizon?: NitroReceiptValidationHorizonOptions | null;
}
// Purchase request parameters
/**
* iOS-specific purchase request parameters
*/
export interface NitroRequestPurchaseIos {
sku: RequestPurchaseIosProps['sku'];
andDangerouslyFinishTransactionAutomatically?: RequestPurchaseIosProps['andDangerouslyFinishTransactionAutomatically'];
appAccountToken?: RequestPurchaseIosProps['appAccountToken'];
quantity?: RequestPurchaseIosProps['quantity'];
withOffer?: Record<string, string> | null;
/**
* Advanced commerce data for StoreKit 2's Product.PurchaseOption.custom API.
* Used to pass attribution data (campaign tokens, affiliate IDs) during purchases.
* Data is formatted as JSON: {"signatureInfo": {"token": "<value>"}}
* @platform iOS
*/
advancedCommerceData?: RequestPurchaseIosProps['advancedCommerceData'];
/**
* Billing plan to use for annual subscriptions that offer monthly billing with
* a 12-month commitment (iOS 26.4+).
* @platform iOS
*/
billingPlanType?: RequestSubscriptionIosProps['billingPlanType'];
/**
* Compact JWS string for overriding introductory offer eligibility
* (iOS 15+, WWDC 2025). When nil, the system determines eligibility.
* @platform iOS
*/
compactJWS?: RequestSubscriptionIosProps['compactJWS'];
/**
* JWS promotional offer (iOS 15+, WWDC 2025).
* New signature format using compact JWS string for promotional offers.
* Back-deployed to iOS 15.
* @platform iOS
*/
promotionalOfferJWS?: PromotionalOfferJwsInputIOS | null;
/**
* Win-back offer to apply (iOS 18+).
* Used to re-engage churned subscribers with a discount or free trial.
* @platform iOS
*/
winBackOffer?: WinBackOfferInputIOS | null;
}
export interface NitroRequestPurchaseAndroid {
skus: RequestSubscriptionAndroidProps['skus'];
obfuscatedAccountId?: RequestSubscriptionAndroidProps['obfuscatedAccountId'];
obfuscatedProfileId?: RequestSubscriptionAndroidProps['obfuscatedProfileId'];
isOfferPersonalized?: RequestSubscriptionAndroidProps['isOfferPersonalized'];
/**
* Offer token for one-time purchase discounts (7.0+).
* Pass the offerToken from oneTimePurchaseOfferDetailsAndroid or discountOffers
* to apply a discount offer to the purchase.
*/
offerToken?: string | null;
subscriptionOffers?: AndroidSubscriptionOfferInput[] | null;
/** @deprecated Use subscriptionProductReplacementParams instead for item-level replacement (8.1.0+) */
replacementMode?: RequestSubscriptionAndroidProps['replacementMode'];
purchaseToken?: RequestSubscriptionAndroidProps['purchaseToken'];
/** Original external transaction ID for developer-billed subscription replacement (9.1.0+). */
originalExternalTransactionId?: RequestSubscriptionAndroidProps['originalExternalTransactionId'];
/** Developer billing option for External Payments (8.3.0+) or Billing Choice (9.1.0+). */
developerBillingOption?: DeveloperBillingOptionParamsAndroid | null;
/**
* Product-level replacement parameters (8.1.0+)
* Use this instead of replacementMode for item-level replacement
*/
subscriptionProductReplacementParams?: SubscriptionProductReplacementParamsAndroid | null;
}
export interface NitroPurchaseRequest {
/** @deprecated Use apple instead */
ios?: NitroRequestPurchaseIos | null;
/** @deprecated Use google instead */
android?: NitroRequestPurchaseAndroid | null;
/** Apple-specific purchase parameters */
apple?: NitroRequestPurchaseIos | null;
/** Google-specific purchase parameters */
google?: NitroRequestPurchaseAndroid | null;
}
// Available purchases parameters
/**
* iOS-specific options for getting available purchases
*/
export interface NitroAvailablePurchasesIosOptions extends PurchaseOptions {
alsoPublishToEventListener?: boolean | null;
onlyIncludeActiveItems?: boolean | null;
}
type NitroAvailablePurchasesAndroidType = 'inapp' | 'subs';
export interface NitroAvailablePurchasesAndroidOptions {
type?: NitroAvailablePurchasesAndroidType;
/**
* Include suspended subscriptions in the result (Android 8.1+).
* Suspended subscriptions have isSuspendedAndroid=true and should NOT be granted entitlements.
* Users should be directed to the subscription center to resolve payment issues.
* Default: false (only active subscriptions are returned)
*/
includeSuspended?: boolean | null;
}
export interface NitroAvailablePurchasesOptions {
ios?: NitroAvailablePurchasesIosOptions | null;
android?: NitroAvailablePurchasesAndroidOptions | null;
}
// Transaction finish parameters
/**
* iOS-specific parameters for finishing a transaction
*/
export interface NitroFinishTransactionIosParams {
transactionId: string;
}
/**
* Android-specific parameters for finishing a transaction
*/
export interface NitroFinishTransactionAndroidParams {
purchaseToken: string;
isConsumable?: MutationFinishTransactionArgs['isConsumable'];
}
/**
* Unified finish transaction parameters with platform-specific options
*/
export interface NitroFinishTransactionParams {
ios?: NitroFinishTransactionIosParams | null;
android?: NitroFinishTransactionAndroidParams | null;
}
export interface NitroDeepLinkOptionsAndroid {
skuAndroid?: DeepLinkOptions['skuAndroid'];
packageNameAndroid?: DeepLinkOptions['packageNameAndroid'];
}
/**
* Parameters for launching an external link (Android 8.2.0+)
*/
export interface NitroLaunchExternalLinkParamsAndroid {
/** The billing program (external-content-link, external-offer, or billing-choice) */
billingProgram: BillingProgramAndroid;
/** Reporting token for a developer-rendered Billing Choice external-link flow (9.1.0+). */
externalTransactionToken?: string | null;
/** The external link launch mode */
launchMode: ExternalLinkLaunchModeAndroid;
/** The type of the external link */
linkType: ExternalLinkTypeAndroid;
/** The URI where the content will be accessed from */
linkUri: string;
}
export interface NitroGetBillingChoiceInfoParamsAndroid {
billingProgram: BillingProgramAndroid;
playBillingChoiceImageLayout: BillingChoiceImageLayoutAndroid;
userLocale?: string | null;
}
export interface NitroBillingProgramInformationDialogParamsAndroid {
billingProgram: BillingProgramAndroid;
externalTransactionToken: string;
}
export interface NitroInAppMessageParamsAndroid {
categories?: InAppMessageCategoryAndroid[] | null;
}
// ╔══════════════════════════════════════════════════════════════════════════╗
// ║ TYPES ║
// ╚══════════════════════════════════════════════════════════════════════════╝
/**
* Subscription renewal information (iOS only)
*/
export interface NitroSubscriptionRenewalInfo {
autoRenewStatus: boolean;
autoRenewPreference?: string | null;
expirationReason?: number | null;
gracePeriodExpirationDate?: number | null;
currentProductID?: string | null;
platform: string;
}
/**
* Subscription status information (iOS only)
*/
export interface NitroSubscriptionStatus {
state: number;
platform: string;
renewalInfo?: NitroSubscriptionRenewalInfo | null;
}
/**
* Purchase result structure for Android operations
*/
export interface NitroPurchaseResult {
responseCode: number;
debugMessage?: string;
code: string;
message: string;
purchaseToken?: string;
}
export interface NitroBillingResultAndroid {
responseCode: number;
debugMessage?: string | null;
subResponseCode?: SubResponseCodeAndroid | null;
}
export interface NitroBillingChoiceInfoAndroid {
playBillingChoiceImageUrl: string;
playBillingLoyaltyInfo?: string | null;
}
export interface NitroInAppMessageResultAndroid {
responseCode: InAppMessageResponseCodeAndroid;
purchaseToken?: string | null;
}
export interface NitroReceiptValidationResultIOS {
isValid: boolean;
receiptData: string;
jwsRepresentation: string;
latestTransaction?: NitroPurchase | null;
}
export interface NitroReceiptValidationResultAndroid {
autoRenewing: VerifyPurchaseResultAndroid['autoRenewing'];
betaProduct: VerifyPurchaseResultAndroid['betaProduct'];
cancelDate: VerifyPurchaseResultAndroid['cancelDate'];
cancelReason: VerifyPurchaseResultAndroid['cancelReason'];
deferredDate: VerifyPurchaseResultAndroid['deferredDate'];
deferredSku: VerifyPurchaseResultAndroid['deferredSku'];
freeTrialEndDate: VerifyPurchaseResultAndroid['freeTrialEndDate'];
gracePeriodEndDate: VerifyPurchaseResultAndroid['gracePeriodEndDate'];
parentProductId: VerifyPurchaseResultAndroid['parentProductId'];
productId: VerifyPurchaseResultAndroid['productId'];
productType: VerifyPurchaseResultAndroid['productType'];
purchaseDate: VerifyPurchaseResultAndroid['purchaseDate'];
quantity: VerifyPurchaseResultAndroid['quantity'];
receiptId: VerifyPurchaseResultAndroid['receiptId'];
renewalDate: VerifyPurchaseResultAndroid['renewalDate'];
term: VerifyPurchaseResultAndroid['term'];
termSku: VerifyPurchaseResultAndroid['termSku'];
testTransaction: VerifyPurchaseResultAndroid['testTransaction'];
}
// VerifyPurchaseWithProvider types
export interface NitroVerifyPurchaseWithIapkitAppleProps {
/** The JWS token returned with the purchase response. */
jws: string;
}
export interface NitroVerifyPurchaseWithIapkitGoogleProps {
/** The token provided to the user's device when the product or subscription was purchased. */
purchaseToken: string;
}
export interface NitroVerifyPurchaseWithIapkitAmazonProps {
/** Amazon Appstore receipt id returned by PurchaseResponse.getReceipt().getReceiptId(). */
receiptId: string;
/** Use Amazon RVS Cloud Sandbox for App Tester receipts. */
sandbox?: boolean | null;
/** Amazon Appstore user id returned by PurchaseResponse.getUserData().getUserId(). */
userId?: string | null;
}
export interface NitroVerifyPurchaseWithIapkitProps {
apiKey?: string | null;
amazon?: NitroVerifyPurchaseWithIapkitAmazonProps | null;
apple?: NitroVerifyPurchaseWithIapkitAppleProps | null;
google?: NitroVerifyPurchaseWithIapkitGoogleProps | null;
}
export interface NitroVerifyPurchaseWithProviderProps {
iapkit?: NitroVerifyPurchaseWithIapkitProps | null;
provider: PurchaseVerificationProvider;
}
export interface NitroVerifyPurchaseWithIapkitResult {
isValid: boolean;
state: IapkitPurchaseState;
store: IapStore;
}
export interface NitroVerifyPurchaseWithProviderError {
code?: string | null;
message: string;
}
export interface NitroVerifyPurchaseWithProviderResult {
iapkit?: NitroVerifyPurchaseWithIapkitResult | null;
errors?: NitroVerifyPurchaseWithProviderError[] | null;
provider: PurchaseVerificationProvider;
}
/**
* Result of checking billing program availability (Android 8.2.0+)
*/
export interface NitroBillingProgramAvailabilityResultAndroid {
/** The billing program that was checked */
billingProgram: BillingProgramAndroid;
/** Billing Choice screen renderer. Populated only for available Billing Choice results. */
choiceScreenType?: BillingChoiceScreenTypeAndroid | null;
/** Whether the billing program is available for the user */
isAvailable: boolean;
/** Whether external-link payment is available for Billing Choice. */
isExternalLinkAvailable?: boolean | null;
}
/**
* Reporting details for external transactions (Android 8.2.0+)
*/
export interface NitroBillingProgramReportingDetailsAndroid {
/** The billing program that the reporting details are associated with */
billingProgram: BillingProgramAndroid;
/** External transaction token used to report transactions to Google */
externalTransactionToken: string;
}
/**
* Discount amount details for one-time purchase offers (Android)
*/
export interface NitroDiscountAmountAndroid {
discountAmountMicros: string;
formattedDiscountAmount: string;
}
/**
* Discount display information for one-time purchase offers (Android)
*/
export interface NitroDiscountDisplayInfoAndroid {
discountAmount?: NitroDiscountAmountAndroid | null;
percentageDiscount?: number | null;
}
/**
* Limited quantity information for one-time purchase offers (Android)
*/
export interface NitroLimitedQuantityInfoAndroid {
maximumQuantity: number;
remainingQuantity: number;
}
/**
* Pre-order details for one-time purchase products (Android)
*/
export interface NitroPreorderDetailsAndroid {
preorderPresaleEndTimeMillis: string;
preorderReleaseTimeMillis: string;
}
/**
* Rental details for one-time purchase products (Android)
*/
export interface NitroRentalDetailsAndroid {
rentalExpirationPeriod?: string | null;
rentalPeriod: string;
}
/**
* Valid time window for when an offer is available (Android)
*/
export interface NitroValidTimeWindowAndroid {
endTimeMillis: string;
startTimeMillis: string;
}
/**
* Android one-time purchase offer details
* Available in Google Play Billing Library 7.0+
*/
export interface NitroOneTimePurchaseOfferDetail {
discountDisplayInfo?: NitroDiscountDisplayInfoAndroid | null;
formattedPrice: string;
fullPriceMicros?: string | null;
limitedQuantityInfo?: NitroLimitedQuantityInfoAndroid | null;
offerId?: string | null;
offerTags: string[];
offerToken: string;
preorderDetailsAndroid?: NitroPreorderDetailsAndroid | null;
priceAmountMicros: string;
priceCurrencyCode: string;
purchaseOptionId?: string | null;
rentalDetailsAndroid?: NitroRentalDetailsAndroid | null;
validTimeWindow?: NitroValidTimeWindowAndroid | null;
}
export interface NitroPurchase {
id: PurchaseCommon['id'];
productId: PurchaseCommon['productId'];
transactionDate: PurchaseCommon['transactionDate'];
purchaseToken?: PurchaseCommon['purchaseToken'];
/** @deprecated Use store instead */
platform: IapPlatform;
/** Store where purchase was made */
store: IapStore;
quantity: PurchaseCommon['quantity'];
purchaseState: PurchaseCommon['purchaseState'];
isAutoRenewing: PurchaseCommon['isAutoRenewing'];
// iOS specific fields
quantityIOS?: number | null;
originalTransactionDateIOS?: number | null;
originalTransactionIdentifierIOS?: string | null;
appAccountToken?: string | null;
appBundleIdIOS?: string | null;
countryCodeIOS?: string | null;
currencyCodeIOS?: string | null;
currencySymbolIOS?: string | null;
environmentIOS?: string | null;
expirationDateIOS?: number | null;
isUpgradedIOS?: boolean | null;
offerIOS?: string | null;
ownershipTypeIOS?: string | null;
reasonIOS?: string | null;
reasonStringRepresentationIOS?: string | null;
revocationDateIOS?: number | null;
revocationReasonIOS?: string | null;
storefrontCountryCodeIOS?: string | null;
subscriptionGroupIdIOS?: string | null;
transactionReasonIOS?: string | null;
webOrderLineItemIdIOS?: string | null;
renewalInfoIOS?: NitroRenewalInfoIOS | null;
// Android specific fields
purchaseTokenAndroid?: string | null;
dataAndroid?: string | null;
signatureAndroid?: string | null;
autoRenewingAndroid?: boolean | null;
purchaseStateAndroid?: number | null;
isAcknowledgedAndroid?: boolean | null;
packageNameAndroid?: string | null;
obfuscatedAccountIdAndroid?: string | null;
obfuscatedProfileIdAndroid?: string | null;
developerPayloadAndroid?: string | null;
isSuspendedAndroid?: boolean | null;
}
/**
* Active subscription with renewalInfoIOS included
*/
export interface NitroActiveSubscription {
productId: ActiveSubscription['productId'];
isActive: ActiveSubscription['isActive'];
transactionId: ActiveSubscription['transactionId'];
purchaseToken?: ActiveSubscription['purchaseToken'];
transactionDate: ActiveSubscription['transactionDate'];
// iOS specific fields
expirationDateIOS?: ActiveSubscription['expirationDateIOS'];
environmentIOS?: ActiveSubscription['environmentIOS'];
willExpireSoon?: ActiveSubscription['willExpireSoon'];
daysUntilExpirationIOS?: ActiveSubscription['daysUntilExpirationIOS'];
renewalInfoIOS?: NitroRenewalInfoIOS | null; // 🆕 Key field for upgrade/downgrade detection
// Android specific fields
autoRenewingAndroid?: ActiveSubscription['autoRenewingAndroid'];
basePlanIdAndroid?: ActiveSubscription['basePlanIdAndroid'];
currentPlanId?: ActiveSubscription['currentPlanId'];
purchaseTokenAndroid?: ActiveSubscription['purchaseTokenAndroid'];
}
/**
* Renewal information from StoreKit 2 (iOS only)
* Must match RenewalInfoIOS from types.ts
*/
export interface NitroRenewalInfoIOS {
willAutoRenew: boolean;
autoRenewPreference?: string | null;
pendingUpgradeProductId?: string | null;
renewalDate?: number | null;
expirationReason?: string | null;
isInBillingRetry?: boolean | null;
gracePeriodExpirationDate?: number | null;
priceIncreaseStatus?: string | null;
renewalOfferType?: string | null;
renewalOfferId?: string | null;
jsonRepresentation?: string | null;
}
export interface NitroProduct {
id: ProductCommon['id'];
title: ProductCommon['title'];
description: ProductCommon['description'];
debugDescription?: ProductCommon['debugDescription'];
type: string;
displayName?: ProductCommon['displayName'];
displayPrice?: ProductCommon['displayPrice'];
currency?: ProductCommon['currency'];
price?: ProductCommon['price'];
platform: IapPlatform;
// iOS specific fields
typeIOS?: string | null;
isFamilyShareableIOS?: boolean | null;
jsonRepresentationIOS?: string | null;
pricingTermsIOS?: string | null;
subscriptionInfoIOS?: string | null;
discountsIOS?: string | null;
introductoryPriceIOS?: string | null;
introductoryPriceAsAmountIOS?: number | null;
introductoryPriceNumberOfPeriodsIOS?: number | null;
introductoryPricePaymentModeIOS: PaymentModeIOS;
introductoryPriceSubscriptionPeriodIOS?: string | null;
subscriptionGroupIdIOS?: string | null;
subscriptionPeriodNumberIOS?: number | null;
subscriptionPeriodUnitIOS?: string | null;
// Cross-platform standardized offer fields (JSON serialized)
/** Standardized subscription offers (JSON string) - cross-platform */
subscriptionOffers?: string | null;
/** Standardized discount offers for one-time purchases (JSON string) - cross-platform */
discountOffers?: string | null;
// Android specific fields
nameAndroid?: string | null;
originalPriceAndroid?: string | null;
originalPriceAmountMicrosAndroid?: number | null;
introductoryPriceCyclesAndroid?: number | null;
introductoryPricePeriodAndroid?: string | null;
introductoryPriceValueAndroid?: number | null;
subscriptionPeriodAndroid?: string | null;
freeTrialPeriodAndroid?: string | null;
subscriptionOfferDetailsAndroid?: string | null;
oneTimePurchaseOfferDetailsAndroid?: NitroOneTimePurchaseOfferDetail[] | null;
/**
* Product-level status code indicating fetch result (Android 8.0+)
* OK = product fetched successfully
* NOT_FOUND = SKU doesn't exist
* NO_OFFERS_AVAILABLE = user not eligible for any offers
* Available in Google Play Billing Library 8.0.0+
*/
productStatusAndroid?: string | null;
}
// ╔══════════════════════════════════════════════════════════════════════════╗
// ║ MAIN INTERFACE ║
// ╚══════════════════════════════════════════════════════════════════════════╝
/**
* Main RnIap HybridObject interface for native bridge
*/
export interface RnIap extends HybridObject<{ios: 'swift'; android: 'kotlin'}> {
// Connection methods
/**
* Initialize connection to the store
* @param config - Optional configuration including alternative billing mode for Android
* @returns Promise<boolean> - true if connection successful
*/
initConnection(config?: InitConnectionConfig | null): Promise<boolean>;
/**
* End connection to the store
* @returns Promise<boolean> - true if disconnection successful
*/
endConnection(): Promise<boolean>;
// Product methods
/**
* Fetch products from the store
* @param skus - Array of product SKUs to fetch
* @param type - Type of products: 'inapp' or 'subs'
* @returns Promise<NitroProduct[]> - Array of products from the store
*/
fetchProducts(skus: string[], type: string): Promise<NitroProduct[]>;
// Purchase methods (unified)
/**
* Request a purchase (unified method for both platforms)
* ⚠️ Important: This is an event-based operation, not promise-based.
* Listen for events through purchaseUpdatedListener or purchaseErrorListener.
* @param request - Platform-specific purchase request parameters
* @returns Promise<void> - Always returns void, listen for events instead
*/
requestPurchase(
request: NitroPurchaseRequest,
): Promise<RequestPurchaseResult>;
/**
* Get available purchases (unified method for both platforms)
* @param options - Platform-specific options for getting available purchases
* @returns Promise<NitroPurchase[]> - Array of available purchases
*/
getAvailablePurchases(
options?: NitroAvailablePurchasesOptions,
): Promise<NitroPurchase[]>;
/**
* Get active subscriptions with renewalInfoIOS included
* @param subscriptionIds - Optional array of subscription IDs to filter
* @returns Promise<NitroActiveSubscription[]> - Array of active subscriptions with renewalInfoIOS
*/
getActiveSubscriptions(
subscriptionIds?: string[],
): Promise<NitroActiveSubscription[]>;
/**
* Check if there are any active subscriptions
* @param subscriptionIds - Optional array of subscription IDs to filter
* @returns Promise<boolean> - True if there are active subscriptions
*/
hasActiveSubscriptions(subscriptionIds?: string[]): Promise<boolean>;
/**
* Finish a transaction (unified method for both platforms)
* @param params - Platform-specific transaction finish parameters
* @returns Promise<NitroPurchaseResult | boolean> - Result (Android) or success flag (iOS)
*/
finishTransaction(
params: NitroFinishTransactionParams,
): Promise<NitroPurchaseResult | boolean>;
// Event listener methods
/**
* Add a listener for purchase updates
* @param listener - Function to call when a purchase is updated
*/
addPurchaseUpdatedListener(
listener: (purchase: NitroPurchase) => void,
options?: NitroPurchaseUpdatedListenerOptions,
): number;
/**
* Add a listener for purchase errors
* @param listener - Function to call when a purchase error occurs
*/
addPurchaseErrorListener(
listener: (error: NitroPurchaseResult) => void,
): void;
/**
* Remove a purchase updated listener
* @param token - Token returned from addPurchaseUpdatedListener
*/
removePurchaseUpdatedListener(token: number): void;
/**
* Remove a purchase error listener
* @param listener - Function to remove from listeners
*/
removePurchaseErrorListener(
listener: (error: NitroPurchaseResult) => void,
): void;
/**
* Add a listener for iOS promoted product events
* @param listener - Function to call when a promoted product is selected in the App Store
* @platform iOS
*/
addPromotedProductListenerIOS(
listener: (product: NitroProduct) => void,
): void;
/**
* Remove a promoted product listener
* @param listener - Function to remove from listeners
* @platform iOS
*/
removePromotedProductListenerIOS(
listener: (product: NitroProduct) => void,
): void;
/**
* Get the storefront identifier for the user's App Store account (iOS only)
* @returns Promise<string> - The storefront identifier (e.g., 'USA' for United States)
* @platform iOS
*/
getStorefrontIOS(): Promise<string>;
/**
* Get the original app transaction ID if the app was purchased from the App Store (iOS only)
* @returns Promise<string | null> - The original app transaction ID or null if not purchased
* @platform iOS
*/
getAppTransactionIOS(): Promise<string | null>;
/**
* Request the promoted product from the App Store (iOS only)
* @returns Promise<NitroProduct | null> - The promoted product or null if none available
* @platform iOS
*/
requestPromotedProductIOS(): Promise<NitroProduct | null>;
/**
* Retrieve the currently promoted product without initiating a purchase flow (iOS only)
* @returns Promise<NitroProduct | null> - The promoted product or null if none available
* @platform iOS
*/
getPromotedProductIOS(): Promise<NitroProduct | null>;
/**
* Buy the promoted product from the App Store (iOS only)
* @returns Promise<void>
* @platform iOS
*/
buyPromotedProductIOS(): Promise<void>;
/**
* Present the code redemption sheet for offer codes (iOS only)
* @returns Promise<boolean> - True if the sheet was presented successfully
* @platform iOS
*/
presentCodeRedemptionSheetIOS(): Promise<boolean>;
/**
* Clear unfinished transactions (iOS only)
* @returns Promise<void>
* @platform iOS
*/
clearTransactionIOS(): Promise<void>;
/**
* Begin a refund request for a product (iOS 15+ only)
* @param sku - The product SKU to refund
* @returns Promise<string | null> - The refund status or null if not available
* @platform iOS
*/
beginRefundRequestIOS(sku: string): Promise<string | null>;
/**
* Get subscription status for a product (iOS only)
* @param sku - The product SKU
* @returns Promise<NitroSubscriptionStatus[] | null> - Array of subscription status objects
* @platform iOS
*/
subscriptionStatusIOS(sku: string): Promise<NitroSubscriptionStatus[] | null>;
/**
* Get current entitlement for a product (iOS only)
* @param sku - The product SKU
* @returns Promise<NitroPurchase | null> - Current entitlement or null
* @platform iOS
*/
currentEntitlementIOS(sku: string): Promise<NitroPurchase | null>;
/**
* Get latest transaction for a product (iOS only)
* @param sku - The product SKU
* @returns Promise<NitroPurchase | null> - Latest transaction or null
* @platform iOS
*/
latestTransactionIOS(sku: string): Promise<NitroPurchase | null>;
/**
* Get pending transactions (iOS only)
* @returns Promise<NitroPurchase[]> - Array of pending transactions
* @platform iOS
*/
getPendingTransactionsIOS(): Promise<NitroPurchase[]>;
/**
* Get the full StoreKit 2 transaction history as PurchaseIOS values.
* Requires SK2ConsumableTransactionHistory Info.plist key for finished consumables (iOS 18+).
* @returns Promise<NitroPurchase[]> - Array of all transactions
* @platform iOS
*/
getAllTransactionsIOS(): Promise<NitroPurchase[]>;
/**
* Sync with the App Store (iOS only)
* @returns Promise<boolean> - Success flag
* @platform iOS
*/
syncIOS(): Promise<boolean>;
/**
* Show manage subscriptions screen (iOS only)
* @returns Promise<NitroPurchase[]> - Array of updated subscriptions with renewal info
* @platform iOS
*/
showManageSubscriptionsIOS(): Promise<NitroPurchase[]>;
/**
* Deep link to the native subscription management UI (iOS only)
* @returns Promise<boolean> - True if the deep link request succeeded
* @platform iOS
*/
deepLinkToSubscriptionsIOS(): Promise<boolean>;
/**
* Check if user is eligible for intro offer (iOS only)
* @param groupID - The subscription group ID
* @returns Promise<boolean> - Eligibility status
* @platform iOS
*/
isEligibleForIntroOfferIOS(groupID: string): Promise<boolean>;
/**
* Get receipt data (iOS only)
*
* ⚠️ **IMPORTANT**: iOS receipts are cumulative and contain ALL transactions for the app,
* not just the most recent one. The receipt data does not change between purchases.
*
* **For individual purchase validation, use `getTransactionJwsIOS(productId)` instead.**
*
* This returns the App Store Receipt, which:
* - Contains all purchase history for the app
* - Does not update immediately after finishTransaction()
* - May be unavailable immediately after purchase (throws receipt-failed error)
* - Requires parsing to extract specific transactions
*
* @returns Promise<string> - Base64 encoded receipt data containing all app transactions
* @throws {Error} receipt-failed if receipt is not available (e.g., immediately after purchase)
* @platform iOS
* @see getTransactionJwsIOS for validating individual transactions (recommended)
*/
getReceiptDataIOS(): Promise<string>;
/**
* Alias for getReceiptDataIOS maintained for compatibility (iOS only)