Google in-app payments: howto to handle Google's postback JWT

余生颓废 提交于 2019-12-23 22:44:17

问题


Maybe its a stupid question but I'm not an advanced programmer. I've have successfully setup In-App payments for my app but it only works without using a postback url.

I've Google'd around many hours trying to tackle this myself without success. Hopefully anybody could help me out. I've included the script handling the post data which does obviously something wrong.. This is what Google says:

Your server must send a 200 OK response for each HTTP POST message that Google sends to your postback URL. To send this response, your server must:

Decode the JWT that's specified in the jwt parameter of the POST message. Check to make sure that the order is OK. Get the value of the JWT's "orderId" field. Send a 200 OK response that has only one thing in the body: the "orderId" value you got in step 3.

This is what I wrote but as far as I can see there is no way to test it (how can I simulate a post from Google?).

require_once 'include/jwt.php'; // including luciferous jwt library 

$encoded_jwt = $_POST['jwt']; 
$decoded_jwt = JWT::decode($encoded_jwt, "fdNAbAdfkCDakJQBdViErg"); 
$decoded_jwt_array = (array) $decoded_jwt; 
$orderId = $decoded_jwt_array['response']['orderId']; 

header("HTTP/1.0 200 OK"); 
echo $orderId; 

Any help would be much appreciated. Thanks Tim


回答1:


I had this same problem a year later and solved it with the following code:

require_once 'include/jwt.php'; // including luciferous jwt library 

$encoded_jwt = $_POST['jwt']; 
$decodedJWT = JWT::decode($jwt, $sellerSecret);

// get orderId
$orderId = $decodedJWT->response->orderId;

header("HTTP/1.0 200 OK"); 
echo $orderId; 

Google Wallet's In App Purchase documentation is relatively new, and lacking on the callback side. This code works both sandbox and production side, just make sure you use your own seller secret.




回答2:


Set Sandbox Postback URL in your Google Wallet setting to a test page, then log the requests to that page. You will see a JWT. Use it for test.



来源:https://stackoverflow.com/questions/9399221/google-in-app-payments-howto-to-handle-googles-postback-jwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!