Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if in-app purchase has been made on start #88

Open
2 of 3 tasks
Twansparant opened this issue May 9, 2017 · 3 comments
Open
2 of 3 tasks

Check if in-app purchase has been made on start #88

Twansparant opened this issue May 9, 2017 · 3 comments

Comments

@Twansparant
Copy link

Twansparant commented May 9, 2017

Hi there,

I'm a bit lost on how to achieve the following workflow:

  • When opening my app, check if the currently logged in user (in App Store) has already purchased my in-app purchase by either checking a local storage item and if not present, checking existing receiptData using the InAppUtils.receiptData function.

  • Add Get Full App button for purchasing in-app premium content using the InAppUtils.loadProducts & InAppUtils.purchaseProduct functions.

  • Add Restore Purchase button for manually restoring previous in-app purchase using the InAppUtils.restorePurchases function.

I'm confused what the receiptData actually contains? Does it contain ALL receipts from ALL the apps from the logged-in user? Or just the receipts from my app?

If I would just use this as a check for the in-app purchase, it will always enable the premium content:

InAppUtils.receiptData((error, receiptData)=> {
  if(error) {
    AlertIOS.alert('itunes Error', 'Receipt not found.');
  } else {
    // enable premium content
  }
});

With the InAppUtils.restorePurchases function you CAN check if the current purchases contain your in-app purchase, but that requires logging in to your AppStore account everytime/most of the time, so not ideal for step 1 of my workflow.

So my question is, how should I validate the receiptData? I don't have a server for my app.
I found this module for validating receipts, but I can't get it working yet with rn-nodify.

Any help is appreciated.
Thanks!

@anshul-kai
Copy link

receiptData contains information for your purchase from what I understand. You'd want to verify the information contained in receiptData before enabling premium content.

Receipt validations are ideally performed on a server. This allows you to protect your API keys that something like in-app-purchase would require. Any on-device validation would require you to embed your API keys in your app which is insecure.

I'd highly encourage you to look into a node.js server. It isn't hard to setup and you can get by with a small free AWS EC2 instance running a daily job to check all your receipts.

rn-nodify looks interesting but now sure how compatible it is with something as complex as in-app-purchase.

Hope this helps.

@franvera
Copy link

franvera commented Oct 5, 2017

@Twansparant afaik, there is no way of knowing if the user is logged is to the App store. The best option and what I'm doing atm is to verify if the receipt exists before requesting.

You can see my pull request for that: #126

You then check if the receipts exists first, if not: Tell the user that you need to verify the existence of the purchase. Proceed to verify the receipt. If receipt is found, grant access and continue.
If receiptData fails, you can then ask the user to purchase/subscribe or restore purchases to continue

@superandrew213
Copy link
Contributor

@Twansparant you could easily setup an AWS Lambda + API GateWay endpoint that validates the purchases and subscriptions.

You would just call InAppUtils.receiptData and then call your validation endpoint with receipt data. In your lambda function you can use in-app-purchase to validate the receipts and tell your app if they are valid, expired, canceled, etc.

This way the user won't get prompted to login all the time if you use InAppUtils.restorePurchases. You also don't need to manage a server and it will be cheaper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants