Skip to content

Commit 9369e6f

Browse files
authored
Fix missing parameter in purchaseProduct (#129)
* adds missing parameter * reverts sample * updates test * Fixes another test
1 parent 1c8796b commit 9369e6f

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

__tests__/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ describe("Purchases", () => {
193193

194194
Purchases.makePurchase("onemonth_freetrial");
195195

196-
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", null, "subs");
196+
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", null, "subs", null);
197197
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledTimes(1);
198198

199199
Purchases.makePurchase("onemonth_freetrial", "viejo", Purchases.PURCHASE_TYPE.INAPP);
200200

201-
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial",{ oldSKU: "viejo" }, Purchases.PURCHASE_TYPE.INAPP);
201+
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial",{ oldSKU: "viejo" }, Purchases.PURCHASE_TYPE.INAPP, null);
202202
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledTimes(2);
203203
});
204204

@@ -212,22 +212,22 @@ describe("Purchases", () => {
212212

213213
Purchases.purchaseProduct("onemonth_freetrial")
214214

215-
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", undefined, "subs");
215+
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", undefined, "subs", null);
216216
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledTimes(1);
217217

218218
Purchases.purchaseProduct("onemonth_freetrial", {
219219
oldSKU: "viejo"
220220
}, Purchases.PURCHASE_TYPE.INAPP)
221221

222-
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", { oldSKU: "viejo" }, Purchases.PURCHASE_TYPE.INAPP);
222+
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", { oldSKU: "viejo" }, Purchases.PURCHASE_TYPE.INAPP, null);
223223
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledTimes(2);
224224

225225
Purchases.purchaseProduct("onemonth_freetrial", {
226226
oldSKU: "viejo",
227227
prorationMode: Purchases.PRORATION_MODE.DEFERRED
228228
}, Purchases.PURCHASE_TYPE.INAPP)
229229

230-
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", { oldSKU: "viejo", prorationMode: Purchases.PRORATION_MODE.DEFERRED}, Purchases.PURCHASE_TYPE.INAPP);
230+
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledWith("onemonth_freetrial", { oldSKU: "viejo", prorationMode: Purchases.PRORATION_MODE.DEFERRED}, Purchases.PURCHASE_TYPE.INAPP, null);
231231
expect(NativeModules.RNPurchases.purchaseProduct).toBeCalledTimes(3);
232232
});
233233

android/src/main/java/com/revenuecat/purchases/react/RNPurchasesModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void onError(ErrorContainer errorContainer) {
113113
public void purchaseProduct(final String productIdentifier,
114114
@Nullable final ReadableMap upgradeInfo,
115115
final String type,
116+
@Nullable final String discountTimestamp,
116117
final Promise promise) {
117118
CommonKt.purchaseProduct(
118119
getCurrentActivity(),

example/app/screens/UpsellScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ export default class UpsellScreen extends React.Component {
8484
<Button
8585
color="#f2545b"
8686
onPress={async () => {
87-
const product = this.state.offerings.current.annual.product.identifier;
87+
const aPackage = this.state.offerings.current.monthly;
8888
try {
89-
const purchaseMade = await Purchases.purchaseProduct(product);
89+
const purchaseMade = await Purchases.purchasePackage(aPackage, {oldSKU: "old", prorationMode: Purchases.PRORATION_MODE.DEFERRED}, Purchases.PURCHASE_TYPE.SUBS);
9090
checkIfPro(purchaseMade.purchaserInfo, this.props.navigation);
9191
} catch (e) {
9292
if (!e.userCancelled) {

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ var Purchases = /** @class */ (function () {
271271
*/
272272
Purchases.purchaseProduct = function (productIdentifier, upgradeInfo, type) {
273273
if (type === void 0) { type = PURCHASE_TYPE.SUBS; }
274-
return RNPurchases.purchaseProduct(productIdentifier, upgradeInfo, type).catch(function (error) {
274+
return RNPurchases.purchaseProduct(productIdentifier, upgradeInfo, type, null).catch(function (error) {
275275
error.userCancelled = error.code === "1";
276276
throw error;
277277
});

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,8 @@ export default class Purchases {
779779
return RNPurchases.purchaseProduct(
780780
productIdentifier,
781781
upgradeInfo,
782-
type
782+
type,
783+
null
783784
).catch((error: any) => {
784785
error.userCancelled = error.code === "1";
785786
throw error;

0 commit comments

Comments
 (0)