I have set up my app to include purchasing a subscription as detailed here. I have implemented the appropriate code to validate the POST sent by Google to my back-end server using an approach similar to the one discussed here.
Sending a test message as discussed in the first link from the Google Console results in my back-end server getting the push notification, however I notice that the body of the POST is empty.
Implementing the code to purchase a subscription in my app using version 4.0.0 of the billing API results in a successful result locally on the device from Google Play (i.e. I get a onPurchasesUpdated()
callback in my app with the appropriate values for what the user just purchased), and also results in a push notification as a POST sent from Google to my back-end, but this POST also has an empty body. I do get the "Bearer" header with the proper encoded block, just nothing in the body.
From the docs here, I am supposed to have a body in the POST I receive on the back-end that looks something like:
{
"message": {
"attributes": {
"key": "value"
},
"data": "eyAidmVyc2lvbiI6IHN0cmluZywgInBhY2thZ2VOYW1lIjogc3RyaW5nLCAiZXZlbnRUaW1lTWlsbGlzIjogbG9uZywgIm9uZVRpbWVQcm9kdWN0Tm90aWZpY2F0aW9uIjogT25lVGltZVByb2R1Y3ROb3RpZmljYXRpb24sICJzdWJzY3JpcHRpb25Ob3RpZmljYXRpb24iOiBTdWJzY3JpcHRpb25Ob3RpZmljYXRpb24sICJ0ZXN0Tm90aWZpY2F0aW9uIjogVGVzdE5vdGlmaWNhdGlvbiB9",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
and the data element should be an encoded string that contains info about the purchase event. However as I mentioned, the body of the POST I receive is empty. Why?
For those reading this post, it turned out there is a wrinkle due to my hosting the back-end on a Wix based web server. They intercept the POST and snag the body of it before passing the request along to my back-end javascript. I then have to call a function which is implemented as a promise (back-end coding on the Wix platform is essentially executed on a Node.js server), which I have to retrieve using a Wix specific approach that resolves a promise. Once I did that like this:
const wixBodyResult = await request.body.json();
Then I was able to parse wixBodyResult
appropriately and decode the data block appropriately.