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

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 -3
  3. package/ios/RNIapIosSk2.m +5 -1
  4. package/ios/RNIapIosSk2.swift +13 -5
  5. package/lib/commonjs/iap.js +51 -13
  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 +48 -7
  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 +3 -2
  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 +60 -13
  36. package/src/internal/platform.ts +24 -2
  37. package/src/modules/ios.ts +2 -1
  38. package/src/modules/iosSk2.ts +3 -2
  39. package/src/types/apple.ts +15 -0
  40. package/src/types/appleSk2.ts +2 -2
  41. package/src/types/index.ts +1 -0
@@ -2,9 +2,22 @@ import * as IapAmazon from './modules/amazon';
2
2
  import * as IapAndroid from './modules/android';
3
3
  import * as IapIos from './modules/ios';
4
4
  import * as IapIosSk2 from './modules/iosSk2';
5
- import { enableStorekit2, isIosStorekit2 } from './internal';
5
+ import { isIosStorekit2 } from './internal';
6
6
  import { Product, ProductPurchase, PurchaseResult, RequestPurchase, RequestSubscription, Subscription, SubscriptionPurchase } from './types';
7
- export { IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2, enableStorekit2, };
7
+ export { IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2 };
8
+ /**
9
+ * STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before,
10
+ * minimum changes required in the migration guide (default)
11
+ * HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices
12
+ * There are some edge cases that you need to handle in this case (described in migration guide). This mode
13
+ * is for developers that are migrating to Storekit 2 but want to keep supporting older versions.
14
+ * STOREKIT2_MODE: Will *only* enable Storekit 2. This disables Storekit 1. This is for apps that
15
+ * have already targeted a min version of 15 for their app.
16
+ */
17
+ export declare type STOREKIT_OPTIONS = 'STOREKIT1_MODE' | 'STOREKIT_HYBRID_MODE' | 'STOREKIT2_MODE';
18
+ export declare const setup: ({ storekitMode, }?: {
19
+ storekitMode?: STOREKIT_OPTIONS | undefined;
20
+ }) => void;
8
21
  /**
9
22
  * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
10
23
  * ## Usage
@@ -8,5 +8,7 @@ export declare const getNativeModule: () => import("..").AmazonModuleProps | imp
8
8
  export declare const isIosStorekit2: () => boolean;
9
9
  export declare const isStorekit2Avaiable: () => boolean;
10
10
  export declare const setIosNativeModule: (nativeModule: import("..").IosModuleProps | import("../modules/iosSk2").IosModulePropsSk2) => void;
11
- export declare const enableStorekit2: () => boolean;
11
+ export declare const storekit2Mode: () => boolean;
12
+ export declare const storekit1Mode: () => boolean;
13
+ export declare const storekitHybridMode: () => boolean;
12
14
  export declare const getIosModule: () => import("..").IosModuleProps | import("../modules/iosSk2").IosModulePropsSk2;
@@ -4,7 +4,7 @@ import type { PaymentDiscount } from '../types/apple';
4
4
  import type { NativeModuleProps } from './common';
5
5
  declare type getItems = (skus: Sku[]) => Promise<Product[] | Subscription[]>;
6
6
  declare type getAvailableItems = () => Promise<Purchase[]>;
7
- export declare type BuyProduct = (sku: Sku, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, applicationUsername: string | undefined, quantity: number, withOffer: PaymentDiscount | undefined) => Promise<Purchase>;
7
+ export declare type BuyProduct = (sku: Sku, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, applicationUsername: string | undefined, quantity: number, withOffer: Record<keyof PaymentDiscount, string> | undefined) => Promise<Purchase>;
8
8
  declare type clearTransaction = () => Promise<void>;
9
9
  declare type clearProducts = () => Promise<void>;
10
10
  declare type promotedProduct = () => Promise<Product | null>;
@@ -25,6 +25,7 @@ export interface IosModuleProps extends NativeModuleProps {
25
25
  finishTransaction: finishTransaction;
26
26
  getPendingTransactions: getPendingTransactions;
27
27
  presentCodeRedemptionSheet: presentCodeRedemptionSheet;
28
+ disable: () => Promise<null>;
28
29
  }
29
30
  /**
30
31
  * Get the current receipt base64 encoded in IOS.
@@ -2,8 +2,8 @@ import type { Product, ProductPurchase, Purchase, Sku } from '../types';
2
2
  import type { PaymentDiscountSk2, ProductSk2, ProductStatus, TransactionSk2 } from '../types/appleSk2';
3
3
  import type { NativeModuleProps } from './common';
4
4
  declare type getItems = (skus: Sku[]) => Promise<ProductSk2[]>;
5
- declare type getAvailableItems = (alsoPublishToEventListener?: boolean) => Promise<Purchase[]>;
6
- export declare type BuyProduct = (sku: Sku, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, applicationUsername: string | undefined, quantity: number, withOffer: PaymentDiscountSk2 | undefined) => Promise<Purchase>;
5
+ declare type getAvailableItems = (alsoPublishToEventListener?: boolean) => Promise<TransactionSk2[]>;
6
+ export declare type BuyProduct = (sku: Sku, andDangerouslyFinishTransactionAutomaticallyIOS: boolean, applicationUsername: string | undefined, quantity: number, withOffer: Record<keyof PaymentDiscountSk2, string> | undefined) => Promise<Purchase>;
7
7
  declare type clearTransaction = () => Promise<void>;
8
8
  declare type clearProducts = () => Promise<void>;
9
9
  declare type promotedProduct = () => Promise<Product | null>;
@@ -29,6 +29,7 @@ export interface IosModulePropsSk2 extends NativeModuleProps {
29
29
  finishTransaction: finishTransaction;
30
30
  getPendingTransactions: getPendingTransactions;
31
31
  presentCodeRedemptionSheet: presentCodeRedemptionSheet;
32
+ disable: () => Promise<null>;
32
33
  }
33
34
  /**
34
35
  * Sync state with Appstore (iOS only)
@@ -23,3 +23,4 @@ export interface PaymentDiscount {
23
23
  */
24
24
  timestamp: number;
25
25
  }
26
+ export declare const offerToRecord: (offer: PaymentDiscount | undefined) => Record<keyof PaymentDiscount, string> | undefined;
@@ -97,4 +97,4 @@ export interface PaymentDiscountSk2 {
97
97
  */
98
98
  timestamp: number;
99
99
  }
100
- export declare const offerSk2Map: (offer: Apple.PaymentDiscount | undefined) => PaymentDiscountSk2 | undefined;
100
+ export declare const offerSk2Map: (offer: Apple.PaymentDiscount | undefined) => Record<keyof PaymentDiscountSk2, string> | undefined;
@@ -119,6 +119,7 @@ export interface SubscriptionAndroid extends ProductCommon {
119
119
  recurrenceMode: number;
120
120
  }[];
121
121
  };
122
+ offerTags: string[];
122
123
  }[];
123
124
  }
124
125
  export interface SubscriptionIOS extends ProductCommon {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-iap",
3
- "version": "11.0.0-rc.3",
3
+ "version": "11.0.0-rc.5",
4
4
  "description": "React Native In App Purchase Module.",
5
5
  "repository": "https://github.com/dooboolab/react-native-iap",
6
6
  "author": "dooboolab <support@dooboolab.com> (https://github.com/dooboolab)",
package/src/iap.ts CHANGED
@@ -4,20 +4,24 @@ 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,
10
11
  productSk2Map,
11
12
  subscriptionSk2Map,
13
+ transactionSk2Map,
12
14
  } from './types/appleSk2';
13
15
  import {
14
- enableStorekit2,
15
16
  fillProductsWithAdditionalData,
16
17
  getAndroidModule,
17
18
  getIosModule,
18
19
  getNativeModule,
19
20
  isAmazon,
20
21
  isIosStorekit2,
22
+ storekit1Mode,
23
+ storekit2Mode,
24
+ storekitHybridMode,
21
25
  } from './internal';
22
26
  import {
23
27
  Product,
@@ -31,19 +35,46 @@ import {
31
35
  } from './types';
32
36
  import {PurchaseStateAndroid} from './types';
33
37
 
34
- export {
35
- IapAndroid,
36
- IapAmazon,
37
- IapIos,
38
- IapIosSk2,
39
- isIosStorekit2,
40
- enableStorekit2,
41
- };
38
+ export {IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2};
42
39
 
43
40
  const {RNIapIos, RNIapIosSk2, RNIapModule, RNIapAmazonModule} = NativeModules;
44
41
  const ANDROID_ITEM_TYPE_SUBSCRIPTION = ProductType.subs;
45
42
  const ANDROID_ITEM_TYPE_IAP = ProductType.inapp;
46
43
 
44
+ /**
45
+ * STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before,
46
+ * minimum changes required in the migration guide (default)
47
+ * HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices
48
+ * There are some edge cases that you need to handle in this case (described in migration guide). This mode
49
+ * is for developers that are migrating to Storekit 2 but want to keep supporting older versions.
50
+ * STOREKIT2_MODE: Will *only* enable Storekit 2. This disables Storekit 1. This is for apps that
51
+ * have already targeted a min version of 15 for their app.
52
+ */
53
+ export type STOREKIT_OPTIONS =
54
+ | 'STOREKIT1_MODE'
55
+ | 'STOREKIT_HYBRID_MODE'
56
+ | 'STOREKIT2_MODE';
57
+
58
+ export const setup = ({
59
+ storekitMode = 'STOREKIT1_MODE',
60
+ }: {
61
+ storekitMode?: STOREKIT_OPTIONS;
62
+ } = {}) => {
63
+ switch (storekitMode) {
64
+ case 'STOREKIT1_MODE':
65
+ storekit1Mode();
66
+ break;
67
+ case 'STOREKIT2_MODE':
68
+ storekit2Mode();
69
+ break;
70
+ case 'STOREKIT_HYBRID_MODE':
71
+ storekitHybridMode();
72
+ break;
73
+ default:
74
+ break;
75
+ }
76
+ };
77
+
47
78
  /**
48
79
  * Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
49
80
  * ## Usage
@@ -259,7 +290,15 @@ export const getPurchaseHistory = ({
259
290
  (
260
291
  Platform.select({
261
292
  ios: async () => {
262
- return getIosModule().getAvailableItems(alsoPublishToEventListener);
293
+ if (isIosStorekit2()) {
294
+ return Promise.resolve(
295
+ (
296
+ await RNIapIosSk2.getAvailableItems(alsoPublishToEventListener)
297
+ ).map(transactionSk2Map),
298
+ );
299
+ } else {
300
+ return RNIapIos.getAvailableItems();
301
+ }
263
302
  },
264
303
  android: async () => {
265
304
  if (RNIapAmazonModule) {
@@ -367,7 +406,15 @@ export const getAvailablePurchases = ({
367
406
  (
368
407
  Platform.select({
369
408
  ios: async () => {
370
- return getIosModule().getAvailableItems(alsoPublishToEventListener);
409
+ if (isIosStorekit2()) {
410
+ return Promise.resolve(
411
+ (
412
+ await RNIapIosSk2.getAvailableItems(alsoPublishToEventListener)
413
+ ).map(transactionSk2Map),
414
+ );
415
+ } else {
416
+ return RNIapIos.getAvailableItems();
417
+ }
371
418
  },
372
419
  android: async () => {
373
420
  if (RNIapAmazonModule) {
@@ -493,7 +540,7 @@ export const requestPurchase = ({
493
540
  andDangerouslyFinishTransactionAutomaticallyIOS,
494
541
  appAccountToken,
495
542
  quantity ?? -1,
496
- withOffer,
543
+ offerToRecord(withOffer),
497
544
  );
498
545
  }
499
546
  },
@@ -646,7 +693,7 @@ export const requestSubscription = ({
646
693
  andDangerouslyFinishTransactionAutomaticallyIOS,
647
694
  appAccountToken,
648
695
  quantity ?? -1,
649
- withOffer,
696
+ offerToRecord(withOffer),
650
697
  );
651
698
  }
652
699
  },
@@ -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
  /**
@@ -15,14 +15,14 @@ type getItems = (skus: Sku[]) => Promise<ProductSk2[]>;
15
15
 
16
16
  type getAvailableItems = (
17
17
  alsoPublishToEventListener?: boolean,
18
- ) => Promise<Purchase[]>;
18
+ ) => Promise<TransactionSk2[]>;
19
19
 
20
20
  export type BuyProduct = (
21
21
  sku: Sku,
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