Separate real time notification for staging and production in play console
Asked Answered
P

3

14

Situation - User completes payments for subscription, the app sends purchase token to the backend with the user id. At the same time, we have also configured webhook, which also send same purchase token to map user id to same purchase token and we will get future webhook events for that user and purchase token.

Consider we have set up staging endpoint URL for the current topic name in play console.

This is fine: When staging user completes payment, the app sends data to a staging server and real-time dev. The notification also comes on the staging server.

This is problem - But After LIVE (App published) when staging user completes payment, the app sends data to staging server BUT real-time dev. The notification goes to production server because after LIVE we have changed to production endpoint URL for the current topic name in play console.

Possible solution -

  1. We can always create dummy user in production to test payments so that all data comes to the production server.
  2. We can create one API which sits on the production server and distinguishes SKU id for stagging and production whenever real-time dev. comes. If SKU id is from production then continue otherwise hits staging server API to dump that data in stating.

Help - I need your help in knowing the best solution for this.

Pram answered 23/4, 2018 at 8:48 Comment(3)
Could you please suggest me a step to setup webhook?Pernick
I have the same question - did you get a solution in the end?Culler
Do you find solution?Tableau
H
5

I have the same problem right now. The solution I am going for is to use the androidpublisher subscriptions API. In the Real-time developer notification, you get the packageName, subscriptionId and purchaseToken you need to access the API.

The response you get from the API can contain a purchaseType: purchaseType

So you can simply check if purchaseType field is present in the API result. If it is, the purchase was made using a license testing account, and you can forward the notification to your staging environment.

Hope this helps you and anyone else. :)

Hoad answered 11/10, 2018 at 11:56 Comment(0)
O
1

If you are using purchases.subscriptionsv2.get (get subscription v2) from the androidpublisher subscriptions API, a property in the response testPurchase will exist if the purchase was a test purchase.

Android publisher api subscriptions check if test purchase

Source: https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#SubscriptionPurchaseV2

Opportina answered 6/2, 2023 at 0:29 Comment(0)
H
0

we have changed to production endpoint URL for the current topic name in play console

You can actually change the endpoint URL in the Google Pub/Sub Subscription but keep the same topic name and thus not change the topic URL in the Play Console.

Then you can create a 2nd Subscription attached to that same Topic. The 2nd Subscription can Push to a different URL (e.g. a staging server). Therefore both production and staging servers will receive a copy of every message.

You still need to find some way to filter for only those messages that are relevant, perhaps by looking for the testPurchase property or some fixed product SKUs or customer IDs that are only for use in your staging database. Really, it's this part which might be difficult and vary a lot for each use-case - getting real time notifications to both staging and production is fairly trivial in comparison.

I'd guess that for the OP (many years ago I know!) this approach is similar to their possible 2nd solution but it doesn't rely on the production system knowing about the staging system and helps keep them entirely separate.

Hardness answered 22/3, 2023 at 15:3 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.