How to verify purchase for android app in server side (google play in app billing v3)

前端 未结 6 485
再見小時候
再見小時候 2020-11-30 16:41

I have a simple app (needs user login with account). I provide some premium features for paid users, like more news content.

I need to record if the user has bought

6条回答
  •  孤独总比滥情好
    2020-11-30 16:49

    Complete example of using Google API Client Library for PHP:

    1. Setup your Google Project and access to Google Play for your service account as described in Marc's answer here https://stackoverflow.com/a/35138885/1046909.

    2. Install the library: https://developers.google.com/api-client-library/php/start/installation.

    3. Now you are able to verify your receipt the following way:

      $client = new \Google_Client();
      $client->setAuthConfig('/path/to/service/account/credentials.json');
      $client->addScope('https://www.googleapis.com/auth/androidpublisher');
      $service = new \Google_Service_AndroidPublisher($client);
      $purchase = $service->purchases_subscriptions->get($packageName, $productId, $token);
      

      After that $purchase is instance of Google_Service_AndroidPublisher_SubscriptionPurchase

      $purchase->getAutoRenewing();
      $purchase->getCancelReason();
      ...
      

提交回复
热议问题