I made a firebase function and defined a pub/sub trigger:
google_play_purchase_handler.py
:
@pubsub_fn.on_message_published(topic=GOOGLE_PLAY_PUBSUB_TOPIC, region=REGION)
async def handle_server_event(self, event: pubsub_fn.CloudEvent[pubsub_fn.MessagePublishedData]):
try:
event = json.loads(event.data.message.decode("utf-8"))
except json.JSONDecodeError as e:
logging.error(f"Could not parse Google Play billing event: {e}")
return
purchase_token = event.get("subscriptionNotification", {}).get("purchaseToken") or \
event.get("oneTimeProductNotification", {}).get("purchaseToken")
product_id = event.get("subscriptionNotification", {}).get("subscriptionId") or \
event.get("oneTimeProductNotification", {}).get("sku")
product_data = product_data_map.get(product_id)
if not product_data:
return
if product_data["type"] == "SUBSCRIPTION":
await self.handle_subscription(None, product_data, purchase_token)
elif product_data["type"] == "NON_SUBSCRIPTION":
await self.handle_non_subscription(None, product_data, purchase_token)
.....
In main.py:
from google_play_purchase_handler import GooglePlayPurchaseHandler
handle_google_server_event = GooglePlayPurchaseHandler.handle_server_event
i ran firebase deploy
and it was successful.
However when I checked in the Firebase console, it says the trigger is unknown:
I created the pub/sub topic on google cloud, set the proper permissions to the topic and added it in Google Play(at monetization setup option).