Question

Completing a purchase results

  • 30 October 2023
  • 3 replies
  • 93 views

Badge +5

I am using react native library/sdk on Android to complete a purchase and want to get clarification on how to know the purchase completed successfully. Using this example, i call 

await Purchases.purchasePackage(package)

but this evaluates to false:

typeof customerInfo.entitlements.active.my_entitlement_identifier !== "undefined"

and it is considered not a successful purchase even though in the OS it said purchase was done ok.

seems like my_entitlement_identifier is undefined.

Any idea why this would happen?

The resulting customerInfo has activeSubscriptions populated to it is telling me it was a success. What is the best way to know it was done successfully? Just compare the product id of the purchase with the one inside activeSubscriptions?

productIdentifier coming from the promise is just the name of the subscription and does not include the base so that was not enough to tell..


3 replies

Badge +5

also an Issue I am noticing is that nothing really happens (in the app or backend webhooks) unless the purchase is clean and the user comes back to the app. the Android OS has a few extra prompts that happen once the purchase is complete. What if the user closes the app in-between success payment and before going back to the app? It seems that there could be a state when the purchase is done but the application will not know about it..

Userlevel 3
Badge +8

Hi,

Happy to help here. We have some example code of how to verify a purchase here: https://www.revenuecat.com/docs/making-purchases

 

In the case of an app state missing a purchase, you can call getCustomerInfo frequently (like when the app comes back to the foreground) throughout the app’s lifecycle. We cache this object, so it won’t make a lot of network calls.

Badge +5

Thank you for that example. I looked at the Making Purchases document but it is still not clear how to check that the package being purchased now has succeeded. my_entitlement_identifier in the available packages is in the format of subscription:basePlan for Android. but the productIdentifier coming out of purchasePackage() is just subscription without the :basePlan. I want to avoid concatenating names in client code.


As for calling getCustomerInfo somewhere in the app to make sure entitlements are there is ok but but that still does not let some code that runs after purchase to be reached. Also will back-end know about this or only have to setup webhooks? Reason for this question is that once purchase completes successfully I would like to let back-end know as well as set things up in the app to open up paid content. 

I think your suggestions requires some extensive code everywhere getCustomerInfo() is called to check and set the extra paid content in the app again and again.

Am I missing anything?

 

Reply