Skip to content

Commit ed32a56

Browse files
author
hero
committed
chore: Rename oldProductId to originalPurchaseToken when updating subscription
1 parent 16c9495 commit ed32a56

File tree

4 files changed

+46
-37
lines changed

4 files changed

+46
-37
lines changed

android/src/main/java/net/class101/iap/RNInAppPurchaseModule.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,22 @@ public void fetchProducts(ReadableArray productIds) {
158158
* Purchase in-app or subscription item.
159159
*
160160
* @param productId Unique ID of item to purchase.
161-
* @param oldProductId When upgrading or downgrading a subscription, the unique ID of the
162-
* subscription item that user originally used.
161+
* @param originalPurchaseToken When upgrading or downgrading a subscription, purchase token
162+
* of the subscription that user originally used.
163163
*/
164164
@ReactMethod
165-
public void purchase(String productId, @Nullable String oldProductId) {
165+
public void purchase(String productId, @Nullable String originalPurchaseToken) {
166166
tryConnect(() -> {
167167
if (getCurrentActivity() == null) {
168168
return;
169169
}
170170

171171
BillingFlowParams.Builder builder = BillingFlowParams.newBuilder();
172172

173-
if (oldProductId != null) {
173+
if (originalPurchaseToken != null) {
174174
builder.setSubscriptionUpdateParams(
175175
BillingFlowParams.SubscriptionUpdateParams.newBuilder()
176-
.setOldSkuPurchaseToken(oldProductId)
176+
.setOldSkuPurchaseToken(originalPurchaseToken)
177177
.build()
178178
);
179179
}

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare module "@class101/react-native-in-app-purchase" {
3838

3939
function fetchProducts(productIds: string[]): void;
4040

41-
function purchase(productId: string, oldProductId?: string): void;
41+
function purchase(productId: string, originalPurchaseToken?: string): void;
4242

4343
function finalize(purchase: Purchase, isConsumable: boolean): Promise<void>;
4444

index.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,61 +3,70 @@ import {
33
NativeEventEmitter,
44
DeviceEventEmitter,
55
Platform,
6-
} from 'react-native';
6+
} from "react-native";
77

88
const { RNInAppPurchase } = NativeModules;
99

1010
const ERROR = {
11-
FETCH_PRODUCTS: 'FETCH_PRODUCTS',
12-
PURCHASE: 'PURCHASE',
13-
CONNECTION: 'CONNECTION',
11+
FETCH_PRODUCTS: "FETCH_PRODUCTS",
12+
PURCHASE: "PURCHASE",
13+
CONNECTION: "CONNECTION",
1414
};
1515

16-
const addListener = (event, listener) => Platform.select({
17-
ios: new NativeEventEmitter(RNInAppPurchase),
18-
android: DeviceEventEmitter,
19-
}).addListener(event, listener);
16+
const addListener = (event, listener) =>
17+
Platform.select({
18+
ios: new NativeEventEmitter(RNInAppPurchase),
19+
android: DeviceEventEmitter,
20+
}).addListener(event, listener);
2021

21-
const removeAllListeners = (event) => Platform.select({
22-
ios: new NativeEventEmitter(RNInAppPurchase),
23-
android: DeviceEventEmitter,
24-
}).removeAllListeners(event);
22+
const removeAllListeners = (event) =>
23+
Platform.select({
24+
ios: new NativeEventEmitter(RNInAppPurchase),
25+
android: DeviceEventEmitter,
26+
}).removeAllListeners(event);
2527

26-
const onFetchProducts = listener => addListener('iap:onFetchProductsSuccess', listener);
28+
const onFetchProducts = (listener) =>
29+
addListener("iap:onFetchProductsSuccess", listener);
2730

28-
const onPurchase = listener => addListener('iap:onPurchaseSuccess', listener);
31+
const onPurchase = (listener) => addListener("iap:onPurchaseSuccess", listener);
2932

3033
const onError = (listener) => {
31-
if (Platform.OS === 'android') {
32-
addListener('iap:onConnectionFailure', e => listener(Object.assign(e, { type: ERROR.CONNECTION })));
34+
if (Platform.OS === "android") {
35+
addListener("iap:onConnectionFailure", (e) =>
36+
listener(Object.assign(e, { type: ERROR.CONNECTION }))
37+
);
3338
}
34-
addListener('iap:onFetchProductsFailure', e => listener(Object.assign(e, { type: ERROR.FETCH_PRODUCTS })));
35-
addListener('iap:onPurchaseFailure', e => listener(Object.assign(e, { type: ERROR.PURCHASE })));
39+
addListener("iap:onFetchProductsFailure", (e) =>
40+
listener(Object.assign(e, { type: ERROR.FETCH_PRODUCTS }))
41+
);
42+
addListener("iap:onPurchaseFailure", (e) =>
43+
listener(Object.assign(e, { type: ERROR.PURCHASE }))
44+
);
3645
};
3746

3847
const clear = () => {
39-
removeAllListeners('iap:onFetchProductsSuccess');
40-
removeAllListeners('iap:onPurchaseSuccess');
41-
removeAllListeners('iap:onFetchProductsFailure');
42-
removeAllListeners('iap:onPurchaseFailure');
43-
if (Platform.OS === 'android') {
44-
removeAllListeners('iap:onConnectionFailure');
48+
removeAllListeners("iap:onFetchProductsSuccess");
49+
removeAllListeners("iap:onPurchaseSuccess");
50+
removeAllListeners("iap:onFetchProductsFailure");
51+
removeAllListeners("iap:onPurchaseFailure");
52+
if (Platform.OS === "android") {
53+
removeAllListeners("iap:onConnectionFailure");
4554
}
4655
};
4756

48-
const purchase = (productId, oldProductId) => {
49-
if (Platform.OS === 'android') {
50-
RNInAppPurchase.purchase(productId, oldProductId || null);
57+
const purchase = (productId, originalPurchaseToken) => {
58+
if (Platform.OS === "android") {
59+
RNInAppPurchase.purchase(productId, originalPurchaseToken || null);
5160
} else {
5261
RNInAppPurchase.purchase(productId);
5362
}
5463
};
5564

5665
const finalize = (purchase, isConsumable) => {
57-
return Platform.OS === 'android'
66+
return Platform.OS === "android"
5867
? RNInAppPurchase.finalize(purchase, isConsumable)
5968
: RNInAppPurchase.finalize(purchase);
60-
}
69+
};
6170

6271
export default {
6372
configure: RNInAppPurchase.configure,
@@ -70,4 +79,4 @@ export default {
7079
onError,
7180
clear,
7281
ERROR,
73-
}
82+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@class101/react-native-in-app-purchase",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "👻 A dead simple in app purchase library for React Native",
55
"main": "index.js",
66
"repository": "https://github.com/pedaling/react-native-in-app-purchase",

0 commit comments

Comments
 (0)