react-native-iap 11.0.0-rc.2 → 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.
- package/ios/IapSerializationUtils.swift +50 -11
- package/ios/IapTypes.swift +1 -6
- package/ios/RNIapIos.m +3 -0
- package/ios/RNIapIos.swift +12 -3
- package/ios/RNIapIosSk2.m +6 -1
- package/ios/RNIapIosSk2.swift +37 -16
- package/lib/commonjs/eventEmitter.js +145 -2
- package/lib/commonjs/eventEmitter.js.map +1 -1
- package/lib/commonjs/hooks/withIAPContext.js +8 -1
- package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
- package/lib/commonjs/iap.js +81 -37
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/internal/platform.js +33 -4
- package/lib/commonjs/internal/platform.js.map +1 -1
- package/lib/commonjs/modules/ios.js +5 -2
- package/lib/commonjs/modules/ios.js.map +1 -1
- package/lib/commonjs/modules/iosSk2.js.map +1 -1
- package/lib/commonjs/types/apple.js +24 -0
- package/lib/commonjs/types/apple.js.map +1 -1
- package/lib/commonjs/types/appleSk2.js +3 -3
- package/lib/commonjs/types/appleSk2.js.map +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/eventEmitter.js +141 -1
- package/lib/module/eventEmitter.js.map +1 -1
- package/lib/module/hooks/withIAPContext.js +9 -2
- package/lib/module/hooks/withIAPContext.js.map +1 -1
- package/lib/module/iap.js +77 -30
- package/lib/module/iap.js.map +1 -1
- package/lib/module/internal/platform.js +25 -2
- package/lib/module/internal/platform.js.map +1 -1
- package/lib/module/modules/ios.js +5 -2
- package/lib/module/modules/ios.js.map +1 -1
- package/lib/module/modules/iosSk2.js.map +1 -1
- package/lib/module/types/apple.js +15 -0
- package/lib/module/types/apple.js.map +1 -1
- package/lib/module/types/appleSk2.js +3 -3
- package/lib/module/types/appleSk2.js.map +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/eventEmitter.d.ts +133 -0
- package/lib/typescript/hooks/withIAPContext.d.ts +2 -0
- package/lib/typescript/iap.d.ts +25 -4
- package/lib/typescript/internal/platform.d.ts +3 -1
- package/lib/typescript/modules/ios.d.ts +2 -1
- package/lib/typescript/modules/iosSk2.d.ts +3 -2
- package/lib/typescript/types/apple.d.ts +1 -0
- package/lib/typescript/types/appleSk2.d.ts +31 -2
- package/lib/typescript/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/eventEmitter.ts +144 -2
- package/src/hooks/withIAPContext.tsx +15 -0
- package/src/iap.ts +55 -17
- package/src/internal/platform.ts +24 -2
- package/src/modules/ios.ts +7 -3
- package/src/modules/iosSk2.ts +5 -2
- package/src/types/apple.ts +15 -0
- package/src/types/appleSk2.ts +42 -5
- package/src/types/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ProrationModesAndroid","PurchaseStateAndroid","PROMOTED_PRODUCT","InstallSourceAndroid","ProductType"],"sources":["index.ts"],"sourcesContent":["import type {\n AmazonModuleProps,\n AndroidModuleProps,\n IosModuleProps,\n} from '../modules';\nimport type {IosModulePropsSk2} from '../modules/iosSk2';\n\nimport type * as Apple from './apple';\n\nexport type Sku = string;\n\nexport enum ProrationModesAndroid {\n IMMEDIATE_WITH_TIME_PRORATION = 1,\n IMMEDIATE_AND_CHARGE_PRORATED_PRICE = 2,\n IMMEDIATE_WITHOUT_PRORATION = 3,\n DEFERRED = 4,\n IMMEDIATE_AND_CHARGE_FULL_PRICE = 5,\n UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY = 0,\n}\n\nexport enum PurchaseStateAndroid {\n UNSPECIFIED_STATE = 0,\n PURCHASED = 1,\n PENDING = 2,\n}\n\nexport const PROMOTED_PRODUCT = 'iap-promoted-product';\n\nexport enum InstallSourceAndroid {\n NOT_SET = 0,\n GOOGLE_PLAY = 1,\n AMAZON = 2,\n}\n\nexport enum ProductType {\n /** Subscription */\n subs = 'subs',\n\n /** Subscription */\n sub = 'sub',\n\n /** Consumable */\n inapp = 'inapp',\n\n /** Consumable */\n iap = 'iap',\n}\n\nexport interface ProductCommon {\n type: 'subs' | 'sub' | 'inapp' | 'iap';\n productId: string; //iOS\n productIds?: string[];\n title: string;\n description: string;\n price: string;\n currency: string;\n localizedPrice: string;\n countryCode?: string;\n}\n\nexport interface ProductPurchase {\n productId: string;\n transactionId?: string;\n transactionDate: number;\n transactionReceipt: string;\n purchaseToken?: string;\n //iOS\n quantityIOS?: number;\n originalTransactionDateIOS?: string;\n originalTransactionIdentifierIOS?: string;\n //Android\n productIds?: string[];\n dataAndroid?: string;\n signatureAndroid?: string;\n autoRenewingAndroid?: boolean;\n purchaseStateAndroid?: PurchaseStateAndroid;\n isAcknowledgedAndroid?: boolean;\n packageNameAndroid?: string;\n developerPayloadAndroid?: string;\n obfuscatedAccountIdAndroid?: string;\n obfuscatedProfileIdAndroid?: string;\n //Amazon\n userIdAmazon?: string;\n userMarketplaceAmazon?: string;\n userJsonAmazon?: string;\n isCanceledAmazon?: boolean;\n}\n\nexport interface PurchaseResult {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n purchaseToken?: string;\n}\n\nexport interface SubscriptionPurchase extends ProductPurchase {\n autoRenewingAndroid?: boolean;\n originalTransactionDateIOS?: string;\n originalTransactionIdentifierIOS?: string;\n}\n\nexport type Purchase = ProductPurchase | SubscriptionPurchase;\n\nexport interface Discount {\n identifier: string;\n type: string;\n numberOfPeriods: string;\n price: string;\n localizedPrice: string;\n paymentMode: '' | 'FREETRIAL' | 'PAYASYOUGO' | 'PAYUPFRONT';\n subscriptionPeriod: string;\n}\n\nexport interface ProductAndroid extends ProductCommon {\n type: 'inapp' | 'iap';\n oneTimePurchaseOfferDetails?: {\n priceCurrencyCode: string;\n formattedPrice: string;\n priceAmountMicros: string;\n };\n}\nexport interface ProductIOS extends ProductCommon {\n type: 'inapp' | 'iap';\n}\n\nexport type Product = ProductAndroid & ProductIOS;\n\n// Android V5\nexport interface SubscriptionAndroid extends ProductCommon {\n type: 'subs';\n\n productType?: string;\n name?: string;\n subscriptionOfferDetails?: {\n offerToken: string;\n pricingPhases: {\n pricingPhaseList: {\n formattedPrice: string;\n priceCurrencyCode: string;\n /**\n * P1W, P1M, P1Y\n */\n billingPeriod: string;\n billingCycleCount: number;\n priceAmountMicros: string;\n recurrenceMode: number;\n }[];\n };\n }[];\n}\n\nexport interface SubscriptionIOS extends ProductCommon {\n type: 'subs';\n discounts?: Discount[];\n introductoryPrice?: string;\n introductoryPriceAsAmountIOS?: string;\n introductoryPricePaymentModeIOS?:\n | ''\n | 'FREETRIAL'\n | 'PAYASYOUGO'\n | 'PAYUPFRONT';\n introductoryPriceNumberOfPeriodsIOS?: string;\n introductoryPriceSubscriptionPeriodIOS?:\n | 'DAY'\n | 'WEEK'\n | 'MONTH'\n | 'YEAR'\n | '';\n\n subscriptionPeriodNumberIOS?: string;\n subscriptionPeriodUnitIOS?: '' | 'YEAR' | 'MONTH' | 'WEEK' | 'DAY';\n}\n\nexport type Subscription = SubscriptionAndroid & SubscriptionIOS;\nexport interface RequestPurchaseBaseAndroid {\n obfuscatedAccountIdAndroid?: string;\n obfuscatedProfileIdAndroid?: string;\n isOfferPersonalized?: boolean; // For AndroidBilling V5 https://developer.android.com/google/play/billing/integrate#personalized-price\n}\n\nexport interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {\n skus?: Sku[];\n}\n\nexport interface RequestPurchaseIOS {\n sku?: Sku;\n andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;\n /**\n * UUID representing user account\n */\n appAccountToken?: string;\n quantity?: number;\n withOffer?: Apple.PaymentDiscount;\n}\n\nexport type RequestPurchase = RequestPurchaseAndroid & RequestPurchaseIOS;\n\n/**\n * In order to purchase a new subscription, every sku must have a selected offerToken\n * @see SubscriptionAndroid.subscriptionOfferDetails.offerToken\n */\nexport interface SubscriptionOffer {\n sku: Sku;\n offerToken: string;\n}\n\nexport interface RequestSubscriptionAndroid extends RequestPurchaseBaseAndroid {\n purchaseTokenAndroid?: string;\n prorationModeAndroid?: ProrationModesAndroid;\n subscriptionOffers?: SubscriptionOffer[]; // For AndroidBilling V5\n}\n\nexport type RequestSubscriptionIOS = RequestPurchaseIOS;\n\nexport type RequestSubscription = RequestSubscriptionAndroid &\n RequestSubscriptionIOS;\n\ndeclare module 'react-native' {\n interface NativeModulesStatic {\n RNIapIos: IosModuleProps;\n RNIapIosSk2: IosModulePropsSk2;\n RNIapModule: AndroidModuleProps;\n RNIapAmazonModule: AmazonModuleProps;\n }\n}\n"],"mappings":";;;;;;IAWYA,qB;;;WAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,qCAAAA,qB;;IASAC,oB;;;WAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB;;AAML,MAAMC,gBAAgB,GAAG,sBAAzB;;IAEKC,oB;;;WAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB;;IAMAC,W;;;WAAAA,W;EAAAA,W;EAAAA,W;EAAAA,W;EAAAA,W;GAAAA,W,2BAAAA,W"}
|
|
1
|
+
{"version":3,"names":["ProrationModesAndroid","PurchaseStateAndroid","PROMOTED_PRODUCT","InstallSourceAndroid","ProductType"],"sources":["index.ts"],"sourcesContent":["import type {\n AmazonModuleProps,\n AndroidModuleProps,\n IosModuleProps,\n} from '../modules';\nimport type {IosModulePropsSk2} from '../modules/iosSk2';\n\nimport type * as Apple from './apple';\n\nexport type Sku = string;\n\nexport enum ProrationModesAndroid {\n IMMEDIATE_WITH_TIME_PRORATION = 1,\n IMMEDIATE_AND_CHARGE_PRORATED_PRICE = 2,\n IMMEDIATE_WITHOUT_PRORATION = 3,\n DEFERRED = 4,\n IMMEDIATE_AND_CHARGE_FULL_PRICE = 5,\n UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY = 0,\n}\n\nexport enum PurchaseStateAndroid {\n UNSPECIFIED_STATE = 0,\n PURCHASED = 1,\n PENDING = 2,\n}\n\nexport const PROMOTED_PRODUCT = 'iap-promoted-product';\n\nexport enum InstallSourceAndroid {\n NOT_SET = 0,\n GOOGLE_PLAY = 1,\n AMAZON = 2,\n}\n\nexport enum ProductType {\n /** Subscription */\n subs = 'subs',\n\n /** Subscription */\n sub = 'sub',\n\n /** Consumable */\n inapp = 'inapp',\n\n /** Consumable */\n iap = 'iap',\n}\n\nexport interface ProductCommon {\n type: 'subs' | 'sub' | 'inapp' | 'iap';\n productId: string; //iOS\n productIds?: string[];\n title: string;\n description: string;\n price: string;\n currency: string;\n localizedPrice: string;\n countryCode?: string;\n}\n\nexport interface ProductPurchase {\n productId: string;\n transactionId?: string;\n transactionDate: number;\n transactionReceipt: string;\n purchaseToken?: string;\n //iOS\n quantityIOS?: number;\n originalTransactionDateIOS?: string;\n originalTransactionIdentifierIOS?: string;\n //Android\n productIds?: string[];\n dataAndroid?: string;\n signatureAndroid?: string;\n autoRenewingAndroid?: boolean;\n purchaseStateAndroid?: PurchaseStateAndroid;\n isAcknowledgedAndroid?: boolean;\n packageNameAndroid?: string;\n developerPayloadAndroid?: string;\n obfuscatedAccountIdAndroid?: string;\n obfuscatedProfileIdAndroid?: string;\n //Amazon\n userIdAmazon?: string;\n userMarketplaceAmazon?: string;\n userJsonAmazon?: string;\n isCanceledAmazon?: boolean;\n}\n\nexport interface PurchaseResult {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n purchaseToken?: string;\n}\n\nexport interface SubscriptionPurchase extends ProductPurchase {\n autoRenewingAndroid?: boolean;\n originalTransactionDateIOS?: string;\n originalTransactionIdentifierIOS?: string;\n}\n\nexport type Purchase = ProductPurchase | SubscriptionPurchase;\n\nexport interface Discount {\n identifier: string;\n type: string;\n numberOfPeriods: string;\n price: string;\n localizedPrice: string;\n paymentMode: '' | 'FREETRIAL' | 'PAYASYOUGO' | 'PAYUPFRONT';\n subscriptionPeriod: string;\n}\n\nexport interface ProductAndroid extends ProductCommon {\n type: 'inapp' | 'iap';\n oneTimePurchaseOfferDetails?: {\n priceCurrencyCode: string;\n formattedPrice: string;\n priceAmountMicros: string;\n };\n}\nexport interface ProductIOS extends ProductCommon {\n type: 'inapp' | 'iap';\n}\n\nexport type Product = ProductAndroid & ProductIOS;\n\n// Android V5\nexport interface SubscriptionAndroid extends ProductCommon {\n type: 'subs';\n\n productType?: string;\n name?: string;\n subscriptionOfferDetails?: {\n offerToken: string;\n pricingPhases: {\n pricingPhaseList: {\n formattedPrice: string;\n priceCurrencyCode: string;\n /**\n * P1W, P1M, P1Y\n */\n billingPeriod: string;\n billingCycleCount: number;\n priceAmountMicros: string;\n recurrenceMode: number;\n }[];\n };\n offerTags: string[];\n }[];\n}\n\nexport interface SubscriptionIOS extends ProductCommon {\n type: 'subs';\n discounts?: Discount[];\n introductoryPrice?: string;\n introductoryPriceAsAmountIOS?: string;\n introductoryPricePaymentModeIOS?:\n | ''\n | 'FREETRIAL'\n | 'PAYASYOUGO'\n | 'PAYUPFRONT';\n introductoryPriceNumberOfPeriodsIOS?: string;\n introductoryPriceSubscriptionPeriodIOS?:\n | 'DAY'\n | 'WEEK'\n | 'MONTH'\n | 'YEAR'\n | '';\n\n subscriptionPeriodNumberIOS?: string;\n subscriptionPeriodUnitIOS?: '' | 'YEAR' | 'MONTH' | 'WEEK' | 'DAY';\n}\n\nexport type Subscription = SubscriptionAndroid & SubscriptionIOS;\nexport interface RequestPurchaseBaseAndroid {\n obfuscatedAccountIdAndroid?: string;\n obfuscatedProfileIdAndroid?: string;\n isOfferPersonalized?: boolean; // For AndroidBilling V5 https://developer.android.com/google/play/billing/integrate#personalized-price\n}\n\nexport interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {\n skus?: Sku[];\n}\n\nexport interface RequestPurchaseIOS {\n sku?: Sku;\n andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;\n /**\n * UUID representing user account\n */\n appAccountToken?: string;\n quantity?: number;\n withOffer?: Apple.PaymentDiscount;\n}\n\nexport type RequestPurchase = RequestPurchaseAndroid & RequestPurchaseIOS;\n\n/**\n * In order to purchase a new subscription, every sku must have a selected offerToken\n * @see SubscriptionAndroid.subscriptionOfferDetails.offerToken\n */\nexport interface SubscriptionOffer {\n sku: Sku;\n offerToken: string;\n}\n\nexport interface RequestSubscriptionAndroid extends RequestPurchaseBaseAndroid {\n purchaseTokenAndroid?: string;\n prorationModeAndroid?: ProrationModesAndroid;\n subscriptionOffers?: SubscriptionOffer[]; // For AndroidBilling V5\n}\n\nexport type RequestSubscriptionIOS = RequestPurchaseIOS;\n\nexport type RequestSubscription = RequestSubscriptionAndroid &\n RequestSubscriptionIOS;\n\ndeclare module 'react-native' {\n interface NativeModulesStatic {\n RNIapIos: IosModuleProps;\n RNIapIosSk2: IosModulePropsSk2;\n RNIapModule: AndroidModuleProps;\n RNIapAmazonModule: AmazonModuleProps;\n }\n}\n"],"mappings":";;;;;;IAWYA,qB;;;WAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;EAAAA,qB,CAAAA,qB;GAAAA,qB,qCAAAA,qB;;IASAC,oB;;;WAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB;;AAML,MAAMC,gBAAgB,GAAG,sBAAzB;;IAEKC,oB;;;WAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB;;IAMAC,W;;;WAAAA,W;EAAAA,W;EAAAA,W;EAAAA,W;EAAAA,W;GAAAA,W,2BAAAA,W"}
|
|
@@ -5,6 +5,35 @@ import { getAndroidModule, getIosModule, getNativeModule, isAndroid, isIos } fro
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Add IAP purchase event
|
|
8
|
+
* Register a callback that gets called when the store has any updates to purchases that have not yet been finished, consumed or acknowledged. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.
|
|
9
|
+
|
|
10
|
+
## Signature
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
purchaseUpdatedListener((purchase: Purchase) => {});
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import React, {useEffect} from 'react';
|
|
20
|
+
import {View} from 'react-native';
|
|
21
|
+
import {purchaseUpdatedListener} from 'react-native-iap';
|
|
22
|
+
|
|
23
|
+
const App = () => {
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const subscription = purchaseUpdatedListener((purchase: Purchase) => {
|
|
26
|
+
console.log(purchase);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
subscription.remove();
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
|
|
34
|
+
return <View />;
|
|
35
|
+
};
|
|
36
|
+
```
|
|
8
37
|
*/
|
|
9
38
|
export const purchaseUpdatedListener = listener => {
|
|
10
39
|
const eventEmitter = new NativeEventEmitter(getNativeModule());
|
|
@@ -21,6 +50,36 @@ export const purchaseUpdatedListener = listener => {
|
|
|
21
50
|
};
|
|
22
51
|
/**
|
|
23
52
|
* Add IAP purchase error event
|
|
53
|
+
* Register a callback that gets called when there has been an error with a purchase. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates.
|
|
54
|
+
|
|
55
|
+
## Signature
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
purchaseErrorListener((error: PurchaseError) => {});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import React, {useEffect} from 'react';
|
|
65
|
+
import {View} from 'react-native';
|
|
66
|
+
import {purchaseErrorListener} from 'react-native-iap';
|
|
67
|
+
|
|
68
|
+
const App = () => {
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const subscription = purchaseErrorListener((error: PurchaseError) => {
|
|
71
|
+
console.log(error);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
subscription.remove();
|
|
76
|
+
};
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
return <View />;
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
24
83
|
*/
|
|
25
84
|
|
|
26
85
|
export const purchaseErrorListener = listener => {
|
|
@@ -29,16 +88,97 @@ export const purchaseErrorListener = listener => {
|
|
|
29
88
|
};
|
|
30
89
|
/**
|
|
31
90
|
* Add IAP promoted subscription event
|
|
91
|
+
* Add IAP promoted subscription event.
|
|
92
|
+
|
|
93
|
+
## Signature
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
promotedProductListener((productId?: string) => {});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Usage
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
import React, {useEffect} from 'react';
|
|
103
|
+
import {View} from 'react-native';
|
|
104
|
+
import {promotedProductListener} from 'react-native-iap';
|
|
105
|
+
|
|
106
|
+
const App = () => {
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const subscription = promotedProductListener((productId) => {
|
|
109
|
+
console.log(productId);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return () => {
|
|
113
|
+
subscription.remove();
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
return <View />;
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
32
121
|
*
|
|
33
122
|
* @platform iOS
|
|
34
123
|
*/
|
|
35
124
|
|
|
36
125
|
export const promotedProductListener = listener => {
|
|
37
|
-
if (isIos) {
|
|
126
|
+
if (isIos && !isIosStorekit2()) {
|
|
38
127
|
const eventEmitter = new NativeEventEmitter(getIosModule());
|
|
39
128
|
return eventEmitter.addListener('iap-promoted-product', listener);
|
|
40
129
|
}
|
|
41
130
|
|
|
42
131
|
return null;
|
|
43
132
|
};
|
|
133
|
+
/**
|
|
134
|
+
* Updated transactions for iOS Sk2
|
|
135
|
+
* Register a callback that gets called when the store has any updates to transactions related to purchases that have not yet been finished, consumed or acknowledged.
|
|
136
|
+
* Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.
|
|
137
|
+
|
|
138
|
+
**Warning**
|
|
139
|
+
This is only available for iOS 15 and higher and Storekit 2 is activated
|
|
140
|
+
|
|
141
|
+
## Signature
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
purchaseUpdatedListener((transactionOrError: TransactionOrError) => {});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Usage
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import React, {useEffect} from 'react';
|
|
151
|
+
import {View} from 'react-native';
|
|
152
|
+
import {purchaseUpdatedListener} from 'react-native-iap';
|
|
153
|
+
|
|
154
|
+
const App = () => {
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
const subscription = purchaseUpdatedListener((transactionOrError: TransactionOrError) => {
|
|
157
|
+
if(transactionOrError.transaction){
|
|
158
|
+
console.log("There's an update to a transaction", transactionOrError.transaction);
|
|
159
|
+
}else{
|
|
160
|
+
console.log("There's been an error with a received transaction")
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
return () => {
|
|
165
|
+
subscription.remove();
|
|
166
|
+
};
|
|
167
|
+
}, []);
|
|
168
|
+
|
|
169
|
+
return <View />;
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
*
|
|
173
|
+
* @platform iOS (Sk2)
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
export const transactionListener = listener => {
|
|
177
|
+
if (isIos && isIosStorekit2()) {
|
|
178
|
+
const eventEmitter = new NativeEventEmitter(getIosModule());
|
|
179
|
+
return eventEmitter.addListener('iap-transaction-updated', listener);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return null;
|
|
183
|
+
};
|
|
44
184
|
//# sourceMappingURL=eventEmitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","transactionSk2Map","isIosStorekit2","getAndroidModule","getIosModule","getNativeModule","isAndroid","isIos","purchaseUpdatedListener","listener","eventEmitter","proxyListener","event","emitterSubscription","addListener","startListening","purchaseErrorListener","promotedProductListener"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {transactionSk2Map} from './types/appleSk2';\nimport {isIosStorekit2} from './iap';\nimport {\n getAndroidModule,\n getIosModule,\n getNativeModule,\n isAndroid,\n isIos,\n} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\n/**\n * Add IAP purchase event\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n const proxyListener = isIosStorekit2()\n ? (event: Purchase) => {\n listener(transactionSk2Map(event as any));\n }\n : listener;\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n proxyListener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n return eventEmitter.addListener('purchase-error', listener);\n};\n\n/**\n * Add IAP promoted subscription event\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-promoted-product', listener);\n }\n\n return null;\n};\n"],"mappings":"AAAA,SAA6BA,kBAA7B,QAAsD,cAAtD;AAEA,
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","transactionSk2Map","isIosStorekit2","getAndroidModule","getIosModule","getNativeModule","isAndroid","isIos","purchaseUpdatedListener","listener","eventEmitter","proxyListener","event","emitterSubscription","addListener","startListening","purchaseErrorListener","promotedProductListener","transactionListener"],"sources":["eventEmitter.ts"],"sourcesContent":["import {EmitterSubscription, NativeEventEmitter} from 'react-native';\n\nimport {TransactionEvent, transactionSk2Map} from './types/appleSk2';\nimport {isIosStorekit2} from './iap';\nimport {\n getAndroidModule,\n getIosModule,\n getNativeModule,\n isAndroid,\n isIos,\n} from './internal';\nimport type {PurchaseError} from './purchaseError';\nimport type {Purchase} from './types';\n\n/**\n * Add IAP purchase event\n * Register a callback that gets called when the store has any updates to purchases that have not yet been finished, consumed or acknowledged. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.\n\n## Signature\n\n```ts\npurchaseUpdatedListener((purchase: Purchase) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {purchaseUpdatedListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = purchaseUpdatedListener((purchase: Purchase) => {\n console.log(purchase);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n */\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n const proxyListener = isIosStorekit2()\n ? (event: Purchase) => {\n listener(transactionSk2Map(event as any));\n }\n : listener;\n const emitterSubscription = eventEmitter.addListener(\n 'purchase-updated',\n proxyListener,\n );\n\n if (isAndroid) {\n getAndroidModule().startListening();\n }\n\n return emitterSubscription;\n};\n\n/**\n * Add IAP purchase error event\n * Register a callback that gets called when there has been an error with a purchase. Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates.\n\n## Signature\n\n```ts\npurchaseErrorListener((error: PurchaseError) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {purchaseErrorListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = purchaseErrorListener((error: PurchaseError) => {\n console.log(error);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n\n */\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n): EmitterSubscription => {\n const eventEmitter = new NativeEventEmitter(getNativeModule());\n return eventEmitter.addListener('purchase-error', listener);\n};\n\n/**\n * Add IAP promoted subscription event\n * Add IAP promoted subscription event.\n\n## Signature\n\n```ts\npromotedProductListener((productId?: string) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {promotedProductListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = promotedProductListener((productId) => {\n console.log(productId);\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n\n *\n * @platform iOS\n */\nexport const promotedProductListener = (listener: () => void) => {\n if (isIos && !isIosStorekit2()) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-promoted-product', listener);\n }\n\n return null;\n};\n\n/**\n * Updated transactions for iOS Sk2\n * Register a callback that gets called when the store has any updates to transactions related to purchases that have not yet been finished, consumed or acknowledged. \n * Returns a React Native `EmitterSubscription` on which you can call `.remove()` to stop receiving updates. Register you listener as soon as possible and react to updates at all times.\n\n**Warning**\nThis is only available for iOS 15 and higher and Storekit 2 is activated\n\n## Signature\n\n```ts\npurchaseUpdatedListener((transactionOrError: TransactionOrError) => {});\n```\n\n## Usage\n\n```tsx\nimport React, {useEffect} from 'react';\nimport {View} from 'react-native';\nimport {purchaseUpdatedListener} from 'react-native-iap';\n\nconst App = () => {\n useEffect(() => {\n const subscription = purchaseUpdatedListener((transactionOrError: TransactionOrError) => {\n if(transactionOrError.transaction){\n console.log(\"There's an update to a transaction\", transactionOrError.transaction);\n }else{\n console.log(\"There's been an error with a received transaction\")\n }\n });\n\n return () => {\n subscription.remove();\n };\n }, []);\n\n return <View />;\n};\n```\n *\n * @platform iOS (Sk2)\n */\nexport const transactionListener = (\n listener: (event: TransactionEvent) => void,\n) => {\n if (isIos && isIosStorekit2()) {\n const eventEmitter = new NativeEventEmitter(getIosModule());\n return eventEmitter.addListener('iap-transaction-updated', listener);\n }\n\n return null;\n};\n"],"mappings":"AAAA,SAA6BA,kBAA7B,QAAsD,cAAtD;AAEA,SAA0BC,iBAA1B,QAAkD,kBAAlD;AACA,SAAQC,cAAR,QAA6B,OAA7B;AACA,SACEC,gBADF,EAEEC,YAFF,EAGEC,eAHF,EAIEC,SAJF,EAKEC,KALF,QAMO,YANP;;AAUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uBAAuB,GAClCC,QADqC,IAElC;EACH,MAAMC,YAAY,GAAG,IAAIV,kBAAJ,CAAuBK,eAAe,EAAtC,CAArB;EACA,MAAMM,aAAa,GAAGT,cAAc,KAC/BU,KAAD,IAAqB;IACnBH,QAAQ,CAACR,iBAAiB,CAACW,KAAD,CAAlB,CAAR;EACD,CAH+B,GAIhCH,QAJJ;EAKA,MAAMI,mBAAmB,GAAGH,YAAY,CAACI,WAAb,CAC1B,kBAD0B,EAE1BH,aAF0B,CAA5B;;EAKA,IAAIL,SAAJ,EAAe;IACbH,gBAAgB,GAAGY,cAAnB;EACD;;EAED,OAAOF,mBAAP;AACD,CAnBM;AAqBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMG,qBAAqB,GAChCP,QADmC,IAEX;EACxB,MAAMC,YAAY,GAAG,IAAIV,kBAAJ,CAAuBK,eAAe,EAAtC,CAArB;EACA,OAAOK,YAAY,CAACI,WAAb,CAAyB,gBAAzB,EAA2CL,QAA3C,CAAP;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMQ,uBAAuB,GAAIR,QAAD,IAA0B;EAC/D,IAAIF,KAAK,IAAI,CAACL,cAAc,EAA5B,EAAgC;IAC9B,MAAMQ,YAAY,GAAG,IAAIV,kBAAJ,CAAuBI,YAAY,EAAnC,CAArB;IACA,OAAOM,YAAY,CAACI,WAAb,CAAyB,sBAAzB,EAAiDL,QAAjD,CAAP;EACD;;EAED,OAAO,IAAP;AACD,CAPM;AASP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMS,mBAAmB,GAC9BT,QADiC,IAE9B;EACH,IAAIF,KAAK,IAAIL,cAAc,EAA3B,EAA+B;IAC7B,MAAMQ,YAAY,GAAG,IAAIV,kBAAJ,CAAuBI,YAAY,EAAnC,CAArB;IACA,OAAOM,YAAY,CAACI,WAAb,CAAyB,yBAAzB,EAAoDL,QAApD,CAAP;EACD;;EAED,OAAO,IAAP;AACD,CATM"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { promotedProductListener, purchaseErrorListener, purchaseUpdatedListener } from '../eventEmitter';
|
|
2
|
+
import { promotedProductListener, purchaseErrorListener, purchaseUpdatedListener, transactionListener } from '../eventEmitter';
|
|
3
3
|
import { IapIos, initConnection } from '../iap';
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
const IAPContext = /*#__PURE__*/React.createContext(null);
|
|
@@ -21,6 +21,7 @@ export function withIAPContext(Component) {
|
|
|
21
21
|
const [purchaseHistory, setPurchaseHistory] = useState([]);
|
|
22
22
|
const [availablePurchases, setAvailablePurchases] = useState([]);
|
|
23
23
|
const [currentPurchase, setCurrentPurchase] = useState();
|
|
24
|
+
const [currentTransaction, setCurrentTransaction] = useState();
|
|
24
25
|
const [currentPurchaseError, setCurrentPurchaseError] = useState();
|
|
25
26
|
const [initConnectionError, setInitConnectionError] = useState();
|
|
26
27
|
const context = useMemo(() => ({
|
|
@@ -31,6 +32,7 @@ export function withIAPContext(Component) {
|
|
|
31
32
|
purchaseHistory,
|
|
32
33
|
availablePurchases,
|
|
33
34
|
currentPurchase,
|
|
35
|
+
currentTransaction,
|
|
34
36
|
currentPurchaseError,
|
|
35
37
|
initConnectionError,
|
|
36
38
|
setProducts,
|
|
@@ -39,7 +41,7 @@ export function withIAPContext(Component) {
|
|
|
39
41
|
setAvailablePurchases,
|
|
40
42
|
setCurrentPurchase,
|
|
41
43
|
setCurrentPurchaseError
|
|
42
|
-
}), [connected, products, subscriptions, promotedProductsIOS, purchaseHistory, availablePurchases, currentPurchase, currentPurchaseError, initConnectionError, setProducts, setSubscriptions, setPurchaseHistory, setAvailablePurchases, setCurrentPurchase, setCurrentPurchaseError]);
|
|
44
|
+
}), [connected, products, subscriptions, promotedProductsIOS, purchaseHistory, availablePurchases, currentPurchase, currentTransaction, currentPurchaseError, initConnectionError, setProducts, setSubscriptions, setPurchaseHistory, setAvailablePurchases, setCurrentPurchase, setCurrentPurchaseError]);
|
|
43
45
|
useEffect(() => {
|
|
44
46
|
initConnection().then(value => {
|
|
45
47
|
setInitConnectionError(undefined);
|
|
@@ -55,6 +57,10 @@ export function withIAPContext(Component) {
|
|
|
55
57
|
setCurrentPurchaseError(undefined);
|
|
56
58
|
setCurrentPurchase(purchase);
|
|
57
59
|
});
|
|
60
|
+
const transactionUpdateSubscription = transactionListener(async transactionOrError => {
|
|
61
|
+
setCurrentPurchaseError(transactionOrError === null || transactionOrError === void 0 ? void 0 : transactionOrError.error);
|
|
62
|
+
setCurrentTransaction(transactionOrError === null || transactionOrError === void 0 ? void 0 : transactionOrError.transaction);
|
|
63
|
+
});
|
|
58
64
|
const purchaseErrorSubscription = purchaseErrorListener(error => {
|
|
59
65
|
setCurrentPurchase(undefined);
|
|
60
66
|
setCurrentPurchaseError(error);
|
|
@@ -67,6 +73,7 @@ export function withIAPContext(Component) {
|
|
|
67
73
|
purchaseUpdateSubscription.remove();
|
|
68
74
|
purchaseErrorSubscription.remove();
|
|
69
75
|
promotedProductSubscription === null || promotedProductSubscription === void 0 ? void 0 : promotedProductSubscription.remove();
|
|
76
|
+
transactionUpdateSubscription === null || transactionUpdateSubscription === void 0 ? void 0 : transactionUpdateSubscription.remove();
|
|
70
77
|
};
|
|
71
78
|
}, [connected]);
|
|
72
79
|
return /*#__PURE__*/React.createElement(IAPContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useContext","useEffect","useMemo","useState","promotedProductListener","purchaseErrorListener","purchaseUpdatedListener","IapIos","initConnection","IAPContext","createContext","useIAPContext","ctx","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistory","setPurchaseHistory","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","then","value","undefined","catch","purchaseUpdateSubscription","purchase","
|
|
1
|
+
{"version":3,"names":["React","useContext","useEffect","useMemo","useState","promotedProductListener","purchaseErrorListener","purchaseUpdatedListener","transactionListener","IapIos","initConnection","IAPContext","createContext","useIAPContext","ctx","Error","withIAPContext","Component","WrapperComponent","props","connected","setConnected","products","setProducts","promotedProductsIOS","setPromotedProductsIOS","subscriptions","setSubscriptions","purchaseHistory","setPurchaseHistory","availablePurchases","setAvailablePurchases","currentPurchase","setCurrentPurchase","currentTransaction","setCurrentTransaction","currentPurchaseError","setCurrentPurchaseError","initConnectionError","setInitConnectionError","context","then","value","undefined","catch","purchaseUpdateSubscription","purchase","transactionUpdateSubscription","transactionOrError","error","transaction","purchaseErrorSubscription","promotedProductSubscription","product","getPromotedProductIOS","prevProducts","remove"],"sources":["withIAPContext.tsx"],"sourcesContent":["import React, {useContext, useEffect, useMemo, useState} from 'react';\n\nimport {\n promotedProductListener,\n purchaseErrorListener,\n purchaseUpdatedListener,\n transactionListener,\n} from '../eventEmitter';\nimport {IapIos, initConnection} from '../iap';\nimport type {PurchaseError} from '../purchaseError';\nimport type {\n Product,\n ProductPurchase,\n Purchase,\n Subscription,\n SubscriptionPurchase,\n} from '../types';\nimport type {TransactionEvent, TransactionSk2} from '../types/appleSk2';\n\ntype IAPContextType = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: Product[];\n subscriptions: Subscription[];\n purchaseHistory: Purchase[];\n availablePurchases: Purchase[];\n currentPurchase?: Purchase;\n currentTransaction?: TransactionSk2;\n currentPurchaseError?: PurchaseError;\n initConnectionError?: Error;\n setProducts: (products: Product[]) => void;\n setSubscriptions: (subscriptions: Subscription[]) => void;\n setPurchaseHistory: (purchaseHistory: Purchase[]) => void;\n setAvailablePurchases: (availablePurchases: Purchase[]) => void;\n setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;\n setCurrentPurchaseError: (\n currentPurchaseError: PurchaseError | undefined,\n ) => void;\n};\n\n// @ts-ignore\nconst IAPContext = React.createContext<IAPContextType>(null);\n\nexport function useIAPContext(): IAPContextType {\n const ctx = useContext(IAPContext);\n\n if (!ctx) {\n throw new Error('You need wrap your app with withIAPContext HOC');\n }\n\n return ctx;\n}\n\nexport function withIAPContext<T>(Component: React.ComponentType<T>) {\n return function WrapperComponent(props: T) {\n const [connected, setConnected] = useState(false);\n const [products, setProducts] = useState<Product[]>([]);\n\n const [promotedProductsIOS, setPromotedProductsIOS] = useState<Product[]>(\n [],\n );\n const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);\n const [purchaseHistory, setPurchaseHistory] = useState<Purchase[]>([]);\n\n const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>(\n [],\n );\n const [currentPurchase, setCurrentPurchase] = useState<Purchase>();\n const [currentTransaction, setCurrentTransaction] =\n useState<TransactionSk2>();\n\n const [currentPurchaseError, setCurrentPurchaseError] =\n useState<PurchaseError>();\n\n const [initConnectionError, setInitConnectionError] = useState<Error>();\n\n const context = useMemo(\n () => ({\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentTransaction,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistory,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n }),\n [\n connected,\n products,\n subscriptions,\n promotedProductsIOS,\n purchaseHistory,\n availablePurchases,\n currentPurchase,\n currentTransaction,\n currentPurchaseError,\n initConnectionError,\n setProducts,\n setSubscriptions,\n setPurchaseHistory,\n setAvailablePurchases,\n setCurrentPurchase,\n setCurrentPurchaseError,\n ],\n );\n\n useEffect(() => {\n initConnection()\n .then((value) => {\n setInitConnectionError(undefined);\n setConnected(value);\n })\n .catch(setInitConnectionError);\n }, []);\n\n useEffect(() => {\n if (!connected) {\n return;\n }\n\n const purchaseUpdateSubscription = purchaseUpdatedListener(\n async (purchase: ProductPurchase | SubscriptionPurchase) => {\n setCurrentPurchaseError(undefined);\n setCurrentPurchase(purchase);\n },\n );\n\n const transactionUpdateSubscription = transactionListener(\n async (transactionOrError: TransactionEvent) => {\n setCurrentPurchaseError(transactionOrError?.error);\n setCurrentTransaction(transactionOrError?.transaction);\n },\n );\n\n const purchaseErrorSubscription = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n },\n );\n\n const promotedProductSubscription = promotedProductListener(async () => {\n const product = await IapIos.getPromotedProductIOS();\n\n setPromotedProductsIOS((prevProducts) => [\n ...prevProducts,\n ...(product ? [product] : []),\n ]);\n });\n\n return () => {\n purchaseUpdateSubscription.remove();\n purchaseErrorSubscription.remove();\n promotedProductSubscription?.remove();\n transactionUpdateSubscription?.remove();\n };\n }, [connected]);\n\n return (\n <IAPContext.Provider value={context}>\n <Component {...props} />\n </IAPContext.Provider>\n );\n };\n}\n"],"mappings":"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"}
|
package/lib/module/iap.js
CHANGED
|
@@ -3,11 +3,12 @@ import * as IapAmazon from './modules/amazon';
|
|
|
3
3
|
import * as IapAndroid from './modules/android';
|
|
4
4
|
import * as IapIos from './modules/ios';
|
|
5
5
|
import * as IapIosSk2 from './modules/iosSk2';
|
|
6
|
+
import { offerToRecord } from './types/apple';
|
|
6
7
|
import { offerSk2Map, productSk2Map, subscriptionSk2Map } from './types/appleSk2';
|
|
7
|
-
import {
|
|
8
|
+
import { fillProductsWithAdditionalData, getAndroidModule, getIosModule, getNativeModule, isAmazon, isIosStorekit2, storekit1Mode, storekit2Mode, storekitHybridMode } from './internal';
|
|
8
9
|
import { ProductType } from './types';
|
|
9
10
|
import { PurchaseStateAndroid } from './types';
|
|
10
|
-
export { IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2
|
|
11
|
+
export { IapAndroid, IapAmazon, IapIos, IapIosSk2, isIosStorekit2 };
|
|
11
12
|
const {
|
|
12
13
|
RNIapIos,
|
|
13
14
|
RNIapIosSk2,
|
|
@@ -16,6 +17,38 @@ const {
|
|
|
16
17
|
} = NativeModules;
|
|
17
18
|
const ANDROID_ITEM_TYPE_SUBSCRIPTION = ProductType.subs;
|
|
18
19
|
const ANDROID_ITEM_TYPE_IAP = ProductType.inapp;
|
|
20
|
+
/**
|
|
21
|
+
* STOREKIT1_MODE: Will not enable Storekit 2 even if the device supports it. Thigs will work as before,
|
|
22
|
+
* minimum changes required in the migration guide (default)
|
|
23
|
+
* HYBRID_MODE: Will enable Storekit 2 for iOS devices > 15.0 but will fallback to Sk1 on older devices
|
|
24
|
+
* There are some edge cases that you need to handle in this case (described in migration guide). This mode
|
|
25
|
+
* is for developers that are migrating to Storekit 2 but want to keep supporting older versions.
|
|
26
|
+
* STOREKIT2_MODE: Will *only* enable Storekit 2. This disables Storekit 1. This is for apps that
|
|
27
|
+
* have already targeted a min version of 15 for their app.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export const setup = function () {
|
|
31
|
+
let {
|
|
32
|
+
storekitMode = 'STOREKIT1_MODE'
|
|
33
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
34
|
+
|
|
35
|
+
switch (storekitMode) {
|
|
36
|
+
case 'STOREKIT1_MODE':
|
|
37
|
+
storekit1Mode();
|
|
38
|
+
break;
|
|
39
|
+
|
|
40
|
+
case 'STOREKIT2_MODE':
|
|
41
|
+
storekit2Mode();
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case 'STOREKIT_HYBRID_MODE':
|
|
45
|
+
storekitHybridMode();
|
|
46
|
+
break;
|
|
47
|
+
|
|
48
|
+
default:
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
19
52
|
/**
|
|
20
53
|
* Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
|
|
21
54
|
* ## Usage
|
|
@@ -197,22 +230,29 @@ const App = () => {
|
|
|
197
230
|
return <View />;
|
|
198
231
|
};
|
|
199
232
|
```
|
|
233
|
+
@param {alsoPublishToEventListener}:boolean When `true`, every element will also be pushed to the purchaseUpdated listener.
|
|
234
|
+
Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to `false`
|
|
200
235
|
*/
|
|
201
236
|
|
|
202
|
-
export const getPurchaseHistory = ()
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return
|
|
209
|
-
}
|
|
237
|
+
export const getPurchaseHistory = function () {
|
|
238
|
+
let {
|
|
239
|
+
alsoPublishToEventListener = false
|
|
240
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
241
|
+
return (Platform.select({
|
|
242
|
+
ios: async () => {
|
|
243
|
+
return getIosModule().getAvailableItems(alsoPublishToEventListener);
|
|
244
|
+
},
|
|
245
|
+
android: async () => {
|
|
246
|
+
if (RNIapAmazonModule) {
|
|
247
|
+
return await RNIapAmazonModule.getAvailableItems();
|
|
248
|
+
}
|
|
210
249
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}) || (() => Promise.resolve([])))();
|
|
250
|
+
const products = await RNIapModule.getPurchaseHistoryByType(ANDROID_ITEM_TYPE_IAP);
|
|
251
|
+
const subscriptions = await RNIapModule.getPurchaseHistoryByType(ANDROID_ITEM_TYPE_SUBSCRIPTION);
|
|
252
|
+
return products.concat(subscriptions);
|
|
253
|
+
}
|
|
254
|
+
}) || (() => Promise.resolve([])))();
|
|
255
|
+
};
|
|
216
256
|
/**
|
|
217
257
|
* Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
|
|
218
258
|
* ## Usage
|
|
@@ -289,23 +329,30 @@ const App = () => {
|
|
|
289
329
|
)
|
|
290
330
|
};
|
|
291
331
|
```
|
|
332
|
+
@param {alsoPublishToEventListener}:boolean When `true`, every element will also be pushed to the purchaseUpdated listener.
|
|
333
|
+
Note that this is only for backaward compatiblity. It won't publish to transactionUpdated (Storekit2) Defaults to `false`
|
|
292
334
|
*
|
|
293
335
|
*/
|
|
294
336
|
|
|
295
|
-
export const getAvailablePurchases = ()
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return
|
|
302
|
-
}
|
|
337
|
+
export const getAvailablePurchases = function () {
|
|
338
|
+
let {
|
|
339
|
+
alsoPublishToEventListener = false
|
|
340
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
341
|
+
return (Platform.select({
|
|
342
|
+
ios: async () => {
|
|
343
|
+
return getIosModule().getAvailableItems(alsoPublishToEventListener);
|
|
344
|
+
},
|
|
345
|
+
android: async () => {
|
|
346
|
+
if (RNIapAmazonModule) {
|
|
347
|
+
return await RNIapAmazonModule.getAvailableItems();
|
|
348
|
+
}
|
|
303
349
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}) || (() => Promise.resolve([])))();
|
|
350
|
+
const products = await RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_IAP);
|
|
351
|
+
const subscriptions = await RNIapModule.getAvailableItemsByType(ANDROID_ITEM_TYPE_SUBSCRIPTION);
|
|
352
|
+
return products.concat(subscriptions);
|
|
353
|
+
}
|
|
354
|
+
}) || (() => Promise.resolve([])))();
|
|
355
|
+
};
|
|
309
356
|
/**
|
|
310
357
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
311
358
|
* Request a purchase for a product (consumables or non-consumables).
|
|
@@ -402,7 +449,7 @@ export const requestPurchase = _ref3 => {
|
|
|
402
449
|
const offer = offerSk2Map(withOffer);
|
|
403
450
|
return RNIapIosSk2.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer);
|
|
404
451
|
} else {
|
|
405
|
-
return RNIapIos.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, withOffer);
|
|
452
|
+
return RNIapIos.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offerToRecord(withOffer));
|
|
406
453
|
}
|
|
407
454
|
},
|
|
408
455
|
android: async () => {
|
|
@@ -530,7 +577,7 @@ export const requestSubscription = _ref4 => {
|
|
|
530
577
|
const offer = offerSk2Map(withOffer);
|
|
531
578
|
return RNIapIosSk2.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer);
|
|
532
579
|
} else {
|
|
533
|
-
return RNIapIos.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, withOffer);
|
|
580
|
+
return RNIapIos.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offerToRecord(withOffer));
|
|
534
581
|
}
|
|
535
582
|
},
|
|
536
583
|
android: async () => {
|