react-native-iap 11.0.0-rc.3 → 11.0.0-rc.4

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 (41) hide show
  1. package/ios/RNIapIos.m +3 -0
  2. package/ios/RNIapIos.swift +10 -2
  3. package/ios/RNIapIosSk2.m +4 -0
  4. package/ios/RNIapIosSk2.swift +8 -0
  5. package/lib/commonjs/iap.js +41 -11
  6. package/lib/commonjs/iap.js.map +1 -1
  7. package/lib/commonjs/internal/platform.js +33 -4
  8. package/lib/commonjs/internal/platform.js.map +1 -1
  9. package/lib/commonjs/modules/ios.js.map +1 -1
  10. package/lib/commonjs/modules/iosSk2.js.map +1 -1
  11. package/lib/commonjs/types/apple.js +24 -0
  12. package/lib/commonjs/types/apple.js.map +1 -1
  13. package/lib/commonjs/types/appleSk2.js +1 -1
  14. package/lib/commonjs/types/appleSk2.js.map +1 -1
  15. package/lib/commonjs/types/index.js.map +1 -1
  16. package/lib/module/iap.js +37 -4
  17. package/lib/module/iap.js.map +1 -1
  18. package/lib/module/internal/platform.js +25 -2
  19. package/lib/module/internal/platform.js.map +1 -1
  20. package/lib/module/modules/ios.js.map +1 -1
  21. package/lib/module/modules/iosSk2.js.map +1 -1
  22. package/lib/module/types/apple.js +15 -0
  23. package/lib/module/types/apple.js.map +1 -1
  24. package/lib/module/types/appleSk2.js +1 -1
  25. package/lib/module/types/appleSk2.js.map +1 -1
  26. package/lib/module/types/index.js.map +1 -1
  27. package/lib/typescript/iap.d.ts +15 -2
  28. package/lib/typescript/internal/platform.d.ts +3 -1
  29. package/lib/typescript/modules/ios.d.ts +2 -1
  30. package/lib/typescript/modules/iosSk2.d.ts +2 -1
  31. package/lib/typescript/types/apple.d.ts +1 -0
  32. package/lib/typescript/types/appleSk2.d.ts +1 -1
  33. package/lib/typescript/types/index.d.ts +1 -0
  34. package/package.json +1 -1
  35. package/src/iap.ts +41 -11
  36. package/src/internal/platform.ts +24 -2
  37. package/src/modules/ios.ts +2 -1
  38. package/src/modules/iosSk2.ts +2 -1
  39. package/src/types/apple.ts +15 -0
  40. package/src/types/appleSk2.ts +2 -2
  41. package/src/types/index.ts +1 -0
package/src/iap.ts CHANGED
@@ -4,6 +4,7 @@ import * as IapAmazon from './modules/amazon';
4
4
  import * as IapAndroid from './modules/android';
5
5
  import * as IapIos from './modules/ios';
6
6
  import * as IapIosSk2 from './modules/iosSk2';
7
+ import {offerToRecord} from './types/apple';
7
8
  import {
8
9
  offerSk2Map,
9
10
  ProductSk2,
@@ -11,13 +12,15 @@ import {
11
12
  subscriptionSk2Map,
12
13
  } from './types/appleSk2';
13
14
  import {
14
- enableStorekit2,
15
15
  fillProductsWithAdditionalData,
16
16
  getAndroidModule,
17
17
  getIosModule,
18
18
  getNativeModule,
19
19
  isAmazon,
20
20
  isIosStorekit2,
21
+ storekit1Mode,
22
+ storekit2Mode,
23
+ storekitHybridMode,
21
24
  } from './internal';
22
25
  import {
23
26
  Product,
@@ -31,19 +34,46 @@ import {
31
34
  } from './types';
32
35
  import {PurchaseStateAndroid} from './types';
33
36
 
34
- export {
35
- IapAndroid,
36
- IapAmazon,
37
- IapIos,
38
- IapIosSk2,
39
- isIosStorekit2,
40
- enableStorekit2,
41
- };
37
+ export {IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2};
42
38
 
43
39
  const {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;
44
40
  const ANDROID_ITEM_TYPE_SUBSCRIPTION = ProductType.subs;
45
41
  const ANDROID_ITEM_TYPE_IAP = ProductType.inapp;
46
42
 
43
+ /**
44
+ * STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before,
45
+ * minimum changes required in the migration guide (default)
46
+ * HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices
47
+ * There are some edge cases that you need to handle in this case (described in migration guide). This mode
48
+ * is for developers that are migrating to Storekit 2 but want to keep supporting older versions.
49
+ * STOREKIT2_MODE: Will *only* enable Storekit 2. This disables Storekit 1. This is for apps that
50
+ * have already targeted a min version of 15 for their app.
51
+ */
52
+ export type STOREKIT_OPTIONS =
53
+ | 'STOREKIT1_MODE'
54
+ | 'STOREKIT_HYBRID_MODE'
55
+ | 'STOREKIT2_MODE';
56
+
57
+ export const setup = ({
58
+ storekitMode = 'STOREKIT1_MODE',
59
+ }: {
60
+ storekitMode?: STOREKIT_OPTIONS;
61
+ } = {}) => {
62
+ switch (storekitMode) {
63
+ case 'STOREKIT1_MODE':
64
+ storekit1Mode();
65
+ break;
66
+ case 'STOREKIT2_MODE':
67
+ storekit2Mode();
68
+ break;
69
+ case 'STOREKIT_HYBRID_MODE':
70
+ storekitHybridMode();
71
+ break;
72
+ default:
73
+ break;
74
+ }
75
+ };
76
+
47
77
  /**
48
78
  * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
49
79
  * ## Usage
@@ -493,7 +523,7 @@ export const requestPurchase = ({
493
523
  andDangerouslyFinishTransactionAutomaticallyIOS,
494
524
  appAccountToken,
495
525
  quantity ?? -1,
496
- withOffer,
526
+ offerToRecord(withOffer),
497
527
  );
498
528
  }
499
529
  },
@@ -646,7 +676,7 @@ export const requestSubscription = ({
646
676
  andDangerouslyFinishTransactionAutomaticallyIOS,
647
677
  appAccountToken,
648
678
  quantity ?? -1,
649
- withOffer,
679
+ offerToRecord(withOffer),
650
680
  );
651
681
  }
652
682
  },
@@ -57,9 +57,10 @@ export const setIosNativeModule = (
57
57
  iosNativeModule = nativeModule;
58
58
  };
59
59
 
60
- export const enableStorekit2 = () => {
60
+ export const storekit2Mode = () => {
61
+ iosNativeModule = RNIapIosSk2;
61
62
  if (RNIapIosSk2) {
62
- iosNativeModule = RNIapIosSk2;
63
+ RNIapIos.disable();
63
64
  return true;
64
65
  }
65
66
  console.warn('Storekit 2 is not available on this device');
@@ -67,6 +68,27 @@ export const enableStorekit2 = () => {
67
68
  return false;
68
69
  };
69
70
 
71
+ export const storekit1Mode = () => {
72
+ iosNativeModule = RNIapIos;
73
+ if (RNIapIosSk2) {
74
+ RNIapIosSk2.disable();
75
+ return true;
76
+ }
77
+ return false;
78
+ };
79
+
80
+ export const storekitHybridMode = () => {
81
+ if (RNIapIosSk2) {
82
+ iosNativeModule = RNIapIosSk2;
83
+ console.info('Using Storekit 2');
84
+ return true;
85
+ } else {
86
+ iosNativeModule = RNIapIos;
87
+ console.info('Using Storekit 1');
88
+ return true;
89
+ }
90
+ };
91
+
70
92
  const checkNativeIOSAvailable = (): void => {
71
93
  if (!RNIapIos && !RNIapIosSk2) {
72
94
  throw new Error('IAP_NOT_AVAILABLE');
@@ -21,7 +21,7 @@ export type BuyProduct = (
21
21
  andDangerouslyFinishTransactionAutomaticallyIOS: boolean,
22
22
  applicationUsername: string | undefined,
23
23
  quantity: number,
24
- withOffer: PaymentDiscount | undefined,
24
+ withOffer: Record<keyof PaymentDiscount, string> | undefined,
25
25
  ) => Promise<Purchase>;
26
26
 
27
27
  type clearTransaction = () => Promise<void>;
@@ -47,6 +47,7 @@ export interface IosModuleProps extends NativeModuleProps {
47
47
  finishTransaction: finishTransaction;
48
48
  getPendingTransactions: getPendingTransactions;
49
49
  presentCodeRedemptionSheet: presentCodeRedemptionSheet;
50
+ disable: () => Promise<null>;
50
51
  }
51
52
 
52
53
  /**
@@ -22,7 +22,7 @@ export type BuyProduct = (
22
22
  andDangerouslyFinishTransactionAutomaticallyIOS: boolean,
23
23
  applicationUsername: string | undefined,
24
24
  quantity: number,
25
- withOffer: PaymentDiscountSk2 | undefined,
25
+ withOffer: Record<keyof PaymentDiscountSk2, string> | undefined,
26
26
  ) => Promise<Purchase>;
27
27
 
28
28
  type clearTransaction = () => Promise<void>;
@@ -53,6 +53,7 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
53
53
  finishTransaction: finishTransaction;
54
54
  getPendingTransactions: getPendingTransactions;
55
55
  presentCodeRedemptionSheet: presentCodeRedemptionSheet;
56
+ disable: () => Promise<null>;
56
57
  }
57
58
 
58
59
  /**
@@ -27,3 +27,18 @@ export interface PaymentDiscount {
27
27
  */
28
28
  timestamp: number;
29
29
  }
30
+
31
+ export const offerToRecord = (
32
+ offer: PaymentDiscount | undefined,
33
+ ): Record<keyof PaymentDiscount, string> | undefined => {
34
+ if (!offer) {
35
+ return undefined;
36
+ }
37
+ return {
38
+ identifier: offer.identifier,
39
+ keyIdentifier: offer.keyIdentifier,
40
+ nonce: offer.nonce,
41
+ signature: offer.signature,
42
+ timestamp: offer.timestamp.toString(),
43
+ };
44
+ };
@@ -175,7 +175,7 @@ export interface PaymentDiscountSk2 {
175
175
 
176
176
  export const offerSk2Map = (
177
177
  offer: Apple.PaymentDiscount | undefined,
178
- ): PaymentDiscountSk2 | undefined => {
178
+ ): Record<keyof PaymentDiscountSk2, string> | undefined => {
179
179
  if (!offer) {
180
180
  return undefined;
181
181
  }
@@ -184,6 +184,6 @@ export const offerSk2Map = (
184
184
  keyID: offer.keyIdentifier,
185
185
  nonce: offer.nonce,
186
186
  signature: offer.signature,
187
- timestamp: offer.timestamp,
187
+ timestamp: offer.timestamp.toString(),
188
188
  };
189
189
  };
@@ -147,6 +147,7 @@ export interface SubscriptionAndroid extends ProductCommon {
147
147
  recurrenceMode: number;
148
148
  }[];
149
149
  };
150
+ offerTags: string[];
150
151
  }[];
151
152
  }
152
153