Android Billing - How to get subscription duration from Purchase object - android

I am using version 5 of billing library. I have a subscription with product id "MySub" that has two offers. One monthly and one yearly with offer ids "sum.monthly" and "sub.yearly".
When I purchase for example the monthly option, the purchase object I receive from the billing library only has the product id "MySub". But it's not telling me which offer the user purchased. How do I extract that information from the Purchase object?

The offer id is not stored in the "Purchase" object returned by the Google Play Billing Library.
You can keep track of the offer ID's in your own database or in app or local database and associate the Purchase object with the corresponding offer id based on the time period of the subscription.
For example;
If the sub is valid for 30 days you can assume that it's monthly offer, if it's valid for 365 days, you can assume that it's yearly offer.
You can check this with a simple if else struct.
I suggest create another sub plan or create base plan.

Related

Verify Google Subscription on backend - get base plan

Recently Google introduces base plans to subscriptions. Base plans are used to introduce different billing period (you end up with single subscription and couple of base plans for example: monthly, weekly, yearly) https://support.google.com/googleplay/android-developer/answer/12154973?hl=en
When I verify subscription on backend I would like to know which base plan user selected but I cannot find any way to get that. Previously I was getting all necessary informations from:
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptions
when Google introduced Base plans they also released purchases.subscriptionsv2:
https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2
but both only returns productId which is subscription id and no base plan id. Any idea how to get that with service account authentication?
On the other hand I can see on Google Play Console under order details productId and selected base plan, so I know subscription is configured correctly
Google added new field offerDetails with basePlanId, offerId and offerTags into lineItems (https://developer.android.com/google/play/billing/compatibility#subscriptionpurchasev2-fields). Fields not documented yet in https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2, but already come in response.

Google Play Billing Library: Determine base plan / expiry of subscription purchase

I am using the Google Play Billing Library 5 and have a subscription product with different base plans.
When processing the purchases in the PurchasesUpdatedListener or in the callback of queryPurchasesAsync, I receive a list of Purchase objects which contain inter alia the product IDs, purchase time and whether it's auto-renewing.
But how do I know which base plan was selected by the user, and when it expires?
The PurchaseHistoryRecord returned from queryPurchaseHistoryAsync also seems not to contain this info.
I know the Play Developer API returns the expiry time
with purchases.subscriptionsv2.get, but is the inconvenience of using the API directly necessary?
The conclusion I am coming to is that it is best to ignore the whole multiple base plans feature.
Create the subscriptions individually instead so you have
Silver_Plan_Monthly --> Silver_Monthly_Base --> Silver_monthly_free_trial_offer.
Then a separate subscription.
Silver_Plan_Yearly --> Silver_Yearly_Base --> Silver_yearly_free_trial_offer.
And so on for however many subscription levels you want Silver, Gold, Platinum etc.
This way when you get the users purchases you can immediately tell what sub/level/renewal period they bought by the productId which will be the subscription name (Silver_Plan_Monthly).
This is annoying in having to create all these subs but the billing library doesn't give enough info otherwise.
And you should be able to now easily upgrade/downgrade user between these levels and the billing periods.

Getting Billing details of Subscription android?

I am using InAppBilling version 3 in my app, I am able to purchase subscriptions using test account. Now my question is how do I know the billing details in my app againt one subscription plan. Suppose I have purchase one plan and it renews Daily, Is there any provision or method to know that renew is done to this product with details(like for ex. product_id, time, date, update, renewing_status...etc). I have refered to this link.
And the other thing is that do a user can subscribed to multiple subscription at a time ?
After searching quite a bit, finally I found my solution. Google don't provide subscription order number for test purchases(if you are using test account to test your application without going to production). It only provide product_id, token, purchase_time, developer_payload, autoRenewing, package_name and purchase_state as if Google don't send details to Play Billing server as it is not a real purchase. Still your can implement your own logic as it provide autoRenewing = true(if product is in renewal state) and false(if product is in non-renewal state) with purchase_state = 0(purchased) , 1(canceled) and 2(refunded). And one more thing I came to know after reading documentation of Google that, test user who has taken the subscriptions the recur on daily basis, but they will only get the same details, which they get while purchasing a test subscription plan.
It provide order Id for real purchases with other details. If your subscription is monthly and your order Id is GPA.1234-5678-9012-34567 while purchasing the plan. Then next month Google append your order Id with GPA.1234-5678-9012-34567..0(second month) , GPA.1234-5678-9012-34567..1 (third month) and so on. So you can track your renewal of purchases with order Id as described in here. Rest are same.

Android In app billing purchase history query

I am building an app that I want to use Google in app billing for. Does Google track in-app purchase history for me, so that I can query history and get data, say, by date or by item, etc. Or must my app itself store user's purchase history on my own backend? Also, if you can please provide a link so I can verify this info.
For your question answer is both YES and NO Google will take care of all purchases based on product type. If you are using Non-consumable or Subscription based products Google will keep records, in other case if you are using Consumable products Google will keep it's record till your app consumes that product.
If your app sends a purchase request Google will associate it with primary gmail account registered on android device and will not allow to purchase same product twice.
NOTE:- If You are using IAB-2 then above product type and flow will slightly different
Non-consumable ** is known as **Managed Products
*Subscription* is same as Subscription
*Consumable* is known as Unmanaged products
In case of IAB-2 google will never keep record of Unmanaged products and it is your responsibility to keep records if you want.
For more details see below link to developer guide.
Developer guide

Is possible in Android in app purchase create registered members and take fee at the end of the month

Is it possible in Android In-app purchase to create something like registered members or subscribers, to allow the users in that group to download content and to take fee at the end of the month?
As of now, not with Google Play. The Amazon in-app billing API does support this though.
It is possible with unmanaged purchase, but you will need to have server side support for this.
You will have to save the purchases in your own system, keep track of the expiry for each user, etc.
Also, you could do it with managed purchase by creating a new product for each month, but it has its limitations. E.g. you offer monthly subscriptions from the first day to the last of the month and the user buys one on the last day of the month, the he/she will pay the full monthly price for only one day. I do not recommend it.

Categories

Resources