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.