How to Connect Google Play Real-Time Developer Notifications to Firebase Cloud Function via Pub/Sub?
Asked Answered
B

1

12

I'm in the final stages of development for my new mobile app, but can't seem to find a way to allow Google Play Real-Time Developer Notifications to communicate to a firebase cloud function via the recommended Google Pub/Sub method.

The expected payload flow should go as follows:

User Purchases Subscription via Play Store > Play Store sends R-T Dev Notification to Pub/Sub > Pub/Sub sends message across to firebase cloud function > Cloud function runs with payload.

I currently have an Apple Developer webhook set-up in a similar way, which webhooks a receipt payload to an iOS cloud function I have setup.

During the pub/sub setup phase, the Pub/Sub page asks to verify the cloud function URL, which I cannot do as I am not the true webmaster of cloud function domain, hence halting me about halfway down the 'Add real-time developer notification' docs that google supplies.

Is there a way to get the RT notification to either a Pub/Sub cloud function or a HTTPS cloud function bypassing the google Pub/Sub and going directly to the webhook or another way to complete the flow above?

The ultimate aim is to provide a way to ensure the purchase made is actually a valid purchase, and not a forged request made by someone intercepting the client > server webhook and submitting one of their own accord.

Barquisimeto answered 18/9, 2019 at 20:53 Comment(1)
Is there any way of using Google Play Real-Time Developer Notifications but in an AWS Cloud? Like if google can notify my cloud by calling a webhook or my URL that the purchase has been made?Bow
A
10

After creating the new topic you DO NOT have to create manually a Pub/Sub subscription as explained in the documentation.

To make it work with firebase you have to deploy a new cloud function like this:

exports.YOUR_FUNCTION_NAME = functions.pubsub.topic('YOUR_TOPIC_NAME').onPublish((message) => {

  // Decode the PubSub Message body.
  const messageBody = message.data ? Buffer.from(message.data, 'base64').toString() : null;

  // Print the message in the logs.
  console.log(`Hello ${messageBody || 'World'}!`);
  return null;


});

Please note that you need to replace YOUR_FUNCTION_NAME and YOUR_TOPIC_NAME.

When the deploy of this function finish, you will finally find the function in the subscription list. At this point, you can edit the params of the automatically created subscription, and you will find the url endpoint already filled with an internal url.

Here you can find an example: how to setup a PubSub triggered Cloud Function using the Firebase SDK for Cloud Functions.

Appointee answered 26/9, 2019 at 14:48 Comment(1)
Is there any way of using Google Play Real-Time Developer Notifications but in an AWS Cloud? Like if google can notify my cloud by calling a webhook or my URL that the purchase has been made?Bow

© 2022 - 2024 — McMap. All rights reserved.