react-native-iap 9.0.0-rc.1 → 9.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/android/src/amazon/java/com/dooboolab/RNIap/RNIapAmazonModule.kt +0 -5
- package/android/src/play/java/com/dooboolab/RNIap/RNIapModule.kt +90 -82
- package/ios/RNIapIos.swift +30 -17
- package/lib/commonjs/iap.js +22 -7
- package/lib/commonjs/iap.js.map +1 -1
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/module/iap.js +22 -7
- package/lib/module/iap.js.map +1 -1
- package/lib/module/types/index.js.map +1 -1
- package/lib/typescript/iap.d.ts +5 -4
- package/lib/typescript/types/index.d.ts +39 -20
- package/package.json +1 -1
- package/src/iap.ts +30 -14
- package/src/types/index.ts +45 -20
|
@@ -101,27 +101,30 @@ export interface Discount {
|
|
|
101
101
|
}
|
|
102
102
|
export interface Product extends ProductCommon {
|
|
103
103
|
type: 'inapp' | 'iap';
|
|
104
|
+
oneTimePurchaseOfferDetails?: {
|
|
105
|
+
priceCurrencyCode: string;
|
|
106
|
+
formattedPrice: string;
|
|
107
|
+
priceAmountMicros: string;
|
|
108
|
+
};
|
|
104
109
|
}
|
|
105
110
|
export interface SubscriptionAndroid extends ProductCommon {
|
|
106
111
|
type: 'subs';
|
|
107
112
|
productType?: string;
|
|
108
113
|
name?: string;
|
|
109
|
-
oneTimePurchaseOfferDetails?: {
|
|
110
|
-
priceCurrencyCode?: string;
|
|
111
|
-
formattedPrice?: string;
|
|
112
|
-
priceAmountMicros?: string;
|
|
113
|
-
}[];
|
|
114
114
|
subscriptionOfferDetails?: {
|
|
115
|
-
offerToken
|
|
115
|
+
offerToken: string;
|
|
116
116
|
pricingPhases: {
|
|
117
117
|
pricingPhaseList: {
|
|
118
|
-
formattedPrice
|
|
119
|
-
priceCurrencyCode
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
formattedPrice: string;
|
|
119
|
+
priceCurrencyCode: string;
|
|
120
|
+
/**
|
|
121
|
+
* P1W, P1M, P1Y
|
|
122
|
+
*/
|
|
123
|
+
billingPeriod: string;
|
|
124
|
+
billingCycleCount: number;
|
|
125
|
+
priceAmountMicros: string;
|
|
126
|
+
recurrenceMode: number;
|
|
127
|
+
}[];
|
|
125
128
|
};
|
|
126
129
|
}[];
|
|
127
130
|
}
|
|
@@ -137,16 +140,32 @@ export interface SubscriptionIOS extends ProductCommon {
|
|
|
137
140
|
subscriptionPeriodUnitIOS?: '' | 'YEAR' | 'MONTH' | 'WEEK' | 'DAY';
|
|
138
141
|
}
|
|
139
142
|
export declare type Subscription = SubscriptionAndroid & SubscriptionIOS;
|
|
140
|
-
export interface
|
|
141
|
-
sku: Sku;
|
|
142
|
-
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
|
|
143
|
-
applicationUsername?: string;
|
|
143
|
+
export interface RequestPurchaseBaseAndroid {
|
|
144
144
|
obfuscatedAccountIdAndroid?: string;
|
|
145
145
|
obfuscatedProfileIdAndroid?: string;
|
|
146
|
+
isOfferPersonalized?: boolean;
|
|
147
|
+
}
|
|
148
|
+
export interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {
|
|
149
|
+
skus?: Sku[];
|
|
150
|
+
}
|
|
151
|
+
export interface RequestPurchaseIOS {
|
|
152
|
+
sku?: Sku;
|
|
153
|
+
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
|
|
154
|
+
applicationUsername?: string;
|
|
155
|
+
}
|
|
156
|
+
export declare type RequestPurchase = RequestPurchaseAndroid & RequestPurchaseIOS;
|
|
157
|
+
/**
|
|
158
|
+
* In order to purchase a new subscription, every sku must have a selected offerToken
|
|
159
|
+
* @see SubscriptionAndroid.subscriptionOfferDetails.offerToken
|
|
160
|
+
*/
|
|
161
|
+
export interface SubscriptionOffer {
|
|
162
|
+
sku: Sku;
|
|
163
|
+
offerToken: string;
|
|
146
164
|
}
|
|
147
|
-
export interface
|
|
165
|
+
export interface RequestSubscriptionAndroid extends RequestPurchaseBaseAndroid {
|
|
148
166
|
purchaseTokenAndroid?: string;
|
|
149
167
|
prorationModeAndroid?: ProrationModesAndroid;
|
|
150
|
-
|
|
151
|
-
skus?: string[] | undefined;
|
|
168
|
+
subscriptionOffers?: SubscriptionOffer[];
|
|
152
169
|
}
|
|
170
|
+
export declare type RequestSubscriptionIOS = RequestPurchaseIOS;
|
|
171
|
+
export declare type RequestSubscription = RequestSubscriptionAndroid & RequestSubscriptionIOS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-iap",
|
|
3
|
-
"version": "9.0.0-rc.
|
|
3
|
+
"version": "9.0.0-rc.4",
|
|
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
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
|
|
31
31
|
const {RNIapIos, RNIapModule, RNIapAmazonModule} = NativeModules;
|
|
32
32
|
const isAndroid = Platform.OS === 'android';
|
|
33
|
+
const isAmazon = isAndroid && !!RNIapAmazonModule;
|
|
33
34
|
const isIos = Platform.OS === 'ios';
|
|
34
35
|
const ANDROID_ITEM_TYPE_SUBSCRIPTION = 'subs';
|
|
35
36
|
const ANDROID_ITEM_TYPE_IAP = 'inapp';
|
|
@@ -273,6 +274,8 @@ export const getAvailablePurchases = (): Promise<
|
|
|
273
274
|
* @param {boolean} [andDangerouslyFinishTransactionAutomaticallyIOS] You should set this to false and call finishTransaction manually when you have delivered the purchased goods to the user. It defaults to true to provide backwards compatibility. Will default to false in version 4.0.0.
|
|
274
275
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
275
276
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
277
|
+
* @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
|
|
278
|
+
* @param {boolean} [isOfferPersonalized] Defaults to false, Only for Android V5
|
|
276
279
|
* @returns {Promise<InAppPurchase>}
|
|
277
280
|
*/
|
|
278
281
|
|
|
@@ -282,6 +285,8 @@ export const requestPurchase = ({
|
|
|
282
285
|
obfuscatedAccountIdAndroid,
|
|
283
286
|
obfuscatedProfileIdAndroid,
|
|
284
287
|
applicationUsername,
|
|
288
|
+
skus, // Android Billing V5
|
|
289
|
+
isOfferPersonalized = undefined, // Android Billing V5
|
|
285
290
|
}: RequestPurchase): Promise<InAppPurchase> =>
|
|
286
291
|
(
|
|
287
292
|
Platform.select({
|
|
@@ -301,12 +306,13 @@ export const requestPurchase = ({
|
|
|
301
306
|
android: async () => {
|
|
302
307
|
return getAndroidModule().buyItemByType(
|
|
303
308
|
ANDROID_ITEM_TYPE_IAP,
|
|
304
|
-
[sku],
|
|
309
|
+
skus?.length ? skus : [sku],
|
|
305
310
|
null,
|
|
306
311
|
-1,
|
|
307
312
|
obfuscatedAccountIdAndroid,
|
|
308
313
|
obfuscatedProfileIdAndroid,
|
|
309
314
|
undefined,
|
|
315
|
+
isOfferPersonalized ?? false,
|
|
310
316
|
);
|
|
311
317
|
},
|
|
312
318
|
}) || Promise.resolve
|
|
@@ -321,8 +327,7 @@ export const requestPurchase = ({
|
|
|
321
327
|
* @param {ProrationModesAndroid} [prorationModeAndroid] UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY, IMMEDIATE_WITH_TIME_PRORATION, IMMEDIATE_AND_CHARGE_PRORATED_PRICE, IMMEDIATE_WITHOUT_PRORATION, DEFERRED
|
|
322
328
|
* @param {string} [obfuscatedAccountIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's account in your app.
|
|
323
329
|
* @param {string} [obfuscatedProfileIdAndroid] Specifies an optional obfuscated string that is uniquely associated with the user's profile in your app.
|
|
324
|
-
* @param {
|
|
325
|
-
* @param {string[]} [skus] Skus to purchase, if more than one, otherwise it'll default to sku
|
|
330
|
+
* @param {SubscriptionOffers[]} [subscriptionOffers] Array of SubscriptionOffers. Every sku must be paired with a corresponding offerToken
|
|
326
331
|
* @returns {Promise<SubscriptionPurchase | null>} Promise resolves to null when using proratioModesAndroid=DEFERRED, and to a SubscriptionPurchase otherwise
|
|
327
332
|
*/
|
|
328
333
|
export const requestSubscription = ({
|
|
@@ -332,8 +337,8 @@ export const requestSubscription = ({
|
|
|
332
337
|
prorationModeAndroid = -1,
|
|
333
338
|
obfuscatedAccountIdAndroid,
|
|
334
339
|
obfuscatedProfileIdAndroid,
|
|
335
|
-
|
|
336
|
-
|
|
340
|
+
subscriptionOffers = undefined, // Android Billing V5
|
|
341
|
+
isOfferPersonalized = undefined, // Android Billing V5
|
|
337
342
|
applicationUsername,
|
|
338
343
|
}: RequestSubscription): Promise<SubscriptionPurchase | null> =>
|
|
339
344
|
(
|
|
@@ -352,15 +357,26 @@ export const requestSubscription = ({
|
|
|
352
357
|
);
|
|
353
358
|
},
|
|
354
359
|
android: async () => {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
360
|
+
if (isAmazon) {
|
|
361
|
+
return RNIapAmazonModule.buyItemByType(sku);
|
|
362
|
+
} else {
|
|
363
|
+
if (!subscriptionOffers?.length) {
|
|
364
|
+
Promise.reject(
|
|
365
|
+
'subscriptionOffers are required for Google Play Subscriptions',
|
|
366
|
+
);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
return RNIapModule.buyItemByType(
|
|
370
|
+
ANDROID_ITEM_TYPE_SUBSCRIPTION,
|
|
371
|
+
subscriptionOffers?.map((so) => so.sku),
|
|
372
|
+
purchaseTokenAndroid,
|
|
373
|
+
prorationModeAndroid,
|
|
374
|
+
obfuscatedAccountIdAndroid,
|
|
375
|
+
obfuscatedProfileIdAndroid,
|
|
376
|
+
subscriptionOffers?.map((so) => so.offerToken),
|
|
377
|
+
isOfferPersonalized ?? false,
|
|
378
|
+
);
|
|
379
|
+
}
|
|
364
380
|
},
|
|
365
381
|
}) || Promise.resolve
|
|
366
382
|
)();
|
package/src/types/index.ts
CHANGED
|
@@ -118,6 +118,12 @@ export interface Discount {
|
|
|
118
118
|
|
|
119
119
|
export interface Product extends ProductCommon {
|
|
120
120
|
type: 'inapp' | 'iap';
|
|
121
|
+
// Android V5
|
|
122
|
+
oneTimePurchaseOfferDetails?: {
|
|
123
|
+
priceCurrencyCode: string;
|
|
124
|
+
formattedPrice: string;
|
|
125
|
+
priceAmountMicros: string;
|
|
126
|
+
};
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
//Android V5
|
|
@@ -126,22 +132,20 @@ export interface SubscriptionAndroid extends ProductCommon {
|
|
|
126
132
|
|
|
127
133
|
productType?: string;
|
|
128
134
|
name?: string;
|
|
129
|
-
oneTimePurchaseOfferDetails?: {
|
|
130
|
-
priceCurrencyCode?: string;
|
|
131
|
-
formattedPrice?: string;
|
|
132
|
-
priceAmountMicros?: string;
|
|
133
|
-
}[];
|
|
134
135
|
subscriptionOfferDetails?: {
|
|
135
|
-
offerToken
|
|
136
|
+
offerToken: string;
|
|
136
137
|
pricingPhases: {
|
|
137
138
|
pricingPhaseList: {
|
|
138
|
-
formattedPrice
|
|
139
|
-
priceCurrencyCode
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
139
|
+
formattedPrice: string;
|
|
140
|
+
priceCurrencyCode: string;
|
|
141
|
+
/**
|
|
142
|
+
* P1W, P1M, P1Y
|
|
143
|
+
*/
|
|
144
|
+
billingPeriod: string;
|
|
145
|
+
billingCycleCount: number;
|
|
146
|
+
priceAmountMicros: string;
|
|
147
|
+
recurrenceMode: number;
|
|
148
|
+
}[];
|
|
145
149
|
};
|
|
146
150
|
}[];
|
|
147
151
|
}
|
|
@@ -171,17 +175,38 @@ export interface SubscriptionIOS extends ProductCommon {
|
|
|
171
175
|
|
|
172
176
|
export type Subscription = SubscriptionAndroid & SubscriptionIOS;
|
|
173
177
|
|
|
174
|
-
export interface
|
|
175
|
-
sku: Sku;
|
|
176
|
-
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
|
|
177
|
-
applicationUsername?: string;
|
|
178
|
+
export interface RequestPurchaseBaseAndroid {
|
|
178
179
|
obfuscatedAccountIdAndroid?: string;
|
|
179
180
|
obfuscatedProfileIdAndroid?: string;
|
|
181
|
+
isOfferPersonalized?: boolean; // For AndroidBilling V5 https://developer.android.com/google/play/billing/integrate#personalized-price
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {
|
|
185
|
+
skus?: Sku[];
|
|
180
186
|
}
|
|
181
187
|
|
|
182
|
-
export interface
|
|
188
|
+
export interface RequestPurchaseIOS {
|
|
189
|
+
sku?: Sku;
|
|
190
|
+
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
|
|
191
|
+
applicationUsername?: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export type RequestPurchase = RequestPurchaseAndroid & RequestPurchaseIOS;
|
|
195
|
+
/**
|
|
196
|
+
* In order to purchase a new subscription, every sku must have a selected offerToken
|
|
197
|
+
* @see SubscriptionAndroid.subscriptionOfferDetails.offerToken
|
|
198
|
+
*/
|
|
199
|
+
export interface SubscriptionOffer {
|
|
200
|
+
sku: Sku;
|
|
201
|
+
offerToken: string;
|
|
202
|
+
}
|
|
203
|
+
export interface RequestSubscriptionAndroid extends RequestPurchaseBaseAndroid {
|
|
183
204
|
purchaseTokenAndroid?: string;
|
|
184
205
|
prorationModeAndroid?: ProrationModesAndroid;
|
|
185
|
-
|
|
186
|
-
skus?: string[] | undefined; // For AndroidBilling V5
|
|
206
|
+
subscriptionOffers?: SubscriptionOffer[]; // For AndroidBilling V5
|
|
187
207
|
}
|
|
208
|
+
|
|
209
|
+
export type RequestSubscriptionIOS = RequestPurchaseIOS;
|
|
210
|
+
|
|
211
|
+
export type RequestSubscription = RequestSubscriptionAndroid &
|
|
212
|
+
RequestSubscriptionIOS;
|