I am building an Android App, using Firebase as Backend. Firebase will be used for authentication, storage, some data in firebase database, and also using cloud functions.
There are subsriptions in my app with Google Play Billing Library v5.
After the subscription is purchased and acknowledged, I'd like to do some server side verification, where my problems begin. I have created cloud function - thank you guys - that listens to pub/sub topic and to verify the subscription I call the google api - Method: purchases.subscriptionsv2.get . After the successful response, I'd like to write this data to my database. Response I get is ok in the form of JSON object like here
This is the function:
exports.insertFromPubSubTopic = functions.pubsub.topic('mytopic').onPublish(async(message, context) => {
if (message.json.subscriptionNotification) {
console.log("ok - we have message.json.subscriptionNotification")
try {
await authClient.authorize();
const subscription = await playDeveloperApiClient.purchases.subscriptionsv2.get({
packageName: data.packageName,
token: data.subscriptionNotification.purchaseToken
});
if (subscription.status === 200) {
// Subscription response is successful.
console.log("subscription.status===200")
var message = {
'data': data
}
return firestore.collection('billing-verified').add(message)
}
} catch (error) {
// Logging error for debugging
console.log(error)
}
return {
status: 500,
message: "Failed to verify subscription, Try again!"
}
} else {
console.log('Test event... logging test');
//return admin.firestore().collection('mp-billing-messages-error').add(data)
return firestore.collection('mp-billing-messages-error').add(data)
}
})
My question is: How do I get user's data from successfully returned subscription object, so that I can store in firestore database something like - this purchase was made by this user.
I know Firebase and GooglePlayBilling are not related and have different purposes and functionalities. But let's say I have anonymous user who did not login in my app. So I don't know anything about her and cannot identify her in firebase so far. And then she gets and buys the subscription. Does anyone have any suggestions of how do I get the data about this user from verified purchased object?? Any suggestion would be helpful.