react-native-iap 9.0.4 → 10.0.2
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/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +2 -1
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +2 -1
- package/ios/RNIapIos.swift +848 -848
- package/lib/commonjs/eventEmitter.js +54 -0
- package/lib/commonjs/eventEmitter.js.map +1 -0
- package/lib/commonjs/hooks/useIAP.js +33 -15
- package/lib/commonjs/hooks/useIAP.js.map +1 -1
- package/lib/commonjs/hooks/withIAPContext.js +9 -7
- package/lib/commonjs/hooks/withIAPContext.js.map +1 -1
- package/lib/commonjs/iap.js +127 -197
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/index.js +28 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/enhancedFetch.js +30 -0
- package/lib/commonjs/internal/enhancedFetch.js.map +1 -0
- package/lib/commonjs/internal/fillProductsWithAdditionalData.js +47 -0
- package/lib/commonjs/internal/fillProductsWithAdditionalData.js.map +1 -0
- package/lib/commonjs/internal/index.js +45 -0
- package/lib/commonjs/internal/index.js.map +1 -0
- package/lib/commonjs/internal/platform.js +19 -0
- package/lib/commonjs/internal/platform.js.map +1 -0
- package/lib/commonjs/purchaseError.js +47 -0
- package/lib/commonjs/purchaseError.js.map +1 -0
- package/lib/commonjs/types/index.js +1 -23
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/eventEmitter.js +36 -0
- package/lib/module/eventEmitter.js.map +1 -0
- package/lib/module/hooks/useIAP.js +34 -16
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/hooks/withIAPContext.js +6 -5
- package/lib/module/hooks/withIAPContext.js.map +1 -1
- package/lib/module/iap.js +118 -185
- package/lib/module/iap.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/enhancedFetch.js +21 -0
- package/lib/module/internal/enhancedFetch.js.map +1 -0
- package/lib/module/internal/fillProductsWithAdditionalData.js +37 -0
- package/lib/module/internal/fillProductsWithAdditionalData.js.map +1 -0
- package/lib/module/internal/index.js +4 -0
- package/lib/module/internal/index.js.map +1 -0
- package/lib/module/internal/platform.js +8 -0
- package/lib/module/internal/platform.js.map +1 -0
- package/lib/module/purchaseError.js +38 -0
- package/lib/module/purchaseError.js.map +1 -0
- package/lib/module/types/index.js +0 -21
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/eventEmitter.d.ts +17 -0
- package/lib/typescript/hooks/useIAP.d.ts +15 -9
- package/lib/typescript/hooks/withIAPContext.d.ts +4 -3
- package/lib/typescript/iap.d.ts +80 -41
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/internal/enhancedFetch.d.ts +6 -0
- package/lib/typescript/internal/fillProductsWithAdditionalData.d.ts +5 -0
- package/lib/typescript/internal/index.d.ts +3 -0
- package/lib/typescript/internal/platform.d.ts +3 -0
- package/lib/typescript/purchaseError.d.ts +26 -0
- package/lib/typescript/types/index.d.ts +1 -48
- package/package.json +1 -1
- package/src/eventEmitter.ts +49 -0
- package/src/hooks/useIAP.ts +38 -35
- package/src/hooks/withIAPContext.tsx +12 -13
- package/src/iap.ts +151 -232
- package/src/index.ts +2 -4
- package/src/internal/enhancedFetch.ts +25 -0
- package/src/internal/fillProductsWithAdditionalData.ts +43 -0
- package/src/internal/index.ts +3 -0
- package/src/internal/platform.ts +7 -0
- package/src/purchaseError.ts +35 -0
- package/src/types/index.ts +1 -59
package/lib/typescript/iap.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { EmitterSubscription } from 'react-native';
|
|
2
1
|
import type * as Amazon from './types/amazon';
|
|
3
2
|
import type * as Android from './types/android';
|
|
4
3
|
import type * as Apple from './types/apple';
|
|
5
|
-
import type {
|
|
4
|
+
import type { Product, ProductPurchase, ProrationModesAndroid, PurchaseResult, Sku, Subscription, SubscriptionOffer, SubscriptionPurchase } from './types';
|
|
6
5
|
import { InstallSourceAndroid } from './types';
|
|
7
|
-
export declare class IapError implements PurchaseError {
|
|
8
|
-
code?: string | undefined;
|
|
9
|
-
message?: string | undefined;
|
|
10
|
-
constructor(code?: string | undefined, message?: string | undefined);
|
|
11
|
-
}
|
|
12
6
|
export declare const getInstallSourceAndroid: () => InstallSourceAndroid;
|
|
13
7
|
export declare const setAndroidNativeModule: (nativeModule: any) => void;
|
|
8
|
+
export declare const getAndroidModule: () => any;
|
|
9
|
+
export declare const getIosModule: () => any;
|
|
10
|
+
export declare const getNativeModule: () => any;
|
|
14
11
|
/**
|
|
15
12
|
* Init module for purchase flow. Required on Android. In ios it will check whether user canMakePayment.
|
|
16
13
|
* @returns {Promise<boolean>}
|
|
@@ -31,23 +28,27 @@ export declare const flushFailedPurchasesCachedAsPendingAndroid: () => Promise<s
|
|
|
31
28
|
* @param {string[]} skus The item skus
|
|
32
29
|
* @returns {Promise<Product[]>}
|
|
33
30
|
*/
|
|
34
|
-
export declare const getProducts: (skus:
|
|
31
|
+
export declare const getProducts: ({ skus, }: {
|
|
32
|
+
skus: string[];
|
|
33
|
+
}) => Promise<Array<Product>>;
|
|
35
34
|
/**
|
|
36
35
|
* Get a list of subscriptions
|
|
37
36
|
* @param {string[]} skus The item skus
|
|
38
37
|
* @returns {Promise<Subscription[]>}
|
|
39
38
|
*/
|
|
40
|
-
export declare const getSubscriptions: (skus:
|
|
39
|
+
export declare const getSubscriptions: ({ skus, }: {
|
|
40
|
+
skus: string[];
|
|
41
|
+
}) => Promise<Subscription[]>;
|
|
41
42
|
/**
|
|
42
43
|
* Gets an inventory of purchases made by the user regardless of consumption status
|
|
43
|
-
* @returns {Promise<(
|
|
44
|
+
* @returns {Promise<(ProductPurchase | SubscriptionPurchase)[]>}
|
|
44
45
|
*/
|
|
45
|
-
export declare const getPurchaseHistory: () => Promise<(
|
|
46
|
+
export declare const getPurchaseHistory: () => Promise<(ProductPurchase | SubscriptionPurchase)[]>;
|
|
46
47
|
/**
|
|
47
48
|
* Get all purchases made by the user (either non-consumable, or haven't been consumed yet)
|
|
48
|
-
* @returns {Promise<(
|
|
49
|
+
* @returns {Promise<(ProductPurchase | SubscriptionPurchase)[]>}
|
|
49
50
|
*/
|
|
50
|
-
export declare const getAvailablePurchases: () => Promise<(
|
|
51
|
+
export declare const getAvailablePurchases: () => Promise<(ProductPurchase | SubscriptionPurchase)[]>;
|
|
51
52
|
/**
|
|
52
53
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
53
54
|
* @param {string} sku The product's sku/ID
|
|
@@ -57,9 +58,18 @@ export declare const getAvailablePurchases: () => Promise<(InAppPurchase | Subsc
|
|
|
57
58
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
58
59
|
* @param {string[]} [skus] Product Ids to purchase. Note that this is only for Android. iOS only uses a single SKU. If not provided, it'll default to using [sku] for backward-compatibility
|
|
59
60
|
* @param {boolean} [isOfferPersonalized] Defaults to false, Only for Android V5
|
|
60
|
-
* @returns {Promise<
|
|
61
|
-
*/
|
|
62
|
-
export declare const requestPurchase: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid,
|
|
61
|
+
* @returns {Promise<ProductPurchase>}
|
|
62
|
+
*/
|
|
63
|
+
export declare const requestPurchase: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, skus, isOfferPersonalized, }: {
|
|
64
|
+
sku?: string | undefined;
|
|
65
|
+
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean | undefined;
|
|
66
|
+
applicationUsername?: string | undefined;
|
|
67
|
+
obfuscatedAccountIdAndroid?: string | undefined;
|
|
68
|
+
obfuscatedProfileIdAndroid?: string | undefined;
|
|
69
|
+
/** For Google Play Billing Library 5 https://developer.android.com/google/play/billing/integrate#personalized-price */
|
|
70
|
+
skus?: string[] | undefined;
|
|
71
|
+
isOfferPersonalized?: boolean | undefined;
|
|
72
|
+
}) => Promise<ProductPurchase>;
|
|
63
73
|
/**
|
|
64
74
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
65
75
|
* @param {string} [sku] The product's sku/ID
|
|
@@ -72,13 +82,28 @@ export declare const requestPurchase: ({ sku, andDangerouslyFinishTransactionAut
|
|
|
72
82
|
* @param {SubscriptionOffers[]} [subscriptionOffers] Array of SubscriptionOffers. Every sku must be paired with a corresponding offerToken
|
|
73
83
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
74
84
|
*/
|
|
75
|
-
export declare const requestSubscription: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, purchaseTokenAndroid, prorationModeAndroid, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid,
|
|
85
|
+
export declare const requestSubscription: ({ sku, andDangerouslyFinishTransactionAutomaticallyIOS, applicationUsername, purchaseTokenAndroid, prorationModeAndroid, subscriptionOffers, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, isOfferPersonalized, }: {
|
|
86
|
+
sku?: string | undefined;
|
|
87
|
+
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean | undefined;
|
|
88
|
+
applicationUsername?: string | undefined;
|
|
89
|
+
purchaseTokenAndroid?: string | undefined;
|
|
90
|
+
prorationModeAndroid?: ProrationModesAndroid | undefined;
|
|
91
|
+
/** For Google Play Billing Library 5 */
|
|
92
|
+
subscriptionOffers?: SubscriptionOffer[] | undefined;
|
|
93
|
+
obfuscatedAccountIdAndroid?: string | undefined;
|
|
94
|
+
obfuscatedProfileIdAndroid?: string | undefined;
|
|
95
|
+
/** For Google Play Billing Library 5 https://developer.android.com/google/play/billing/integrate#personalized-price */
|
|
96
|
+
isOfferPersonalized?: boolean | undefined;
|
|
97
|
+
}) => Promise<SubscriptionPurchase | null>;
|
|
76
98
|
/**
|
|
77
99
|
* Request a purchase for product. This will be received in `PurchaseUpdatedListener`.
|
|
78
100
|
* @param {string} sku The product's sku/ID
|
|
79
101
|
* @returns {Promise<void>}
|
|
80
102
|
*/
|
|
81
|
-
export declare const requestPurchaseWithQuantityIOS: (sku
|
|
103
|
+
export declare const requestPurchaseWithQuantityIOS: ({ sku, quantity, }: {
|
|
104
|
+
sku: Sku;
|
|
105
|
+
quantity: number;
|
|
106
|
+
}) => Promise<ProductPurchase>;
|
|
82
107
|
/**
|
|
83
108
|
* Finish Transaction (both platforms)
|
|
84
109
|
* Abstracts Finish Transaction
|
|
@@ -91,7 +116,11 @@ export declare const requestPurchaseWithQuantityIOS: (sku: string, quantity: num
|
|
|
91
116
|
* @param {string} developerPayloadAndroid Android developerPayload.
|
|
92
117
|
* @returns {Promise<string | void> }
|
|
93
118
|
*/
|
|
94
|
-
export declare const finishTransaction: (purchase
|
|
119
|
+
export declare const finishTransaction: ({ purchase, isConsumable, developerPayloadAndroid, }: {
|
|
120
|
+
purchase: ProductPurchase | ProductPurchase;
|
|
121
|
+
isConsumable?: boolean | undefined;
|
|
122
|
+
developerPayloadAndroid?: string | undefined;
|
|
123
|
+
}) => Promise<string | void>;
|
|
95
124
|
/**
|
|
96
125
|
* Clear Transaction (iOS only)
|
|
97
126
|
* Finish remaining transactions. Related to issue #257 and #801
|
|
@@ -111,13 +140,18 @@ export declare const clearProductsIOS: () => Promise<void>;
|
|
|
111
140
|
* @param {string} token The product's token (on Android)
|
|
112
141
|
* @returns {Promise<PurchaseResult | void>}
|
|
113
142
|
*/
|
|
114
|
-
export declare const acknowledgePurchaseAndroid: (token
|
|
143
|
+
export declare const acknowledgePurchaseAndroid: ({ token, developerPayload, }: {
|
|
144
|
+
token: string;
|
|
145
|
+
developerPayload?: string | undefined;
|
|
146
|
+
}) => Promise<PurchaseResult | void>;
|
|
115
147
|
/**
|
|
116
148
|
* Deep link to subscriptions screen on Android. No-op on iOS.
|
|
117
149
|
* @param {string} sku The product's SKU (on Android)
|
|
118
150
|
* @returns {Promise<void>}
|
|
119
151
|
*/
|
|
120
|
-
export declare const deepLinkToSubscriptionsAndroid: (sku:
|
|
152
|
+
export declare const deepLinkToSubscriptionsAndroid: ({ sku, }: {
|
|
153
|
+
sku: Sku;
|
|
154
|
+
}) => Promise<void>;
|
|
121
155
|
/**
|
|
122
156
|
* Should Add Store Payment (iOS only)
|
|
123
157
|
* Indicates the the App Store purchase should continue from the app instead of the App Store.
|
|
@@ -145,14 +179,21 @@ export declare const buyPromotedProductIOS: () => Promise<void>;
|
|
|
145
179
|
* @param {number} withOffer.timestamp The timestamp of the signature
|
|
146
180
|
* @returns {Promise<void>}
|
|
147
181
|
*/
|
|
148
|
-
export declare const requestPurchaseWithOfferIOS: (sku
|
|
182
|
+
export declare const requestPurchaseWithOfferIOS: ({ sku, forUser, withOffer, }: {
|
|
183
|
+
sku: Sku;
|
|
184
|
+
forUser: string;
|
|
185
|
+
withOffer: Apple.PaymentDiscount;
|
|
186
|
+
}) => Promise<void>;
|
|
149
187
|
/**
|
|
150
188
|
* Validate receipt for iOS.
|
|
151
189
|
* @param {object} receiptBody the receipt body to send to apple server.
|
|
152
190
|
* @param {boolean} isTest whether this is in test environment which is sandbox.
|
|
153
191
|
* @returns {Promise<Apple.ReceiptValidationResponse | false>}
|
|
154
192
|
*/
|
|
155
|
-
export declare const validateReceiptIos: (receiptBody
|
|
193
|
+
export declare const validateReceiptIos: ({ receiptBody, isTest, }: {
|
|
194
|
+
receiptBody: Record<string, unknown>;
|
|
195
|
+
isTest?: boolean | undefined;
|
|
196
|
+
}) => Promise<Apple.ReceiptValidationResponse | false>;
|
|
156
197
|
/**
|
|
157
198
|
* Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including
|
|
158
199
|
* your access token in the binary you ship to users is potentially dangerous.
|
|
@@ -164,7 +205,13 @@ export declare const validateReceiptIos: (receiptBody: Record<string, unknown>,
|
|
|
164
205
|
* @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.
|
|
165
206
|
* @returns {Promise<object>}
|
|
166
207
|
*/
|
|
167
|
-
export declare const validateReceiptAndroid: (packageName
|
|
208
|
+
export declare const validateReceiptAndroid: ({ packageName, productId, productToken, accessToken, isSub, }: {
|
|
209
|
+
packageName: string;
|
|
210
|
+
productId: string;
|
|
211
|
+
productToken: string;
|
|
212
|
+
accessToken: string;
|
|
213
|
+
isSub?: boolean | undefined;
|
|
214
|
+
}) => Promise<Android.ReceiptType>;
|
|
168
215
|
/**
|
|
169
216
|
* Validate receipt for Amazon. NOTE: This method is here for debugging purposes only. Including
|
|
170
217
|
* your developer secret in the binary you ship to users is potentially dangerous.
|
|
@@ -175,22 +222,12 @@ export declare const validateReceiptAndroid: (packageName: string, productId: st
|
|
|
175
222
|
* @param {boolean} useSandbox Defaults to true, use sandbox environment or production.
|
|
176
223
|
* @returns {Promise<object>}
|
|
177
224
|
*/
|
|
178
|
-
export declare const validateReceiptAmazon: (developerSecret
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Add IAP purchase error event
|
|
186
|
-
* @returns {callback(e: PurchaseError)}
|
|
187
|
-
*/
|
|
188
|
-
export declare const purchaseErrorListener: (listener: (errorEvent: PurchaseError) => void) => EmitterSubscription;
|
|
189
|
-
/**
|
|
190
|
-
* Add IAP promoted subscription event
|
|
191
|
-
* Only available on iOS
|
|
192
|
-
*/
|
|
193
|
-
export declare const promotedProductListener: (listener: (productId?: string) => void) => EmitterSubscription | null;
|
|
225
|
+
export declare const validateReceiptAmazon: ({ developerSecret, userId, receiptId, useSandbox, }: {
|
|
226
|
+
developerSecret: string;
|
|
227
|
+
userId: string;
|
|
228
|
+
receiptId: string;
|
|
229
|
+
useSandbox: boolean;
|
|
230
|
+
}) => Promise<Amazon.ReceiptType>;
|
|
194
231
|
/**
|
|
195
232
|
* Get the current receipt base64 encoded in IOS.
|
|
196
233
|
* @param {forceRefresh?:boolean}
|
|
@@ -202,7 +239,9 @@ export declare const getPendingPurchasesIOS: () => Promise<ProductPurchase[]>;
|
|
|
202
239
|
* @param {forceRefresh?:boolean}
|
|
203
240
|
* @returns {Promise<string>}
|
|
204
241
|
*/
|
|
205
|
-
export declare const getReceiptIOS: (forceRefresh
|
|
242
|
+
export declare const getReceiptIOS: ({ forceRefresh, }: {
|
|
243
|
+
forceRefresh?: boolean | undefined;
|
|
244
|
+
}) => Promise<string>;
|
|
206
245
|
/**
|
|
207
246
|
* Launches a modal to register the redeem offer code in IOS.
|
|
208
247
|
* @returns {Promise<null>}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare enum ErrorCode {
|
|
2
|
+
E_UNKNOWN = "E_UNKNOWN",
|
|
3
|
+
E_USER_CANCELLED = "E_USER_CANCELLED",
|
|
4
|
+
E_USER_ERROR = "E_USER_ERROR",
|
|
5
|
+
E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE",
|
|
6
|
+
E_REMOTE_ERROR = "E_REMOTE_ERROR",
|
|
7
|
+
E_NETWORK_ERROR = "E_NETWORK_ERROR",
|
|
8
|
+
E_SERVICE_ERROR = "E_SERVICE_ERROR",
|
|
9
|
+
E_RECEIPT_FAILED = "E_RECEIPT_FAILED",
|
|
10
|
+
E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED",
|
|
11
|
+
E_NOT_PREPARED = "E_NOT_PREPARED",
|
|
12
|
+
E_NOT_ENDED = "E_NOT_ENDED",
|
|
13
|
+
E_ALREADY_OWNED = "E_ALREADY_OWNED",
|
|
14
|
+
E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR",
|
|
15
|
+
E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR",
|
|
16
|
+
E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT"
|
|
17
|
+
}
|
|
18
|
+
export declare class PurchaseError implements Error {
|
|
19
|
+
name: string;
|
|
20
|
+
message: string;
|
|
21
|
+
responseCode?: number | undefined;
|
|
22
|
+
debugMessage?: string | undefined;
|
|
23
|
+
code?: ErrorCode | undefined;
|
|
24
|
+
productId?: string | undefined;
|
|
25
|
+
constructor(name: string, message: string, responseCode?: number | undefined, debugMessage?: string | undefined, code?: ErrorCode | undefined, productId?: string | undefined);
|
|
26
|
+
}
|
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
export declare type Sku = string;
|
|
2
|
-
export declare enum IAPErrorCode {
|
|
3
|
-
E_IAP_NOT_AVAILABLE = "E_IAP_NOT_AVAILABLE",
|
|
4
|
-
E_UNKNOWN = "E_UNKNOWN",
|
|
5
|
-
E_USER_CANCELLED = "E_USER_CANCELLED",
|
|
6
|
-
E_USER_ERROR = "E_USER_ERROR",
|
|
7
|
-
E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE",
|
|
8
|
-
E_REMOTE_ERROR = "E_REMOTE_ERROR",
|
|
9
|
-
E_NETWORK_ERROR = "E_NETWORK_ERROR",
|
|
10
|
-
E_SERVICE_ERROR = "E_SERVICE_ERROR",
|
|
11
|
-
E_RECEIPT_FAILED = "E_RECEIPT_FAILED",
|
|
12
|
-
E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED",
|
|
13
|
-
E_NOT_PREPARED = "E_NOT_PREPARED",
|
|
14
|
-
E_NOT_ENDED = "E_NOT_ENDED",
|
|
15
|
-
E_ALREADY_OWNED = "E_ALREADY_OWNED",
|
|
16
|
-
E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR",
|
|
17
|
-
E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR",
|
|
18
|
-
E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT"
|
|
19
|
-
}
|
|
20
2
|
export declare enum ProrationModesAndroid {
|
|
21
3
|
IMMEDIATE_WITH_TIME_PRORATION = 1,
|
|
22
4
|
IMMEDIATE_AND_CHARGE_PRORATED_PRICE = 2,
|
|
@@ -77,20 +59,12 @@ export interface PurchaseResult {
|
|
|
77
59
|
code?: string;
|
|
78
60
|
message?: string;
|
|
79
61
|
}
|
|
80
|
-
export interface PurchaseError {
|
|
81
|
-
responseCode?: number;
|
|
82
|
-
debugMessage?: string;
|
|
83
|
-
code?: string;
|
|
84
|
-
message?: string;
|
|
85
|
-
productId?: string;
|
|
86
|
-
}
|
|
87
|
-
export declare type InAppPurchase = ProductPurchase;
|
|
88
62
|
export interface SubscriptionPurchase extends ProductPurchase {
|
|
89
63
|
autoRenewingAndroid?: boolean;
|
|
90
64
|
originalTransactionDateIOS?: string;
|
|
91
65
|
originalTransactionIdentifierIOS?: string;
|
|
92
66
|
}
|
|
93
|
-
export declare type Purchase =
|
|
67
|
+
export declare type Purchase = ProductPurchase | SubscriptionPurchase;
|
|
94
68
|
export interface Discount {
|
|
95
69
|
identifier: string;
|
|
96
70
|
type: string;
|
|
@@ -141,20 +115,6 @@ export interface SubscriptionIOS extends ProductCommon {
|
|
|
141
115
|
subscriptionPeriodUnitIOS?: '' | 'YEAR' | 'MONTH' | 'WEEK' | 'DAY';
|
|
142
116
|
}
|
|
143
117
|
export declare type Subscription = SubscriptionAndroid & SubscriptionIOS;
|
|
144
|
-
export interface RequestPurchaseBaseAndroid {
|
|
145
|
-
obfuscatedAccountIdAndroid?: string;
|
|
146
|
-
obfuscatedProfileIdAndroid?: string;
|
|
147
|
-
isOfferPersonalized?: boolean;
|
|
148
|
-
}
|
|
149
|
-
export interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {
|
|
150
|
-
skus?: Sku[];
|
|
151
|
-
}
|
|
152
|
-
export interface RequestPurchaseIOS {
|
|
153
|
-
sku?: Sku;
|
|
154
|
-
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
|
|
155
|
-
applicationUsername?: string;
|
|
156
|
-
}
|
|
157
|
-
export declare type RequestPurchase = RequestPurchaseAndroid & RequestPurchaseIOS;
|
|
158
118
|
/**
|
|
159
119
|
* In order to purchase a new subscription, every sku must have a selected offerToken
|
|
160
120
|
* @see SubscriptionAndroid.subscriptionOfferDetails.offerToken
|
|
@@ -163,10 +123,3 @@ export interface SubscriptionOffer {
|
|
|
163
123
|
sku: Sku;
|
|
164
124
|
offerToken: string;
|
|
165
125
|
}
|
|
166
|
-
export interface RequestSubscriptionAndroid extends RequestPurchaseBaseAndroid {
|
|
167
|
-
purchaseTokenAndroid?: string;
|
|
168
|
-
prorationModeAndroid?: ProrationModesAndroid;
|
|
169
|
-
subscriptionOffers?: SubscriptionOffer[];
|
|
170
|
-
}
|
|
171
|
-
export declare type RequestSubscriptionIOS = RequestPurchaseIOS;
|
|
172
|
-
export declare type RequestSubscription = RequestSubscriptionAndroid & RequestSubscriptionIOS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.2",
|
|
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)",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {EmitterSubscription, NativeEventEmitter} from 'react-native';
|
|
2
|
+
|
|
3
|
+
import {getAndroidModule, getIosModule, getNativeModule} from './iap';
|
|
4
|
+
import {isAndroid, isIos} from './internal';
|
|
5
|
+
import type {PurchaseError} from './purchaseError';
|
|
6
|
+
import type {Purchase} from './types';
|
|
7
|
+
|
|
8
|
+
const eventEmitter = new NativeEventEmitter(getNativeModule());
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Add IAP purchase event
|
|
12
|
+
*/
|
|
13
|
+
export const purchaseUpdatedListener = (
|
|
14
|
+
listener: (event: Purchase) => void,
|
|
15
|
+
) => {
|
|
16
|
+
const emitterSubscription = eventEmitter.addListener(
|
|
17
|
+
'purchase-updated',
|
|
18
|
+
listener,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (isAndroid) {
|
|
22
|
+
getAndroidModule().startListening();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return emitterSubscription;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Add IAP purchase error event
|
|
30
|
+
*/
|
|
31
|
+
export const purchaseErrorListener = (
|
|
32
|
+
listener: (error: PurchaseError) => void,
|
|
33
|
+
): EmitterSubscription => eventEmitter.addListener('purchase-error', listener);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Add IAP promoted subscription event
|
|
37
|
+
*
|
|
38
|
+
* @platform iOS
|
|
39
|
+
*/
|
|
40
|
+
export const promotedProductListener = (listener: () => void) => {
|
|
41
|
+
if (isIos) {
|
|
42
|
+
return new NativeEventEmitter(getIosModule()).addListener(
|
|
43
|
+
'iap-promoted-product',
|
|
44
|
+
listener,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null;
|
|
49
|
+
};
|
package/src/hooks/useIAP.ts
CHANGED
|
@@ -4,12 +4,11 @@ import {
|
|
|
4
4
|
finishTransaction as iapFinishTransaction,
|
|
5
5
|
getAvailablePurchases as iapGetAvailablePurchases,
|
|
6
6
|
getProducts as iapGetProducts,
|
|
7
|
-
getPurchaseHistory,
|
|
7
|
+
getPurchaseHistory as iapGetPurchaseHistory,
|
|
8
8
|
getSubscriptions as iapGetSubscriptions,
|
|
9
|
-
requestPurchase as iapRequestPurchase,
|
|
10
|
-
requestSubscription as iapRequestSubscription,
|
|
11
9
|
} from '../iap';
|
|
12
|
-
import type {
|
|
10
|
+
import type {PurchaseError} from '../purchaseError';
|
|
11
|
+
import type {Product, Purchase, Subscription} from '../types';
|
|
13
12
|
|
|
14
13
|
import {useIAPContext} from './withIAPContext';
|
|
15
14
|
|
|
@@ -18,22 +17,24 @@ type IAP_STATUS = {
|
|
|
18
17
|
products: Product[];
|
|
19
18
|
promotedProductsIOS: Product[];
|
|
20
19
|
subscriptions: Subscription[];
|
|
21
|
-
|
|
20
|
+
purchaseHistory: Purchase[];
|
|
22
21
|
availablePurchases: Purchase[];
|
|
23
22
|
currentPurchase?: Purchase;
|
|
24
23
|
currentPurchaseError?: PurchaseError;
|
|
25
24
|
initConnectionError?: Error;
|
|
26
|
-
finishTransaction: (
|
|
27
|
-
purchase
|
|
28
|
-
isConsumable
|
|
29
|
-
developerPayloadAndroid
|
|
30
|
-
|
|
25
|
+
finishTransaction: ({
|
|
26
|
+
purchase,
|
|
27
|
+
isConsumable,
|
|
28
|
+
developerPayloadAndroid,
|
|
29
|
+
}: {
|
|
30
|
+
purchase: Purchase;
|
|
31
|
+
isConsumable?: boolean;
|
|
32
|
+
developerPayloadAndroid?: string;
|
|
33
|
+
}) => Promise<string | void>;
|
|
31
34
|
getAvailablePurchases: () => Promise<void>;
|
|
32
|
-
|
|
33
|
-
getProducts: (skus: string[]) => Promise<void>;
|
|
34
|
-
getSubscriptions: (skus: string[]) => Promise<void>;
|
|
35
|
-
requestPurchase: typeof iapRequestPurchase;
|
|
36
|
-
requestSubscription: typeof iapRequestSubscription;
|
|
35
|
+
getPurchaseHistory: () => Promise<void>;
|
|
36
|
+
getProducts: ({skus}: {skus: string[]}) => Promise<void>;
|
|
37
|
+
getSubscriptions: ({skus}: {skus: string[]}) => Promise<void>;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
export function useIAP(): IAP_STATUS {
|
|
@@ -42,7 +43,7 @@ export function useIAP(): IAP_STATUS {
|
|
|
42
43
|
products,
|
|
43
44
|
promotedProductsIOS,
|
|
44
45
|
subscriptions,
|
|
45
|
-
|
|
46
|
+
purchaseHistory,
|
|
46
47
|
availablePurchases,
|
|
47
48
|
currentPurchase,
|
|
48
49
|
currentPurchaseError,
|
|
@@ -50,21 +51,21 @@ export function useIAP(): IAP_STATUS {
|
|
|
50
51
|
setProducts,
|
|
51
52
|
setSubscriptions,
|
|
52
53
|
setAvailablePurchases,
|
|
53
|
-
|
|
54
|
+
setPurchaseHistory,
|
|
54
55
|
setCurrentPurchase,
|
|
55
56
|
setCurrentPurchaseError,
|
|
56
57
|
} = useIAPContext();
|
|
57
58
|
|
|
58
59
|
const getProducts = useCallback(
|
|
59
|
-
async (skus: string[]): Promise<void> => {
|
|
60
|
-
setProducts(await iapGetProducts(skus));
|
|
60
|
+
async ({skus}: {skus: string[]}): Promise<void> => {
|
|
61
|
+
setProducts(await iapGetProducts({skus}));
|
|
61
62
|
},
|
|
62
63
|
[setProducts],
|
|
63
64
|
);
|
|
64
65
|
|
|
65
66
|
const getSubscriptions = useCallback(
|
|
66
|
-
async (skus: string[]): Promise<void> => {
|
|
67
|
-
setSubscriptions(await iapGetSubscriptions(skus));
|
|
67
|
+
async ({skus}: {skus: string[]}): Promise<void> => {
|
|
68
|
+
setSubscriptions(await iapGetSubscriptions({skus}));
|
|
68
69
|
},
|
|
69
70
|
[setSubscriptions],
|
|
70
71
|
);
|
|
@@ -73,22 +74,26 @@ export function useIAP(): IAP_STATUS {
|
|
|
73
74
|
setAvailablePurchases(await iapGetAvailablePurchases());
|
|
74
75
|
}, [setAvailablePurchases]);
|
|
75
76
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
}, [
|
|
77
|
+
const getPurchaseHistory = useCallback(async (): Promise<void> => {
|
|
78
|
+
setPurchaseHistory(await iapGetPurchaseHistory());
|
|
79
|
+
}, [setPurchaseHistory]);
|
|
79
80
|
|
|
80
81
|
const finishTransaction = useCallback(
|
|
81
|
-
async (
|
|
82
|
-
purchase
|
|
83
|
-
isConsumable
|
|
84
|
-
developerPayloadAndroid
|
|
85
|
-
|
|
82
|
+
async ({
|
|
83
|
+
purchase,
|
|
84
|
+
isConsumable,
|
|
85
|
+
developerPayloadAndroid,
|
|
86
|
+
}: {
|
|
87
|
+
purchase: Purchase;
|
|
88
|
+
isConsumable?: boolean;
|
|
89
|
+
developerPayloadAndroid?: string;
|
|
90
|
+
}): Promise<string | void> => {
|
|
86
91
|
try {
|
|
87
|
-
return await iapFinishTransaction(
|
|
92
|
+
return await iapFinishTransaction({
|
|
88
93
|
purchase,
|
|
89
94
|
isConsumable,
|
|
90
95
|
developerPayloadAndroid,
|
|
91
|
-
);
|
|
96
|
+
});
|
|
92
97
|
} catch (err) {
|
|
93
98
|
throw err;
|
|
94
99
|
} finally {
|
|
@@ -114,7 +119,7 @@ export function useIAP(): IAP_STATUS {
|
|
|
114
119
|
products,
|
|
115
120
|
promotedProductsIOS,
|
|
116
121
|
subscriptions,
|
|
117
|
-
|
|
122
|
+
purchaseHistory,
|
|
118
123
|
availablePurchases,
|
|
119
124
|
currentPurchase,
|
|
120
125
|
currentPurchaseError,
|
|
@@ -123,8 +128,6 @@ export function useIAP(): IAP_STATUS {
|
|
|
123
128
|
getProducts,
|
|
124
129
|
getSubscriptions,
|
|
125
130
|
getAvailablePurchases,
|
|
126
|
-
|
|
127
|
-
requestPurchase: iapRequestPurchase,
|
|
128
|
-
requestSubscription: iapRequestSubscription,
|
|
131
|
+
getPurchaseHistory,
|
|
129
132
|
};
|
|
130
133
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import React, {useContext, useEffect, useMemo, useState} from 'react';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
getPromotedProductIOS,
|
|
5
|
-
initConnection,
|
|
6
4
|
promotedProductListener,
|
|
7
5
|
purchaseErrorListener,
|
|
8
6
|
purchaseUpdatedListener,
|
|
9
|
-
} from '../
|
|
7
|
+
} from '../eventEmitter';
|
|
8
|
+
import {getPromotedProductIOS, initConnection} from '../iap';
|
|
9
|
+
import type {PurchaseError} from '../purchaseError';
|
|
10
10
|
import type {
|
|
11
|
-
InAppPurchase,
|
|
12
11
|
Product,
|
|
12
|
+
ProductPurchase,
|
|
13
13
|
Purchase,
|
|
14
|
-
PurchaseError,
|
|
15
14
|
Subscription,
|
|
16
15
|
SubscriptionPurchase,
|
|
17
16
|
} from '../types';
|
|
@@ -21,14 +20,14 @@ type IAPContextType = {
|
|
|
21
20
|
products: Product[];
|
|
22
21
|
promotedProductsIOS: Product[];
|
|
23
22
|
subscriptions: Subscription[];
|
|
24
|
-
|
|
23
|
+
purchaseHistory: Purchase[];
|
|
25
24
|
availablePurchases: Purchase[];
|
|
26
25
|
currentPurchase?: Purchase;
|
|
27
26
|
currentPurchaseError?: PurchaseError;
|
|
28
27
|
initConnectionError?: Error;
|
|
29
28
|
setProducts: (products: Product[]) => void;
|
|
30
29
|
setSubscriptions: (subscriptions: Subscription[]) => void;
|
|
31
|
-
|
|
30
|
+
setPurchaseHistory: (purchaseHistory: Purchase[]) => void;
|
|
32
31
|
setAvailablePurchases: (availablePurchases: Purchase[]) => void;
|
|
33
32
|
setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;
|
|
34
33
|
setCurrentPurchaseError: (
|
|
@@ -58,7 +57,7 @@ export function withIAPContext<T>(Component: React.ComponentType<T>) {
|
|
|
58
57
|
[],
|
|
59
58
|
);
|
|
60
59
|
const [subscriptions, setSubscriptions] = useState<Subscription[]>([]);
|
|
61
|
-
const [
|
|
60
|
+
const [purchaseHistory, setPurchaseHistory] = useState<Purchase[]>([]);
|
|
62
61
|
|
|
63
62
|
const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>(
|
|
64
63
|
[],
|
|
@@ -76,14 +75,14 @@ export function withIAPContext<T>(Component: React.ComponentType<T>) {
|
|
|
76
75
|
products,
|
|
77
76
|
subscriptions,
|
|
78
77
|
promotedProductsIOS,
|
|
79
|
-
|
|
78
|
+
purchaseHistory,
|
|
80
79
|
availablePurchases,
|
|
81
80
|
currentPurchase,
|
|
82
81
|
currentPurchaseError,
|
|
83
82
|
initConnectionError,
|
|
84
83
|
setProducts,
|
|
85
84
|
setSubscriptions,
|
|
86
|
-
|
|
85
|
+
setPurchaseHistory,
|
|
87
86
|
setAvailablePurchases,
|
|
88
87
|
setCurrentPurchase,
|
|
89
88
|
setCurrentPurchaseError,
|
|
@@ -93,14 +92,14 @@ export function withIAPContext<T>(Component: React.ComponentType<T>) {
|
|
|
93
92
|
products,
|
|
94
93
|
subscriptions,
|
|
95
94
|
promotedProductsIOS,
|
|
96
|
-
|
|
95
|
+
purchaseHistory,
|
|
97
96
|
availablePurchases,
|
|
98
97
|
currentPurchase,
|
|
99
98
|
currentPurchaseError,
|
|
100
99
|
initConnectionError,
|
|
101
100
|
setProducts,
|
|
102
101
|
setSubscriptions,
|
|
103
|
-
|
|
102
|
+
setPurchaseHistory,
|
|
104
103
|
setAvailablePurchases,
|
|
105
104
|
setCurrentPurchase,
|
|
106
105
|
setCurrentPurchaseError,
|
|
@@ -122,7 +121,7 @@ export function withIAPContext<T>(Component: React.ComponentType<T>) {
|
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
const purchaseUpdateSubscription = purchaseUpdatedListener(
|
|
125
|
-
async (purchase:
|
|
124
|
+
async (purchase: ProductPurchase | SubscriptionPurchase) => {
|
|
126
125
|
setCurrentPurchaseError(undefined);
|
|
127
126
|
setCurrentPurchase(purchase);
|
|
128
127
|
},
|