Google Wallet API and PHP, Handling Postbacks

2019-06-14 13:25发布

问题:

I'm trying to handle postbacks with Google Wallet but I'm unsure as to the best way to detect the type of postback.

For example, how would I differentiate a Subscription Cancellation vs a Subscription Sale vs a One Time Purchase?

I've read the Documentation: https://developers.google.com/wallet/digital/docs/postback

It's a little unclear as to the best method, as you only provide a single postback URL for everything.

if($decoded_jwt->typ === "google/payments/inapp/subscription/v1/canceled") {
   //Logic to handle cancel
}

Would this work in production? What would I use if it weren't a cancellation?

Thanks for any input!

回答1:

  • A single purchase typ : google/payments/inapp/item/v1/postback/buy
  • A subscription purchase typ : google/payments/inapp/subscription/v1/postback/buy
  • A subscription cancellation typ: google/payments/inapp/subscription/v1/canceled

I'm going through some of my old notes, and remember that the docs for subscription postback seem to have an error - which is probably why you asked :)

I ran into exceptions back then and after debugging, the typ for the subscription postback is actually what I have above (re: the docs show the postback typ for single item).

Hth....


Update

When the cancellation postback is sent, do I get the sellerdata in the JWT?

Nope. You'll see a sample cancellation postback JWT in the docs

How would I know which account to deactivate in the event of a cancellation? Or should I store the orderID?

You will get the original orderId in the cancellation postback. So yes, you'll need to store it.