chirag04 / react-native-in-app-utils

A react-native wrapper for handling in-app payments
MIT License
890 stars 185 forks source link

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

Open Twansparant opened 7 years ago

Twansparant commented 7 years ago

Hi there,

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

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 commented 7 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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.