react-native-iap 14.3.7 → 14.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/README.md +1 -1
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +61 -11
  4. package/ios/HybridRnIap.swift +47 -12
  5. package/lib/module/hooks/useIAP.js +31 -21
  6. package/lib/module/hooks/useIAP.js.map +1 -1
  7. package/lib/module/index.js +580 -695
  8. package/lib/module/index.js.map +1 -1
  9. package/lib/module/types.js +12 -0
  10. package/lib/module/types.js.map +1 -1
  11. package/lib/module/utils/purchase.js +22 -0
  12. package/lib/module/utils/purchase.js.map +1 -0
  13. package/lib/module/utils.js +43 -0
  14. package/lib/module/utils.js.map +1 -0
  15. package/lib/typescript/plugin/src/withIAP.d.ts +1 -0
  16. package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
  17. package/lib/typescript/src/hooks/useIAP.d.ts +4 -5
  18. package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
  19. package/lib/typescript/src/index.d.ts +57 -176
  20. package/lib/typescript/src/index.d.ts.map +1 -1
  21. package/lib/typescript/src/specs/RnIap.nitro.d.ts +113 -154
  22. package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
  23. package/lib/typescript/src/types.d.ts +99 -76
  24. package/lib/typescript/src/types.d.ts.map +1 -1
  25. package/lib/typescript/src/utils/purchase.d.ts +4 -0
  26. package/lib/typescript/src/utils/purchase.d.ts.map +1 -0
  27. package/lib/typescript/src/utils.d.ts +8 -0
  28. package/lib/typescript/src/utils.d.ts.map +1 -0
  29. package/nitrogen/generated/android/NitroIap+autolinking.cmake +1 -1
  30. package/nitrogen/generated/android/c++/{JNitroSubscriptionOffer.hpp → JAndroidSubscriptionOfferInput.hpp} +15 -15
  31. package/nitrogen/generated/android/c++/JFunc_void_NitroProduct.hpp +2 -0
  32. package/nitrogen/generated/android/c++/JFunc_void_NitroPurchase.hpp +4 -0
  33. package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +16 -16
  34. package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +1 -1
  35. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidOptions.hpp +6 -5
  36. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidType.hpp +59 -0
  37. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesOptions.hpp +2 -1
  38. package/nitrogen/generated/android/c++/JNitroProduct.hpp +22 -20
  39. package/nitrogen/generated/android/c++/JNitroPurchase.hpp +12 -8
  40. package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +2 -2
  41. package/nitrogen/generated/android/c++/JNitroReceiptValidationAndroidOptions.hpp +10 -10
  42. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultAndroid.hpp +6 -6
  43. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultIOS.hpp +4 -0
  44. package/nitrogen/generated/android/c++/JNitroRequestPurchaseAndroid.hpp +7 -7
  45. package/nitrogen/generated/android/c++/JRequestPurchaseResult.cpp +39 -0
  46. package/nitrogen/generated/android/c++/JRequestPurchaseResult.hpp +68 -53
  47. package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.hpp +4 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/{NitroSubscriptionOffer.kt → AndroidSubscriptionOfferInput.kt} +5 -5
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +1 -1
  50. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidOptions.kt +1 -1
  51. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidType.kt +21 -0
  52. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroProduct.kt +11 -11
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchase.kt +2 -2
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationAndroidOptions.kt +4 -4
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultAndroid.kt +2 -2
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseAndroid.kt +1 -1
  57. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/RequestPurchaseResult.kt +31 -13
  58. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +4 -4
  59. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +99 -64
  60. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +6 -6
  61. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +10 -10
  62. package/nitrogen/generated/ios/swift/{NitroSubscriptionOffer.swift → AndroidSubscriptionOfferInput.swift} +13 -13
  63. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__std__vector_std__variant_PurchaseAndroid__PurchaseIOS____.swift +81 -0
  64. package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +1 -1
  65. package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +35 -7
  66. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidOptions.swift +7 -14
  67. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidType.swift +40 -0
  68. package/nitrogen/generated/ios/swift/NitroProduct.swift +72 -72
  69. package/nitrogen/generated/ios/swift/NitroPurchase.swift +8 -8
  70. package/nitrogen/generated/ios/swift/NitroReceiptValidationAndroidOptions.swift +21 -21
  71. package/nitrogen/generated/ios/swift/NitroReceiptValidationResultAndroid.swift +37 -11
  72. package/nitrogen/generated/ios/swift/NitroRequestPurchaseAndroid.swift +11 -11
  73. package/nitrogen/generated/ios/swift/RequestPurchaseResult.swift +8 -137
  74. package/nitrogen/generated/shared/c++/{NitroSubscriptionOffer.hpp → AndroidSubscriptionOfferInput.hpp} +15 -15
  75. package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +9 -6
  76. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidOptions.hpp +8 -7
  77. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidType.hpp +76 -0
  78. package/nitrogen/generated/shared/c++/NitroProduct.hpp +24 -22
  79. package/nitrogen/generated/shared/c++/NitroPurchase.hpp +15 -10
  80. package/nitrogen/generated/shared/c++/NitroReceiptValidationAndroidOptions.hpp +10 -10
  81. package/nitrogen/generated/shared/c++/NitroReceiptValidationResultAndroid.hpp +9 -9
  82. package/nitrogen/generated/shared/c++/NitroRequestPurchaseAndroid.hpp +8 -8
  83. package/package.json +2 -2
  84. package/plugin/build/withIAP.d.ts +1 -0
  85. package/plugin/build/withIAP.js +8 -2
  86. package/plugin/src/withIAP.ts +13 -3
  87. package/src/hooks/useIAP.ts +63 -32
  88. package/src/index.ts +716 -790
  89. package/src/specs/RnIap.nitro.ts +131 -163
  90. package/src/types.ts +131 -85
  91. package/src/utils/purchase.ts +32 -0
  92. package/src/utils.ts +68 -0
  93. package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.cpp +0 -26
  94. package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.hpp +0 -80
  95. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS.kt +0 -42
  96. package/nitrogen/generated/ios/swift/Func_void_RequestPurchaseResult.swift +0 -47
  97. package/nitrogen/generated/ios/swift/Variant_PurchaseAndroid_PurchaseIOS.swift +0 -18
  98. package/nitrogen/generated/shared/c++/RequestPurchaseResult.hpp +0 -78
package/src/types.ts CHANGED
@@ -126,10 +126,7 @@ export enum ErrorCode {
126
126
  UserError = 'USER_ERROR'
127
127
  }
128
128
 
129
- export interface FetchProductsResult {
130
- products?: (Product[] | null);
131
- subscriptions?: (ProductSubscription[] | null);
132
- }
129
+ export type FetchProductsResult = Product[] | ProductSubscription[] | null;
133
130
 
134
131
  export type IapEvent = 'promoted-product-ios' | 'purchase-error' | 'purchase-updated';
135
132
 
@@ -137,57 +134,46 @@ export type IapPlatform = 'android' | 'ios';
137
134
 
138
135
  export interface Mutation {
139
136
  /** Acknowledge a non-consumable purchase or subscription */
140
- acknowledgePurchaseAndroid: Promise<VoidResult>;
137
+ acknowledgePurchaseAndroid: Promise<boolean>;
141
138
  /** Initiate a refund request for a product (iOS 15+) */
142
- beginRefundRequestIOS: Promise<RefundResultIOS>;
139
+ beginRefundRequestIOS?: Promise<(string | null)>;
143
140
  /** Clear pending transactions from the StoreKit payment queue */
144
- clearTransactionIOS: Promise<VoidResult>;
141
+ clearTransactionIOS: Promise<boolean>;
145
142
  /** Consume a purchase token so it can be repurchased */
146
- consumePurchaseAndroid: Promise<VoidResult>;
143
+ consumePurchaseAndroid: Promise<boolean>;
147
144
  /** Open the native subscription management surface */
148
- deepLinkToSubscriptions: Promise<VoidResult>;
145
+ deepLinkToSubscriptions: Promise<void>;
149
146
  /** Close the platform billing connection */
150
147
  endConnection: Promise<boolean>;
151
148
  /** Finish a transaction after validating receipts */
152
- finishTransaction: Promise<VoidResult>;
149
+ finishTransaction: Promise<void>;
153
150
  /** Establish the platform billing connection */
154
151
  initConnection: Promise<boolean>;
155
152
  /** Present the App Store code redemption sheet */
156
- presentCodeRedemptionSheetIOS: Promise<VoidResult>;
153
+ presentCodeRedemptionSheetIOS: Promise<boolean>;
157
154
  /** Initiate a purchase flow; rely on events for final state */
158
- requestPurchase?: Promise<(RequestPurchaseResult | null)>;
155
+ requestPurchase?: Promise<(Purchase | Purchase[] | null)>;
159
156
  /** Purchase the promoted product surfaced by the App Store */
160
- requestPurchaseOnPromotedProductIOS: Promise<PurchaseIOS>;
157
+ requestPurchaseOnPromotedProductIOS: Promise<boolean>;
161
158
  /** Restore completed purchases across platforms */
162
- restorePurchases: Promise<VoidResult>;
159
+ restorePurchases: Promise<void>;
163
160
  /** Open subscription management UI and return changed purchases (iOS 15+) */
164
161
  showManageSubscriptionsIOS: Promise<PurchaseIOS[]>;
165
162
  /** Force a StoreKit sync for transactions (iOS 15+) */
166
- syncIOS: Promise<VoidResult>;
163
+ syncIOS: Promise<boolean>;
167
164
  /** Validate purchase receipts with the configured providers */
168
165
  validateReceipt: Promise<ReceiptValidationResult>;
169
166
  }
170
167
 
171
168
 
172
- export interface MutationAcknowledgePurchaseAndroidArgs {
173
- purchaseToken: string;
174
- }
175
-
176
169
 
177
- export interface MutationBeginRefundRequestIosArgs {
178
- sku: string;
179
- }
170
+ export type MutationAcknowledgePurchaseAndroidArgs = string;
180
171
 
172
+ export type MutationBeginRefundRequestIosArgs = string;
181
173
 
182
- export interface MutationConsumePurchaseAndroidArgs {
183
- purchaseToken: string;
184
- }
185
-
186
-
187
- export interface MutationDeepLinkToSubscriptionsArgs {
188
- options?: (DeepLinkOptions | null);
189
- }
174
+ export type MutationConsumePurchaseAndroidArgs = string;
190
175
 
176
+ export type MutationDeepLinkToSubscriptionsArgs = (DeepLinkOptions | null) | undefined;
191
177
 
192
178
  export interface MutationFinishTransactionArgs {
193
179
  isConsumable?: (boolean | null);
@@ -195,14 +181,20 @@ export interface MutationFinishTransactionArgs {
195
181
  }
196
182
 
197
183
 
198
- export interface MutationRequestPurchaseArgs {
199
- params: RequestPurchaseProps;
200
- }
184
+ export type MutationRequestPurchaseArgs =
185
+ | {
186
+ /** Per-platform purchase request props */
187
+ request: RequestPurchasePropsByPlatforms;
188
+ type: 'in-app';
189
+ }
190
+ | {
191
+ /** Per-platform subscription request props */
192
+ request: RequestSubscriptionPropsByPlatforms;
193
+ type: 'subs';
194
+ };
201
195
 
202
196
 
203
- export interface MutationValidateReceiptArgs {
204
- options: ReceiptValidationProps;
205
- }
197
+ export type MutationValidateReceiptArgs = ReceiptValidationProps;
206
198
 
207
199
  export type PaymentModeIOS = 'empty' | 'free-trial' | 'pay-as-you-go' | 'pay-up-front';
208
200
 
@@ -440,9 +432,9 @@ export type PurchaseState = 'deferred' | 'failed' | 'pending' | 'purchased' | 'r
440
432
 
441
433
  export interface Query {
442
434
  /** Get current StoreKit 2 entitlements (iOS 15+) */
443
- currentEntitlementIOS: Promise<EntitlementIOS[]>;
435
+ currentEntitlementIOS?: Promise<(PurchaseIOS | null)>;
444
436
  /** Retrieve products or subscriptions from the store */
445
- fetchProducts: Promise<FetchProductsResult>;
437
+ fetchProducts: Promise<(Product[] | ProductSubscription[] | null)>;
446
438
  /** Get active subscriptions (filters by subscriptionIds when provided) */
447
439
  getActiveSubscriptions: Promise<ActiveSubscription[]>;
448
440
  /** Fetch the current app transaction (iOS 16+) */
@@ -454,14 +446,14 @@ export interface Query {
454
446
  /** Get the currently promoted product (iOS 11+) */
455
447
  getPromotedProductIOS?: Promise<(ProductIOS | null)>;
456
448
  /** Get base64-encoded receipt data for validation */
457
- getReceiptDataIOS: Promise<string>;
449
+ getReceiptDataIOS?: Promise<(string | null)>;
458
450
  /** Get the current App Store storefront country code */
459
451
  getStorefrontIOS: Promise<string>;
460
452
  /** Get the transaction JWS (StoreKit 2) */
461
- getTransactionJwsIOS: Promise<string>;
453
+ getTransactionJwsIOS?: Promise<(string | null)>;
462
454
  /** Check whether the user has active subscriptions */
463
455
  hasActiveSubscriptions: Promise<boolean>;
464
- /** Check introductory offer eligibility for specific products */
456
+ /** Check introductory offer eligibility for a subscription group */
465
457
  isEligibleForIntroOfferIOS: Promise<boolean>;
466
458
  /** Verify a StoreKit 2 transaction signature */
467
459
  isTransactionVerifiedIOS: Promise<boolean>;
@@ -469,57 +461,33 @@ export interface Query {
469
461
  latestTransactionIOS?: Promise<(PurchaseIOS | null)>;
470
462
  /** Get StoreKit 2 subscription status details (iOS 15+) */
471
463
  subscriptionStatusIOS: Promise<SubscriptionStatusIOS[]>;
464
+ /** Validate a receipt for a specific product */
465
+ validateReceiptIOS: Promise<ReceiptValidationResultIOS>;
472
466
  }
473
467
 
474
468
 
475
- export interface QueryCurrentEntitlementIosArgs {
476
- skus?: (string[] | null);
477
- }
478
-
479
-
480
- export interface QueryFetchProductsArgs {
481
- params: ProductRequest;
482
- }
483
-
484
-
485
- export interface QueryGetActiveSubscriptionsArgs {
486
- subscriptionIds?: (string[] | null);
487
- }
488
469
 
470
+ export type QueryCurrentEntitlementIosArgs = string;
489
471
 
490
- export interface QueryGetAvailablePurchasesArgs {
491
- options?: (PurchaseOptions | null);
492
- }
493
-
494
-
495
- export interface QueryGetTransactionJwsIosArgs {
496
- transactionId: string;
497
- }
498
-
472
+ export type QueryFetchProductsArgs = ProductRequest;
499
473
 
500
- export interface QueryHasActiveSubscriptionsArgs {
501
- subscriptionIds?: (string[] | null);
502
- }
474
+ export type QueryGetActiveSubscriptionsArgs = (string[] | null) | undefined;
503
475
 
476
+ export type QueryGetAvailablePurchasesArgs = (PurchaseOptions | null) | undefined;
504
477
 
505
- export interface QueryIsEligibleForIntroOfferIosArgs {
506
- productIds: string[];
507
- }
478
+ export type QueryGetTransactionJwsIosArgs = string;
508
479
 
480
+ export type QueryHasActiveSubscriptionsArgs = (string[] | null) | undefined;
509
481
 
510
- export interface QueryIsTransactionVerifiedIosArgs {
511
- transactionId: string;
512
- }
482
+ export type QueryIsEligibleForIntroOfferIosArgs = string;
513
483
 
484
+ export type QueryIsTransactionVerifiedIosArgs = string;
514
485
 
515
- export interface QueryLatestTransactionIosArgs {
516
- sku: string;
517
- }
486
+ export type QueryLatestTransactionIosArgs = string;
518
487
 
488
+ export type QuerySubscriptionStatusIosArgs = string;
519
489
 
520
- export interface QuerySubscriptionStatusIosArgs {
521
- skus?: (string[] | null);
522
- }
490
+ export type QueryValidateReceiptIosArgs = ReceiptValidationProps;
523
491
 
524
492
  export interface ReceiptValidationAndroidOptions {
525
493
  accessToken: string;
@@ -623,10 +591,7 @@ export interface RequestPurchasePropsByPlatforms {
623
591
  ios?: (RequestPurchaseIosProps | null);
624
592
  }
625
593
 
626
- export interface RequestPurchaseResult {
627
- purchase?: (Purchase | null);
628
- purchases?: (Purchase[] | null);
629
- }
594
+ export type RequestPurchaseResult = Purchase | Purchase[] | null;
630
595
 
631
596
  export interface RequestSubscriptionAndroidProps {
632
597
  /** Personalized offer flag */
@@ -669,6 +634,7 @@ export interface Subscription {
669
634
  purchaseUpdated: Purchase;
670
635
  }
671
636
 
637
+
672
638
  export interface SubscriptionInfoIOS {
673
639
  introductoryOffer?: (SubscriptionOfferIOS | null);
674
640
  promotionalOffers?: (SubscriptionOfferIOS[] | null);
@@ -700,6 +666,86 @@ export interface SubscriptionStatusIOS {
700
666
  state: string;
701
667
  }
702
668
 
703
- export interface VoidResult {
704
- success: boolean;
705
- }
669
+ export type VoidResult = void;
670
+
671
+ // -- Query helper types (auto-generated)
672
+ export type QueryArgsMap = {
673
+ currentEntitlementIOS: QueryCurrentEntitlementIosArgs;
674
+ fetchProducts: QueryFetchProductsArgs;
675
+ getActiveSubscriptions: QueryGetActiveSubscriptionsArgs;
676
+ getAppTransactionIOS: never;
677
+ getAvailablePurchases: QueryGetAvailablePurchasesArgs;
678
+ getPendingTransactionsIOS: never;
679
+ getPromotedProductIOS: never;
680
+ getReceiptDataIOS: never;
681
+ getStorefrontIOS: never;
682
+ getTransactionJwsIOS: QueryGetTransactionJwsIosArgs;
683
+ hasActiveSubscriptions: QueryHasActiveSubscriptionsArgs;
684
+ isEligibleForIntroOfferIOS: QueryIsEligibleForIntroOfferIosArgs;
685
+ isTransactionVerifiedIOS: QueryIsTransactionVerifiedIosArgs;
686
+ latestTransactionIOS: QueryLatestTransactionIosArgs;
687
+ subscriptionStatusIOS: QuerySubscriptionStatusIosArgs;
688
+ validateReceiptIOS: QueryValidateReceiptIosArgs;
689
+ };
690
+
691
+ export type QueryField<K extends keyof Query> =
692
+ QueryArgsMap[K] extends never
693
+ ? () => NonNullable<Query[K]>
694
+ : undefined extends QueryArgsMap[K]
695
+ ? (args?: QueryArgsMap[K]) => NonNullable<Query[K]>
696
+ : (args: QueryArgsMap[K]) => NonNullable<Query[K]>;
697
+
698
+ export type QueryFieldMap = {
699
+ [K in keyof Query]?: QueryField<K>;
700
+ };
701
+ // -- End query helper types
702
+
703
+ // -- Mutation helper types (auto-generated)
704
+ export type MutationArgsMap = {
705
+ acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidArgs;
706
+ beginRefundRequestIOS: MutationBeginRefundRequestIosArgs;
707
+ clearTransactionIOS: never;
708
+ consumePurchaseAndroid: MutationConsumePurchaseAndroidArgs;
709
+ deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsArgs;
710
+ endConnection: never;
711
+ finishTransaction: MutationFinishTransactionArgs;
712
+ initConnection: never;
713
+ presentCodeRedemptionSheetIOS: never;
714
+ requestPurchase: MutationRequestPurchaseArgs;
715
+ requestPurchaseOnPromotedProductIOS: never;
716
+ restorePurchases: never;
717
+ showManageSubscriptionsIOS: never;
718
+ syncIOS: never;
719
+ validateReceipt: MutationValidateReceiptArgs;
720
+ };
721
+
722
+ export type MutationField<K extends keyof Mutation> =
723
+ MutationArgsMap[K] extends never
724
+ ? () => NonNullable<Mutation[K]>
725
+ : undefined extends MutationArgsMap[K]
726
+ ? (args?: MutationArgsMap[K]) => NonNullable<Mutation[K]>
727
+ : (args: MutationArgsMap[K]) => NonNullable<Mutation[K]>;
728
+
729
+ export type MutationFieldMap = {
730
+ [K in keyof Mutation]?: MutationField<K>;
731
+ };
732
+ // -- End mutation helper types
733
+
734
+ // -- Subscription helper types (auto-generated)
735
+ export type SubscriptionArgsMap = {
736
+ promotedProductIOS: never;
737
+ purchaseError: never;
738
+ purchaseUpdated: never;
739
+ };
740
+
741
+ export type SubscriptionField<K extends keyof Subscription> =
742
+ SubscriptionArgsMap[K] extends never
743
+ ? () => NonNullable<Subscription[K]>
744
+ : undefined extends SubscriptionArgsMap[K]
745
+ ? (args?: SubscriptionArgsMap[K]) => NonNullable<Subscription[K]>
746
+ : (args: SubscriptionArgsMap[K]) => NonNullable<Subscription[K]>;
747
+
748
+ export type SubscriptionFieldMap = {
749
+ [K in keyof Subscription]?: SubscriptionField<K>;
750
+ };
751
+ // -- End subscription helper types
@@ -0,0 +1,32 @@
1
+ import {normalizeErrorCodeFromNative} from './errorMapping';
2
+ import type {NitroPurchaseResult} from '../specs/RnIap.nitro';
3
+
4
+ export type PurchaseOperationContext =
5
+ | 'finishTransaction'
6
+ | 'acknowledgePurchaseAndroid'
7
+ | 'consumePurchaseAndroid';
8
+
9
+ export const getSuccessFromPurchaseVariant = (
10
+ variant: NitroPurchaseResult | boolean,
11
+ context: PurchaseOperationContext,
12
+ ): boolean => {
13
+ if (typeof variant === 'boolean') {
14
+ return variant;
15
+ }
16
+
17
+ if (variant.responseCode === 0) {
18
+ return true;
19
+ }
20
+
21
+ const normalizedCode = normalizeErrorCodeFromNative(variant.code);
22
+ const errorPayload = {
23
+ code: normalizedCode,
24
+ nativeCode: variant.code,
25
+ message: variant.message || `Failed to ${context}`,
26
+ responseCode: variant.responseCode,
27
+ debugMessage: variant.debugMessage,
28
+ purchaseToken: variant.purchaseToken,
29
+ };
30
+
31
+ throw new Error(JSON.stringify(errorPayload));
32
+ };
package/src/utils.ts ADDED
@@ -0,0 +1,68 @@
1
+ import type {AppTransaction} from './types';
2
+
3
+ /**
4
+ * Parse the string payload returned by the native getAppTransactionIOS call into
5
+ * a strongly typed AppTransaction object. Returns null when the payload cannot
6
+ * be safely converted.
7
+ */
8
+ export const parseAppTransactionPayload = (
9
+ payload: string,
10
+ ): AppTransaction | null => {
11
+ try {
12
+ const raw = JSON.parse(payload) as Record<string, unknown>;
13
+ if (raw == null || typeof raw !== 'object') {
14
+ return null;
15
+ }
16
+
17
+ const appId = Number(raw.appId);
18
+ const appVersionId = Number(raw.appVersionId);
19
+ const originalPurchaseDate = Number(raw.originalPurchaseDate);
20
+ const signedDate = Number(raw.signedDate);
21
+
22
+ if (
23
+ Number.isNaN(appId) ||
24
+ Number.isNaN(appVersionId) ||
25
+ Number.isNaN(originalPurchaseDate) ||
26
+ Number.isNaN(signedDate)
27
+ ) {
28
+ return null;
29
+ }
30
+
31
+ const preorderDateRaw = raw.preorderDate;
32
+ const preorderDate =
33
+ preorderDateRaw == null ? null : Number(preorderDateRaw);
34
+
35
+ return {
36
+ appId,
37
+ appTransactionId:
38
+ typeof raw.appTransactionId === 'string' ? raw.appTransactionId : null,
39
+ appVersion: typeof raw.appVersion === 'string' ? raw.appVersion : '',
40
+ appVersionId,
41
+ bundleId: typeof raw.bundleId === 'string' ? raw.bundleId : '',
42
+ deviceVerification:
43
+ typeof raw.deviceVerification === 'string'
44
+ ? raw.deviceVerification
45
+ : '',
46
+ deviceVerificationNonce:
47
+ typeof raw.deviceVerificationNonce === 'string'
48
+ ? raw.deviceVerificationNonce
49
+ : '',
50
+ environment: typeof raw.environment === 'string' ? raw.environment : '',
51
+ originalAppVersion:
52
+ typeof raw.originalAppVersion === 'string'
53
+ ? raw.originalAppVersion
54
+ : '',
55
+ originalPlatform:
56
+ typeof raw.originalPlatform === 'string' ? raw.originalPlatform : null,
57
+ originalPurchaseDate,
58
+ preorderDate:
59
+ preorderDate != null && !Number.isNaN(preorderDate)
60
+ ? preorderDate
61
+ : null,
62
+ signedDate,
63
+ };
64
+ } catch (error) {
65
+ console.warn('[parseAppTransactionPayload] Failed to parse payload', error);
66
+ return null;
67
+ }
68
+ };
@@ -1,26 +0,0 @@
1
- ///
2
- /// JVariant_PurchaseAndroid_PurchaseIOS.cpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- #include "JVariant_PurchaseAndroid_PurchaseIOS.hpp"
9
-
10
- namespace margelo::nitro::iap {
11
- /**
12
- * Converts JVariant_PurchaseAndroid_PurchaseIOS to std::variant<PurchaseAndroid, PurchaseIOS>
13
- */
14
- std::variant<PurchaseAndroid, PurchaseIOS> JVariant_PurchaseAndroid_PurchaseIOS::toCpp() const {
15
- if (isInstanceOf(JVariant_PurchaseAndroid_PurchaseIOS_impl::First::javaClassStatic())) {
16
- // It's a `PurchaseAndroid`
17
- auto jniValue = static_cast<const JVariant_PurchaseAndroid_PurchaseIOS_impl::First*>(this)->getValue();
18
- return jniValue->toCpp();
19
- } else if (isInstanceOf(JVariant_PurchaseAndroid_PurchaseIOS_impl::Second::javaClassStatic())) {
20
- // It's a `PurchaseIOS`
21
- auto jniValue = static_cast<const JVariant_PurchaseAndroid_PurchaseIOS_impl::Second*>(this)->getValue();
22
- return jniValue->toCpp();
23
- }
24
- throw std::invalid_argument("Variant is unknown Kotlin instance!");
25
- }
26
- } // namespace margelo::nitro::iap
@@ -1,80 +0,0 @@
1
- ///
2
- /// JVariant_PurchaseAndroid_PurchaseIOS.hpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- #pragma once
9
-
10
- #include <fbjni/fbjni.h>
11
- #include <variant>
12
-
13
- #include "PurchaseAndroid.hpp"
14
- #include "PurchaseIOS.hpp"
15
- #include <variant>
16
- #include "JPurchaseAndroid.hpp"
17
- #include <optional>
18
- #include <string>
19
- #include <vector>
20
- #include "IapPlatform.hpp"
21
- #include "JIapPlatform.hpp"
22
- #include "PurchaseState.hpp"
23
- #include "JPurchaseState.hpp"
24
- #include "JPurchaseIOS.hpp"
25
- #include "PurchaseOfferIOS.hpp"
26
- #include "JPurchaseOfferIOS.hpp"
27
-
28
- namespace margelo::nitro::iap {
29
-
30
- using namespace facebook;
31
-
32
- /**
33
- * The C++ JNI bridge between the C++ std::variant and the Java class "Variant_PurchaseAndroid_PurchaseIOS".
34
- */
35
- class JVariant_PurchaseAndroid_PurchaseIOS: public jni::JavaClass<JVariant_PurchaseAndroid_PurchaseIOS> {
36
- public:
37
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS;";
38
-
39
- static jni::local_ref<JVariant_PurchaseAndroid_PurchaseIOS> create_0(jni::alias_ref<JPurchaseAndroid> value) {
40
- static const auto method = javaClassStatic()->getStaticMethod<JVariant_PurchaseAndroid_PurchaseIOS(jni::alias_ref<JPurchaseAndroid>)>("create");
41
- return method(javaClassStatic(), value);
42
- }
43
- static jni::local_ref<JVariant_PurchaseAndroid_PurchaseIOS> create_1(jni::alias_ref<JPurchaseIOS> value) {
44
- static const auto method = javaClassStatic()->getStaticMethod<JVariant_PurchaseAndroid_PurchaseIOS(jni::alias_ref<JPurchaseIOS>)>("create");
45
- return method(javaClassStatic(), value);
46
- }
47
-
48
- static jni::local_ref<JVariant_PurchaseAndroid_PurchaseIOS> fromCpp(const std::variant<PurchaseAndroid, PurchaseIOS>& variant) {
49
- switch (variant.index()) {
50
- case 0: return create_0(JPurchaseAndroid::fromCpp(std::get<0>(variant)));
51
- case 1: return create_1(JPurchaseIOS::fromCpp(std::get<1>(variant)));
52
- default: throw std::invalid_argument("Variant holds unknown index! (" + std::to_string(variant.index()) + ")");
53
- }
54
- }
55
-
56
- [[nodiscard]] std::variant<PurchaseAndroid, PurchaseIOS> toCpp() const;
57
- };
58
-
59
- namespace JVariant_PurchaseAndroid_PurchaseIOS_impl {
60
- class First: public jni::JavaClass<First, JVariant_PurchaseAndroid_PurchaseIOS> {
61
- public:
62
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS$First;";
63
-
64
- [[nodiscard]] jni::local_ref<JPurchaseAndroid> getValue() const {
65
- static const auto field = javaClassStatic()->getField<JPurchaseAndroid>("value");
66
- return getFieldValue(field);
67
- }
68
- };
69
-
70
- class Second: public jni::JavaClass<Second, JVariant_PurchaseAndroid_PurchaseIOS> {
71
- public:
72
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS$Second;";
73
-
74
- [[nodiscard]] jni::local_ref<JPurchaseIOS> getValue() const {
75
- static const auto field = javaClassStatic()->getField<JPurchaseIOS>("value");
76
- return getFieldValue(field);
77
- }
78
- };
79
- } // namespace JVariant_PurchaseAndroid_PurchaseIOS_impl
80
- } // namespace margelo::nitro::iap
@@ -1,42 +0,0 @@
1
- ///
2
- /// Variant_PurchaseAndroid_PurchaseIOS.kt
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- package com.margelo.nitro.iap
9
-
10
- import com.facebook.proguard.annotations.DoNotStrip
11
-
12
-
13
- /**
14
- * Represents the TypeScript variant "PurchaseAndroid|PurchaseIOS".
15
- */
16
- @Suppress("ClassName")
17
- @DoNotStrip
18
- sealed class Variant_PurchaseAndroid_PurchaseIOS {
19
- @DoNotStrip
20
- data class First(@DoNotStrip val value: PurchaseAndroid): Variant_PurchaseAndroid_PurchaseIOS()
21
- @DoNotStrip
22
- data class Second(@DoNotStrip val value: PurchaseIOS): Variant_PurchaseAndroid_PurchaseIOS()
23
-
24
- inline fun <reified T> getAs(): T? = when (this) {
25
- is First -> value as? T
26
- is Second -> value as? T
27
- }
28
-
29
- val isFirst: Boolean
30
- get() = this is First
31
- val isSecond: Boolean
32
- get() = this is Second
33
-
34
- companion object {
35
- @JvmStatic
36
- @DoNotStrip
37
- fun create(value: PurchaseAndroid): Variant_PurchaseAndroid_PurchaseIOS = First(value)
38
- @JvmStatic
39
- @DoNotStrip
40
- fun create(value: PurchaseIOS): Variant_PurchaseAndroid_PurchaseIOS = Second(value)
41
- }
42
- }
@@ -1,47 +0,0 @@
1
- ///
2
- /// Func_void_RequestPurchaseResult.swift
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
- import NitroModules
9
-
10
-
11
- /**
12
- * Wraps a Swift `(_ value: RequestPurchaseResult) -> Void` as a class.
13
- * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
- */
15
- public final class Func_void_RequestPurchaseResult {
16
- public typealias bridge = margelo.nitro.iap.bridge.swift
17
-
18
- private let closure: (_ value: RequestPurchaseResult) -> Void
19
-
20
- public init(_ closure: @escaping (_ value: RequestPurchaseResult) -> Void) {
21
- self.closure = closure
22
- }
23
-
24
- @inline(__always)
25
- public func call(value: RequestPurchaseResult) -> Void {
26
- self.closure(value)
27
- }
28
-
29
- /**
30
- * Casts this instance to a retained unsafe raw pointer.
31
- * This acquires one additional strong reference on the object!
32
- */
33
- @inline(__always)
34
- public func toUnsafe() -> UnsafeMutableRawPointer {
35
- return Unmanaged.passRetained(self).toOpaque()
36
- }
37
-
38
- /**
39
- * Casts an unsafe pointer to a `Func_void_RequestPurchaseResult`.
40
- * The pointer has to be a retained opaque `Unmanaged<Func_void_RequestPurchaseResult>`.
41
- * This removes one strong reference from the object!
42
- */
43
- @inline(__always)
44
- public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_RequestPurchaseResult {
45
- return Unmanaged<Func_void_RequestPurchaseResult>.fromOpaque(pointer).takeRetainedValue()
46
- }
47
- }
@@ -1,18 +0,0 @@
1
- ///
2
- /// Variant_PurchaseAndroid_PurchaseIOS.swift
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © 2025 Marc Rousavy @ Margelo
6
- ///
7
-
8
-
9
-
10
- /**
11
- * An Swift enum with associated values representing a Variant/Union type.
12
- * JS type: `struct | struct`
13
- */
14
- @frozen
15
- public indirect enum Variant_PurchaseAndroid_PurchaseIOS {
16
- case first(PurchaseAndroid)
17
- case second(PurchaseIOS)
18
- }