Skip to main content

Hello, I just started adding a subscription to an android app using java for the first time.

Following the getting started guide, I got to the “Making a purchase” section. I want to use the code example from this section in my app but there is one parameter I’m not sure where is coming from.

This is the code:

Purchases.getSharedInstance().purchase(
new PurchaseParams.Builder(this, aPackage).build(),
new PurchaseCallback() {
@Override
public void onCompleted(@NonNull StoreTransaction storeTransaction, @NonNull CustomerInfo customerInfo) {
if (customerInfo.getEntitlements().get(<my_entitlement_identifier>).isActive()) {
// Unlock that great "pro" content
}
}

@Override
public void onError(@NonNull PurchasesError purchasesError, boolean b) {
// No purchase
}
}
);

The missing parameter is aPackage in the second line. What should I put there?

Additional info: The app has only one product which is a subscription, it is connected to an entitlement, and there are no offerings.

Thanks.

Hi, you can just pass your product to it: 

https://sdk.revenuecat.com/android/7.0.0/purchases/com.revenuecat.purchases/-purchase-params/-builder/index.html

https://github.dev/RevenueCat/purchases-android/blob/93f0d4f7371d755f2bf2537e45240c054e165da8/CHANGELOG.md#L396-L398


Hey everyone, 

 

I’m in test mode, and I’m trying to just test if a purchase will work. 

I’m stuck with the error “Error: Must provide aPackage parameter”. 

I’m using capacitor, using iOS simulator. Here’s the code I use to test a purchase:

const makePurchase = async () => {
try {
const purchaseResult = await Purchases.purchasePackage({
aPackage: "$rc_monthly",
});
if (
typeof purchaseResult.customerInfo.entitlements.activen
"my_entitlement_identifier"
] !== "undefined"
) {
// Unlock that great "pro" content
console.log(purchaseResult);
console.log(customerInfo);
}
} catch (error) {
console.log(error);
if (error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR) {
// Purchase cancelled
} else {
// Error making purchase
}
}
};

 I suppose the value I pass to aPackage is not right, but what should you pass? An object? I can’t find in the documentation. 

 

Thanks in advance

 

 

 


Answering my own question : You need to pass the actual object you retrieve from offerings.current.availablePackages. You can can grab the packages like explained here: 

https://www.revenuecat.com/docs/getting-started/displaying-products

 

Hope that will help someone :) 

 


Reply