Get active subscriptions In-app Billing Android











up vote
4
down vote

favorite
2












I have used the In-app billing library for adding subscriptions in my app. Everything is working properly but I am unable to find how do I get a Users current active subscription?



As per the docs, the method queryPurchaseHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. Due to this, I am unable to know whether a current subscription is active or not.



According to this post, if we cancel the subscription, it will still be considered active for that day. But I am getting the subscriptions in the response which were canceled before 15 days.



Any help will be appreciated. Thanks in advance.










share|improve this question






















  • Most of the applications stores the subscription transaction in their own DB as well, do you maintain any database in your application ?
    – Akshay Paliwal
    Nov 12 at 12:33






  • 1




    I have not yet implemented subscriptions, but I am quite sure that queryPurchases() returns the currently valid purchases. Do you have problems with that query?
    – gicci
    Nov 13 at 21:39










  • Who got the bounty?
    – Obsthändler
    Nov 15 at 15:34

















up vote
4
down vote

favorite
2












I have used the In-app billing library for adding subscriptions in my app. Everything is working properly but I am unable to find how do I get a Users current active subscription?



As per the docs, the method queryPurchaseHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. Due to this, I am unable to know whether a current subscription is active or not.



According to this post, if we cancel the subscription, it will still be considered active for that day. But I am getting the subscriptions in the response which were canceled before 15 days.



Any help will be appreciated. Thanks in advance.










share|improve this question






















  • Most of the applications stores the subscription transaction in their own DB as well, do you maintain any database in your application ?
    – Akshay Paliwal
    Nov 12 at 12:33






  • 1




    I have not yet implemented subscriptions, but I am quite sure that queryPurchases() returns the currently valid purchases. Do you have problems with that query?
    – gicci
    Nov 13 at 21:39










  • Who got the bounty?
    – Obsthändler
    Nov 15 at 15:34















up vote
4
down vote

favorite
2









up vote
4
down vote

favorite
2






2





I have used the In-app billing library for adding subscriptions in my app. Everything is working properly but I am unable to find how do I get a Users current active subscription?



As per the docs, the method queryPurchaseHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. Due to this, I am unable to know whether a current subscription is active or not.



According to this post, if we cancel the subscription, it will still be considered active for that day. But I am getting the subscriptions in the response which were canceled before 15 days.



Any help will be appreciated. Thanks in advance.










share|improve this question













I have used the In-app billing library for adding subscriptions in my app. Everything is working properly but I am unable to find how do I get a Users current active subscription?



As per the docs, the method queryPurchaseHistoryAsync returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed. Due to this, I am unable to know whether a current subscription is active or not.



According to this post, if we cancel the subscription, it will still be considered active for that day. But I am getting the subscriptions in the response which were canceled before 15 days.



Any help will be appreciated. Thanks in advance.







android google-play in-app-billing in-app-subscription play-billing-library






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 4 at 10:24









Mehul Kanzariya

458728




458728












  • Most of the applications stores the subscription transaction in their own DB as well, do you maintain any database in your application ?
    – Akshay Paliwal
    Nov 12 at 12:33






  • 1




    I have not yet implemented subscriptions, but I am quite sure that queryPurchases() returns the currently valid purchases. Do you have problems with that query?
    – gicci
    Nov 13 at 21:39










  • Who got the bounty?
    – Obsthändler
    Nov 15 at 15:34




















  • Most of the applications stores the subscription transaction in their own DB as well, do you maintain any database in your application ?
    – Akshay Paliwal
    Nov 12 at 12:33






  • 1




    I have not yet implemented subscriptions, but I am quite sure that queryPurchases() returns the currently valid purchases. Do you have problems with that query?
    – gicci
    Nov 13 at 21:39










  • Who got the bounty?
    – Obsthändler
    Nov 15 at 15:34


















Most of the applications stores the subscription transaction in their own DB as well, do you maintain any database in your application ?
– Akshay Paliwal
Nov 12 at 12:33




Most of the applications stores the subscription transaction in their own DB as well, do you maintain any database in your application ?
– Akshay Paliwal
Nov 12 at 12:33




1




1




I have not yet implemented subscriptions, but I am quite sure that queryPurchases() returns the currently valid purchases. Do you have problems with that query?
– gicci
Nov 13 at 21:39




I have not yet implemented subscriptions, but I am quite sure that queryPurchases() returns the currently valid purchases. Do you have problems with that query?
– gicci
Nov 13 at 21:39












Who got the bounty?
– Obsthändler
Nov 15 at 15:34






Who got the bounty?
– Obsthändler
Nov 15 at 15:34














2 Answers
2






active

oldest

votes

















up vote
2
down vote













To query users subscription i use this method:



public void querySubscriptions() {
Runnable queryToExecute = () -> {
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

if (mBillingClient == null ||
purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
return;
}
mPurchases.clear();
onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
};

executeServiceRequest(queryToExecute);
}


If you need more details, ask.






share|improve this answer





















  • Does this method return only active subscriptions or does it also return previously purchased subscription?
    – Mehul Kanzariya
    Nov 15 at 5:48










  • It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
    – Obsthändler
    Nov 15 at 9:05


















up vote
0
down vote













A user can have multiple subscriptions active at any moment. You can check whether the subscription is active or not using isAutoRenewing method.Here is the docs for that method




Indicates whether the subscription renews automatically. If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription. The user has access to subscription content until the next billing date and will lose access at that time unless they re-enable automatic renewal (or manually renew, as described in Manual Renewal). If you offer a grace period, this value remains set to true for all subscriptions, as long as the grace period has not lapsed. The next billing date is extended dynamically every day until the end of the grace period or until the user fixes their payment method.







share|improve this answer





















  • How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
    – Mehul Kanzariya
    Nov 9 at 9:10










  • Dude, this is not correct. Read the text from the doc you posted.
    – Obsthändler
    Nov 14 at 13:08











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139793%2fget-active-subscriptions-in-app-billing-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













To query users subscription i use this method:



public void querySubscriptions() {
Runnable queryToExecute = () -> {
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

if (mBillingClient == null ||
purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
return;
}
mPurchases.clear();
onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
};

executeServiceRequest(queryToExecute);
}


If you need more details, ask.






share|improve this answer





















  • Does this method return only active subscriptions or does it also return previously purchased subscription?
    – Mehul Kanzariya
    Nov 15 at 5:48










  • It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
    – Obsthändler
    Nov 15 at 9:05















up vote
2
down vote













To query users subscription i use this method:



public void querySubscriptions() {
Runnable queryToExecute = () -> {
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

if (mBillingClient == null ||
purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
return;
}
mPurchases.clear();
onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
};

executeServiceRequest(queryToExecute);
}


If you need more details, ask.






share|improve this answer





















  • Does this method return only active subscriptions or does it also return previously purchased subscription?
    – Mehul Kanzariya
    Nov 15 at 5:48










  • It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
    – Obsthändler
    Nov 15 at 9:05













up vote
2
down vote










up vote
2
down vote









To query users subscription i use this method:



public void querySubscriptions() {
Runnable queryToExecute = () -> {
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

if (mBillingClient == null ||
purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
return;
}
mPurchases.clear();
onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
};

executeServiceRequest(queryToExecute);
}


If you need more details, ask.






share|improve this answer












To query users subscription i use this method:



public void querySubscriptions() {
Runnable queryToExecute = () -> {
Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(BillingClient.SkuType.SUBS);

if (mBillingClient == null ||
purchasesResult.getResponseCode() != BillingClient.BillingResponse.OK) {
return;
}
mPurchases.clear();
onPurchasesUpdated(BillingClient.BillingResponse.OK, purchasesResult.getPurchasesList());
};

executeServiceRequest(queryToExecute);
}


If you need more details, ask.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 at 12:53









Obsthändler

10311




10311












  • Does this method return only active subscriptions or does it also return previously purchased subscription?
    – Mehul Kanzariya
    Nov 15 at 5:48










  • It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
    – Obsthändler
    Nov 15 at 9:05


















  • Does this method return only active subscriptions or does it also return previously purchased subscription?
    – Mehul Kanzariya
    Nov 15 at 5:48










  • It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
    – Obsthändler
    Nov 15 at 9:05
















Does this method return only active subscriptions or does it also return previously purchased subscription?
– Mehul Kanzariya
Nov 15 at 5:48




Does this method return only active subscriptions or does it also return previously purchased subscription?
– Mehul Kanzariya
Nov 15 at 5:48












It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
– Obsthändler
Nov 15 at 9:05




It will return only active subscriptions. You can test it, here is a link on how to test subscriptions: developer.android.com/google/play/billing/…
– Obsthändler
Nov 15 at 9:05












up vote
0
down vote













A user can have multiple subscriptions active at any moment. You can check whether the subscription is active or not using isAutoRenewing method.Here is the docs for that method




Indicates whether the subscription renews automatically. If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription. The user has access to subscription content until the next billing date and will lose access at that time unless they re-enable automatic renewal (or manually renew, as described in Manual Renewal). If you offer a grace period, this value remains set to true for all subscriptions, as long as the grace period has not lapsed. The next billing date is extended dynamically every day until the end of the grace period or until the user fixes their payment method.







share|improve this answer





















  • How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
    – Mehul Kanzariya
    Nov 9 at 9:10










  • Dude, this is not correct. Read the text from the doc you posted.
    – Obsthändler
    Nov 14 at 13:08















up vote
0
down vote













A user can have multiple subscriptions active at any moment. You can check whether the subscription is active or not using isAutoRenewing method.Here is the docs for that method




Indicates whether the subscription renews automatically. If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription. The user has access to subscription content until the next billing date and will lose access at that time unless they re-enable automatic renewal (or manually renew, as described in Manual Renewal). If you offer a grace period, this value remains set to true for all subscriptions, as long as the grace period has not lapsed. The next billing date is extended dynamically every day until the end of the grace period or until the user fixes their payment method.







share|improve this answer





















  • How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
    – Mehul Kanzariya
    Nov 9 at 9:10










  • Dude, this is not correct. Read the text from the doc you posted.
    – Obsthändler
    Nov 14 at 13:08













up vote
0
down vote










up vote
0
down vote









A user can have multiple subscriptions active at any moment. You can check whether the subscription is active or not using isAutoRenewing method.Here is the docs for that method




Indicates whether the subscription renews automatically. If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription. The user has access to subscription content until the next billing date and will lose access at that time unless they re-enable automatic renewal (or manually renew, as described in Manual Renewal). If you offer a grace period, this value remains set to true for all subscriptions, as long as the grace period has not lapsed. The next billing date is extended dynamically every day until the end of the grace period or until the user fixes their payment method.







share|improve this answer












A user can have multiple subscriptions active at any moment. You can check whether the subscription is active or not using isAutoRenewing method.Here is the docs for that method




Indicates whether the subscription renews automatically. If true, the subscription is active, and will automatically renew on the next billing date. If false, indicates that the user has canceled the subscription. The user has access to subscription content until the next billing date and will lose access at that time unless they re-enable automatic renewal (or manually renew, as described in Manual Renewal). If you offer a grace period, this value remains set to true for all subscriptions, as long as the grace period has not lapsed. The next billing date is extended dynamically every day until the end of the grace period or until the user fixes their payment method.








share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 7:02









Farmaan Elahi

814814




814814












  • How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
    – Mehul Kanzariya
    Nov 9 at 9:10










  • Dude, this is not correct. Read the text from the doc you posted.
    – Obsthändler
    Nov 14 at 13:08


















  • How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
    – Mehul Kanzariya
    Nov 9 at 9:10










  • Dude, this is not correct. Read the text from the doc you posted.
    – Obsthändler
    Nov 14 at 13:08
















How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
– Mehul Kanzariya
Nov 9 at 9:10




How do I identify the case where the auto-renewal is set to false but still 10 days are left for the subscription? How can I allow user to access premium features until the subscription is expired?
– Mehul Kanzariya
Nov 9 at 9:10












Dude, this is not correct. Read the text from the doc you posted.
– Obsthändler
Nov 14 at 13:08




Dude, this is not correct. Read the text from the doc you posted.
– Obsthändler
Nov 14 at 13:08


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139793%2fget-active-subscriptions-in-app-billing-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()