Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter In App Purchase What Should I Include in _verifyPurchase()

Hi I have been currently been using the Flutter in app payment plugin example https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/example. Within that code after payment has happened there is a function named _verifyPurchase currently that function is as below.

Future<bool> _verifyPurchase(PurchaseDetails purchaseDetails) {
  // IMPORTANT!! Always verify a purchase before delivering the product.
  // For the purpose of an example, we directly return true.
  return Future<bool>.value(true);
}

Currently it always returns true however I do not fully understand what verification process do I need to include here to verify a purchase.

What verification process do I need to include here to verify a purchase

I am currently confused as to what is actually needed within this function.

like image 424
GILO Avatar asked Jul 26 '20 09:07

GILO


People also ask

What is in-app purchases?

With some apps, you can buy additional content or services within the app. We call these "in-app purchases." Here are some examples of in-app purchases: A sword that gives you more power in a game. A key that unlocks more features of an app.


1 Answers

They mean the verification with your backend server. This way your server can check the acknowledgement state of the purchase, whether or not it was consumed etc., without doing this on the client, which is not a safe way to verify anything, because the client can be compromised - that is why documentation tells to verify purchases through your backend, doing it inside the client has no meaning. You need to send your server the token which is provided with the purchase (in your PurchaseDetails you have .verificationData.serverVerificationData)

Use it to verify purchases through your backend (assuming you have a backend) by sending the token from verification data first to your backend and then from it to Google API that is made for such checks.

You would also need to set up a service account within your Google Play dev console to allow backend to access required data. It's not very complex, but a long process and it also depends on your backend language and so on. Better check out the official documentation starting here: https://developer.android.com/google/play/developer-api#subscriptions_api_overview

like image 55
galloper Avatar answered Oct 18 '22 20:10

galloper