'How to get Google Play Subscription notifications in cloud functions
I am trying to get the response of the req.body of my notifications from Google Play Services in firebase cloud functions.
The notifications come through a webhook on subscription or cancellation. Everything seems to be reporting fine. I am getting something wrong with the response data? Because trying to get some field values logs undefined:
console.log(req.body.kind) // logs undefined
console.log(req.body.autoRenewing) // logs undefined
Below is supposed to be the req.body:
{
"kind": string,
"startTimeMillis": string,
"expiryTimeMillis": string,
"autoResumeTimeMillis": string,
"autoRenewing": boolean,
"priceCurrencyCode": string,
"priceAmountMicros": string,
"introductoryPriceInfo": {
object (IntroductoryPriceInfo)
},
"countryCode": string,
"developerPayload": string,
"paymentState": integer,
"cancelReason": integer,
"userCancellationTimeMillis": string,
"cancelSurveyResult": {
object (SubscriptionCancelSurveyResult)
},
"orderId": string,
"linkedPurchaseToken": string,
"purchaseType": integer,
"priceChange": {
object (SubscriptionPriceChange)
},
"profileName": string,
"emailAddress": string,
"givenName": string,
"familyName": string,
"profileId": string,
"acknowledgementState": integer,
"externalAccountId": string,
"promotionType": integer,
"promotionCode": string,
"obfuscatedExternalAccountId": string,
"obfuscatedExternalProfileId": string
}
My webhook
export const googlePlayWebhook = functions.https.onRequest((req, res) => {
const data = req.body;
console.log('start response body google');
console.log(data.autoRenewing);
..
What am I missing?
Solution 1:[1]
It should be const data = req.data;
instead of const data = req.body;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bernardo Ruz |