Guy
Guy

Reputation: 876

Google Wallet API and PHP, Handling Postbacks

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!

Upvotes: 0

Views: 323

Answers (1)

EdSF
EdSF

Reputation: 12351

  • 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.

Upvotes: 1

Related Questions