PHP code for google payment server order verification

Source: Internet
Author: User
Google has forwarded an article about google payment server order verification before verifying the PHP code. today, I have posted the code for verifying the order payment of the server (PHP version) I have developed.

Before performing server transaction verification, you need to go to the google api consystemic background https://console.developers.google.com to activate the google play developer api and obtain the request api certificate priket. p12 file;

Transaction Status API documentation: https://developers.google.com/android-publisher/api-ref/purchases/products/get

Download the official sdk package for google php, and the code is as follows:


After each successful payment, the client calls the billing callback method to obtain the transaction status: there will be purchase token and productId (that is, the custom identifier of the payment item configured in the google app background)

The request order transaction status code is as follows:

 setAssertionCredentials($cred);$service = new Google_Service_AndroidPublisher( $client );$packageName='com.xxxx.xxxx';$productId='9419';$token = 'omoaokhfkmiipfffmemjaclh.AO-J1OyFcurjPmcY4J5MFMYvW5z6jq-X9SrpZCo93etscPe0SzDItMnAY50RLWLwOEYl71HQEBXG8fREgJp-EVZTOwkG8uHuKf3UPlx0u8rwK7Qw4bRE9SI';$optps=array();$resp = $service->purchases_products->get( $packageName, $productId, $token, $optps );$resp = (array)$resp;var_dump($resp);}catch(Exception $e){echo $e->getCode(),'|',$e->getMessage();}?>


If normal, the api will be related to the status of the transaction, the corresponding field description see the official documentation: https://developers.google.com/android-publisher/api-ref/purchases/products#resource

ConsumptionState: the consumption status of the product. table 0 has not been consumed, and Table 1 has been consumed (because the same product of google has not been consumed, repeated purchases are not allowed)

DeveloperPayload: this is very important. it is custom passthrough by our developers. it is generally the unique identifier of transactions such as the order number of the system and can be used for comparison.

PurchaseState: The Purchase Status. 1 indicates the purchase, and 0 indicates the cancellation.


Note: It seems that this api has a limit of 20 million calls to the google platform per day.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.