In my android application user membership plan is upgraded using inapp subscription on monthly basis. There are 2 membership status corresponding to each user 'free' & 'premium'. If user subscribes on monthly basis, the membership status will become premium. But after 1 month the membership status goes to free.
How can we get auto subscription status from play store so that I could pass this status to the backend to upgrade the user membership status to premium.
Is there any callbacks from google play store to app or direct to the backend server to get the subscription status?
Is there any callbacks from google play store to app or direct to the backend server to get the subscription status?
No, you have to query the purchaseToken yourself using the Google Play Developer API from within your own web-server.
Upon receiving the purchaseToken on your server you should make a request to the Google Play Developer API to retrieve the expiryTimeMillis.
You should then queue a task to run again at the given expiryTimeMillis to retrieve the latest expiry date and so on until the expiryTimeMillis appears in the past indicating that the subscription has not been renewed.
If you're specifically looking for a service with webhook integration that you don't need to build yourself, I suggest checking out https://mbaasy.com. It's in beta at the moment but if you register I can get you in the beta program soon. Disclaimer: I'm the founder of mbaasy.
Related
I'm researching for developing an open source app that will get a sync feature in future.
This will be realized with Firebase Firestore. This feature should only be available to users subscribing to an abonnement via Google Play Billing.
Now, if I upload my google-services.json to my open source repo, anyone can compile the app and remove the check, whether there's an active subscription or not.
But if I don't upload my google-services.json, CircleCI can't build my project, since the file is missing.
Does anyone have experience in this matter, or some tips?
Thanks!
you should have a server for this. firebase or custom, doesn't matter, but the purchase, subscription, and renewal business rules should not be in your app providing the services based on the subscription status.
If all of the logic is in your app, without server, then you're bound to have issues with this. There's no way around that.
You should also assume that somebody will break your subscription logic (to provide free access) and the apk will be listed forever on something like apkmirror for anyone to get it.
Here's a suggested proper flow.
Server:
users need to have a login
have a list of products a user can subscribe to, with SKUs
that exist in the google play store, under your app's products
App:
app calls your server to get a list of products available for this user. you really care about getting the SKUs for this.
make request to google's billing client to get pricing for the list of SKUs
when customer purchases something using google's billing sdk, you'll get a purchase receipt object
send your purchase receipt to your server
Server:
the server will validate the purchase receipt with Google, where the server itself makes an API call to google to verify the authenticity of the receipt
if the receipt succeeds, the server returns a success code
App:
if the response from sending the receipt succeeds, then you make a new request to the billing SDK, this time to fulfill the purchase (close the transaction)
when fulfillment succeeds, call your server to notify that fulfillment is completed. send the lenght of the subscription (monthly, yearly...)
Server:
grant access to the subscription content the user just purchased
when the renewal time is up (which came from the fulfillment call), your server wakes up and calls google to renew the subscription
if renewal succeeds, user continues to have access to the subscription content
Yes, this is A LOT more work, but it is also dramatically more resilient and future proof than having a true/false flag in your app.
With that being said, if your subscriptions are $1 a year, and you expect to have no more than 10 users...then do the quick and easy way.
I have an Android App published on Google Play Store. I implemented In-App purchase in the app with one subscription.
Uses have started purchasing the subscription so, I was wondering if I can get an email notification whenever a user purchased the subscription. I am aware of the Google real-time developer notification but it requires backend API to be modified (and it's not free).
I was hoping for Google Play Console settings which would do just this. If this is not possible then I would like to know how you get notified of new purchases (code).
You can obtain this event in callback and send email to your adress programmatically.
Can any one provide complete documentation for auto renew subscription and update status on backend using android developer notification with pub/sub?
We have to do Monthly & Yearly auto renew in app purchase subscription. If we subscribe using app,then we are getting purchase token and updating on backend.I have some query for auto renew subscription.
Please check the same as below:
1.Do we need to check subscription status at the time subscription period over using cron job? If yes,do we need to pass same purchasetoken in Purchases.subscriptions: get api?
2.If we enable developer notification for real time update on server,then we are getting notification on server. It doesn't contain any purchase information or unique user id.
Please check the below documentation :
https://developer.android.com/google/play/billing/realtime_developer_notifications
Real-time developer notifications do not provide full information about the state of the subscription, such as whether the user is currently entitled to access subscription content. When you receive the token, you should always use the purchase token to query the Google Play Developer API to get the full information and update your backend with the user's current entitlement status.
-> Will we get purchase token from realtime developer notifications?
I implemented with the help of the official implementation. I hope this helps.
I'm trying to implement in-app purchases (consumable) using the Google Play Billing Library.(which is proving less straightforward that I would like...).
In order to plan the workflow I'd like to know what information is available to a backend server (or to the app, and then can be verified by the server) about an app's purchases. For example: can I get the date and time of purchase?
Yes, you definitely can get the date and time of purchase, order id, state, purchase token and so on. All information about purchase data is described here:
(Table 7) https://developer.android.com/google/play/billing/billing_reference
Concerning server verification, official doc says
Successful purchases also generate a purchase token, which is a unique identifier representing the user and the product ID for the in-app product they purchased. Your apps can store the purchase token locally or, ideally, pass it to your secure backend server where it can be used to verify the purchase and protect against fraud.
The process steps of server verification you need to implement:
https://developer.android.com/google/play/billing/billing_library_overview#Verify-purchase
Google Play In-app Billing samples for more clarity:
https://github.com/googlesamples/android-play-billing
I am currently working on an application that incorporates google in-app subscriptions. It seems like google would handle most of billing and transactions, but the questions are:
1. if user's credit card is expired while the app is trying to renew a subscription, do I need to handle this case on the device or my backend server?
2. if no, would google sent notification to the user?
3. if yes, how do I check the state of user's credit card????(hopefully i don't need to)
As per the documentation:
If a recurring payment fails (for example, because the customer’s credit card has become invalid), the subscription does not renew. The
getPurchases() method does not return failed or expired subscriptions.
Recommendation: Include business logic in your app to notify your
backend servers of subscription purchases, tokens, and any billing
errors that may occur. Your backend servers can use the server-side
API to query and update your records and follow up with customers
directly, if needed.
1.Looks like it should be your server's responsibility to check with Google on daily basis or so and disable the content if subscription is not active. If payment fails due to what ever reason, Google doesn't renew the subscription automatically again, so it's as good as saying that subscription is canceled.
2.Google does notify to user.