Skip to main content
Question

PurchaseParams.Builder(this, aPackage) usage

  • September 21, 2023
  • 3 replies
  • 464 views

Forum|alt.badge.img+2

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:

1Purchases.getSharedInstance().purchase(
2 new PurchaseParams.Builder(this, aPackage).build(),
3 new PurchaseCallback() {
4 @Override
5 public void onCompleted(@NonNull StoreTransaction storeTransaction, @NonNull CustomerInfo customerInfo) {
6 if (customerInfo.getEntitlements().get(<my_entitlement_identifier>).isActive()) {
7 // Unlock that great "pro" content
8 }
9 }
10
11 @Override
12 public void onError(@NonNull PurchasesError purchasesError, boolean b) {
13 // No purchase
14 }
15 }
16);

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.

This post has been closed for comments

3 replies

Forum|alt.badge.img+8
  • RevenueCat Staff
  • 674 replies
  • October 3, 2023

Forum|alt.badge.img+4

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:

1const makePurchase = async () => {
2 try {
3 const purchaseResult = await Purchases.purchasePackage({
4 aPackage: "$rc_monthly",
5 });
6 if (
7 typeof purchaseResult.customerInfo.entitlements.active[
8 "my_entitlement_identifier"
9 ] !== "undefined"
10 ) {
11 // Unlock that great "pro" content
12 console.log(purchaseResult);
13 console.log(customerInfo);
14 }
15 } catch (error) {
16 console.log(error);
17 if (error.code === PURCHASES_ERROR_CODE.PURCHASE_CANCELLED_ERROR) {
18 // Purchase cancelled
19 } else {
20 // Error making purchase
21 }
22 }
23};

 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

 

 

 


Forum|alt.badge.img+4

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 :) 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings