How to check user already used FREE Trial In-App Subscription - android

I am creating an app in which i need to update UI based on Google Play Subscriptions
I have two cases in which i have problem
is user used Free Trial Subscription
Is user used Introductory based Subscription or not
I know it will automatic adjust when user try to payment. But I need this in to update App UI

Google doesn't provide an API for this.
First option: If you're forcing users to sign in, then you can use Firebase RTDB to save the user's subscription/trail data and then you can listen to DB changes and update the UI on data changes.
Second one: You can use a service to track this data like Revenuecat. You can check Period Type from their API. I'm currently using it and it does the job.
Other than that, there's no way to get this information from Google yet.

Currently, I don't think there is a way to get the details of free trial subscriptions as per google play API. So as per your use cases, we can make a workaround it.
We can use purchases.subscriptions.get to get the timestamp when the subscription was taken and once that information is with us we can compare the subscription taken the time and we can compare it with the current time. If that time exceeds the Trial days limit we will know that its a Introductory based Subscription.

Related

Can I used google billing API to retrieve trial period?

My app uses google's billing API to retrieve subscription options configured in google's developer console. We have some subscription options configured as free trials.
So far we've been using the IInAppBillingService.getSkuDetails() method. This reference -
https://developer.android.com/google/play/billing/billing_reference.html#getSkuDetails - shows what kind of data you can retrieve data regarding the subscription item. But sadly it does not include the trialPeriod nor billingPeriod.
I stumbled upon this google play API https://developers.google.com/android-publisher/api-ref/inappproducts that shows you can query the in-app products and get a response with more details.
Is this information somehow available using the IInAppBillingService ?
There is currently no API that returns the info if a subscription is bought directly or through free trial.
Haven't tried it myself yet, but a workaround I could think of is to have different periods for an actual subscription and a trial period. Say have an actual subscription to have a minimum of 1-month subscription, then for a free-trial, have it as 1-week. (The difference in periods kinda gives the free trial a demo-like thing into it too)
With that done, you could call Purchases.subscriptions.get (or depending on how you're getting the subscription details, so long as you get the details) to receive a Purchases.subscriptions resource.
From there, you could compare the startTimeMillis and expiryTimeMillis. If it's 7-days, it's a trial, else, an actual subscription. (similar idea as to what was mentioned in this answer.
With all that said, I would like to point out that I'm not entirely sure if this is good practice in determining free trial subscriptions.

Canceling subscription for all users and disabling auto renewal

Reading the documentation for subscriptions and related SO questions/answers i am still confused what to do when i have to stop providing the subscription services and content:
https://developer.android.com/google/play/billing/billing_subscriptions.html#cancellation
In all cases, you must continue to offer the content that your
subscribers have purchased through their subscriptions, as long any
user is able to access it.
For example i am offering some content via my server to subscribed users in my app. At one point i am unable to offer that content and i want to cancel all subscriptions?
The users theoretically wont be able to access the content any more and i certainly dont want to charge them for it any longer. The proper use case for me would be to cancel the user subscriptions and refund the remaining money for them. But i am not sure that this is acceptable according to the available information in the docs...i guess that i can do the cancellation and refunds using the google play developer API (still reading the available options) if that will cover the policy requirements somehow?
I am just finding it hard to believe that if a user for ex. rejects app updates and stays on an old app version with an old subscription i have to support him for eternity :) ?
I know what you are suffering the only way around this is communicate to your users to update. Usually this case would mean a FORCE UPDATE so when they open your app they have to update. Your backend has to have a service like that. If user doesn't update they can't use the app. Also I pretty much believe that some subscriptions are auto renewal so that's one the reasons why deleting in the play store is not possible. Also take into account that change price would generate almost the same problem. Since you can't change a price of a subscription at least the base price, the country price you can.

How to detect plan change for android's in-app purchase using GoogglePlay developer API?

thansk for reading
Context
We provide on-demand video streaming that user can purchase via monthly or yearly subscription on android, ios & web
Thus whenever purchases was made on Android, the app send our server a (purchaseToken, subscriptionID) pair, and we use this google developer API to persists the subscription info in our db
Problem
Recently, we added support for user to change their plan on Android. On Google side, the money is prorated and the new subscription is created. However, the old subscription's start and end time is still the same on the developer API.
We can't say for sure that the old subscription was cancelled and replaced with a new one because the payload (defined here) only tell you above auto-renew status. Plus the cancel reason of 1 is a blanket for anything that's not user-initiated, not just plan change.
I am making a work around, but it requires knowing a few things, like:
When you switch from a more expensive, longer plan (yearly) to a shorter one (monthly), will all the remaining money be prorated, effectively making your new subscription last longer than its normal duration?
which seems likely, based on this:
Google Play cancels the old SKUs and credits the user with the unused value of their subscription time on a pro-rated basis. Google Play applies this credit to the new subscription, and does not begin billing the user for the new subscription until after the credit is used up.
When you cancel the newer subscription, will it happen the same way as cancelling a normal subscription? (i.e, the subscription is not auto renewed, but should stay in effect till the end of its duration), or some credit will be stored with Google to be used later?
However, the old subscription's start and end time is still the same on the developer API.
This seems unexpected and could be a bug.
When you switch from a more expensive, longer plan (yearly) to a shorter one (monthly), will all the remaining money be prorated, effectively making your new subscription last longer than its normal duration?
Yes, the remaining balance of the original subscription is applied to the new subscription. The new billing period will start once that balance is used up. This is best explained in the docs here.
When you cancel the newer subscription, will it happen the same way as cancelling a normal subscription? (i.e, the subscription is not auto renewed, but should stay in effect till the end of its duration), or some credit will be stored with Google to be used later?
I believe what will happen is the subscription will not be auto renewed (as you said), but the subscription will remain active until the balance from the prior subscription is used up.

Android In-App Billing Subscription status change callbacks

I'm writing an app that will support in-app subscriptions. The subscriptions will enable my users to use a number of services and benefits outside the Android world. I know that I can use Google Play Developer API to query the status of a subscription, but due to the nature of the offered services and benefits, it is not very convenient to do that. I was wondering if there is a way to get notified about the status of the subscription when it changes. Something like a web hook for example.
I wanted to post a comment in response to yours, but apparently this was too long. In addition to that, it is also kind of an answer to your question, so I thought this might be a good thing to just post it as an answer instead. Maybe it even solves your problem.
So, regarding your comment. You don't necessarily have to do it that way. Now, I don't know your system requirements, but I'll just share mine and hope it helps you out.
Save Users and Subscriptions on your server (database tables). Have a check_at column on the Subscriptions table, besides a renew_at one. Suppose the user has a monthly subscription created on the 1st of January. On that first day, you call your server from Android after the purchase is finished, save the subscription details, then set renew_at as February 1st and check_at as February 4th, considering you set 3 days as delay for transaction failure in Google Play Developer Console. This way, the user has time from 1st February to 3rd February to change credit card details if the payment fails on the 1st. Then on the 4th you will check the Google Play API for subscription details. But don't disable premium functionality during 1st-4th February. Disable it on the 4th if the subscription was canceled. This way, premium content is not delayed nor tampered with in any way. If the subscription end date returned by the API is in the future, then it was renewed, so you should keep premium activated. Now, how do you check it monthly on the 4th you may ask. Use some kind of scheduler to schedule tasks on the database.
This way you remove the need to rely on webhooks. Although I agree, webhooks would've been more efficient and probably even easier to implement.
Let me know if you have any questions or there are some flaws in the system I described.
Take a look at Real Time Notifications using Google Cloud's PubSub service. It sends notifications of payment/subscription events like: new buy, renewal, cancellation etc. It includes the token which can be used to retrieve additional info from the API like you do now.
You can also configure this PubSub Subscription to call a custom webhook (which still needs to query the PubSub) on each message that you receive.

Playstore subscriptions - testing strategy

Scenario:
I am on the verge of completing my google playstore in-app billing implementation. I am using a monthly or yearly subscription in order to charge my consumers.
Problem: I can't seem to find a way to remove a subscription from active state, since cancellation simply stops the billing from occurring. This doesn't allow QA to thoroughly test the purchase procedure without creating an account for each test, or waiting until the subscription period ends.
Question: Have I missed or am wrong about something? If so, what is it? If not, what should be done to allow QA to do proper testing?
According to what I have understood from your question,
you can not test subscription from the test account. Google play doesn't provide subscription testing using dummy product. you have to test on the real product.
Now question arises how can I test subscription
you can check subscription by purchasing real product and check product status or purchase cancellation using the purchase status api from your server.
you can also get more information from the given link below for the step by step cancellation purchase status:
1) link1
2) link2
you can simply query every day and check your subscription is valid or not and also get it's expiration date.
I also have one other option with out pay for any charges on your real product, you can set trial period in the Google console and before trial period ends up cancel subscription from the Google play store Menu -> MyApp -> Subsciption and cancel product and check above procedure given in the links.
EDIT:
Important: In all cases, you must continue to offer the content that
your subscribers have purchased through their subscriptions, for as
long any users are able to access it. That is, you must not remove any
subscriber’s content while any user still has an active subscription
to it, even if that subscription will terminate at the end of the
current billing cycle. Removing content that a subscriber is entitled
to access will result in penalties. Please see the policies document
for more information.
more information check below links:
1)
http://developer.android.com/google/play/billing/billing_subscriptions.html#cancellation
2) https://support.google.com/googleplay/answer/2476088?hl=en
3)
https://support.google.com/googleplay/android-developer/answer/140504?hl=en
You can not done this with out waiting until the subscription process cycle completes after cancellation of subs product, the only way remaining which is Free trial version it's only the way to provide us to test for the product cancellation in which product cancel immediately after you cancel subscription trial period, it will not continue until even trial periods ends.
more information check below link:
http://developer.android.com/google/play/billing/billing_subscriptions.html#administering
And I think it is better way because in the trial period you should go
with the actual credit card payment process but you doesn't need to
pay anything for it. Google play record the transaction as $0.00 for
the subscription process. And if you cancel the subscription the you
should not pay anything for testing, but yes I am not sure free trial version
is worked before you publish the app but it is only get by efforts only.
Conclusion:
In the current api it is not possible to test subcription product like
normal products and if user has been cancel the subscription product
then you have to wait to purchase the same product until the
subscription cycle has been expired, there is no another way if the
subscription cycle is going on and you can test for the same product
again before subscription cycle ends. And if you still want to test
for the same product then you have to choose another account for
testing it or another way is Free trials, you will not be any charged
until your Free trials period expired or cancel subscription in that
period and for the testing account before publish the app you will be refunded
automatically after 14 days of purchased product according to my
knowledge.
Hope it will solve your problem.
I have a horribly clunky workaround for this problem. Here is what I do every time I want to do a test of in-app subscriptions:
Create a new in-app subscription product in the google play developer console.
Point the android app at the new subscription product you just created.
In your code to check for active subscriptions, add a line to specifically ignore the order number of the previous subscription that you tested.
Export a release build of the app and transfer it directly to your testing device.
After testing, return to step #1 to test the next time.
Don't forget to fix your change from step #2 before deploying the app!
You might want to create many subscriptions in step #1 so you don't have to continually wait hours for them to propagate. Please comment if you know of a better way!
UPDATE: Google now has test subscriptions and is making it easier to use them! https://android-developers.googleblog.com/2018/01/faster-renewals-for-test-subscriptions.html
It seems that nowadays there is better solution:
Open your app page in Google Play Store application
Click "Manage subscriptions"
Click "Cancel subscription"
Go to "Settings", "Apps" in your phone.
Find Google Play Store and clear application data.
You should now be able to re-buy subscription.
Create a mock class that mocks out the Google Play methods that you are using.

Categories

Resources