question

plugmind avatar image
plugmind asked

End of current subscription period

Hi, I need to display in my app a date when current subscription period ends. Is it possible? AFAIK Receipt Verification Service provides that information only if subscription has expired or is cancelled. I wish I knew endDate when a subscription is still active. If this is not possible then maybe I could calculate it myselft for any subscription period. Any hints would be usefule. Message was edited by: plugmind
iap
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bipin@Amazon avatar image
Bipin@Amazon answered
Hi plugmind, Below is the rough code: for (Receipt receipt : purchaseUpdatesResponse.getReceipts()) { SubscriptionPeriod subscriptionPeriod = receipt.getSubscriptionPeriod(); Date startDate = subscriptionPeriod.getStartDate(); Date endDate = subscriptionPeriod.getEndDate(); } Now if there is a subscription with an existing end date, then the subscription is not active. If the application maintain the total subscription period for the particular SKU End Date = startdate + subscription period Time left = End Date - current Date Hope this is useful, I hope you can use the API's in best way.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

plugmind avatar image
plugmind answered
This is useful when day of month in start date is not close to end of month. Let's take some examples on month subscription: Start date: 2013-05-01 End date: 2013-05-31 This one is simple Start date: 2013-05-21 End date: 2013-06-20 This one is simple, too. Start date: 2013-05-31 End date: ? Start date: 2013-01-31 End date: ? I want to show end date to user. It must be accurate. Otherwise they will get confused.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bipin@Amazon avatar image
Bipin@Amazon answered
Hi Plugmind, you can go through the below link: http://developer.android.com/reference/java/util/Calendar.html this will help you to Calculate the difference Example : Calendar ENDDATE = Calendar.getInstance(); . . long diff = ENDDATE.getTimeInMillis() - STARTDATE.getTimeInMillis();
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

plugmind avatar image
plugmind answered
I think you misunderstood. Let's take an example. Let's imagine it is 2013-02-28 today. User purchased monthly subscription on 2013-02-28. Can you tell me when is the last day of current subscription period?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Plugmind, I think you should use Date utility of java utility package. public static Date addDays(Date date, int days) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, days); //minus number would decrement the days return cal.getTime(); } You could call this method like this, String sourceDate = "2013-02-28"; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date myDate = null; myDate = format.parse(sourceDate); myDate = addDays(myDate, 30); System.out.println("myDate.toString() = " + myDate.toString()); You should be able to consider the current time also. Then you need to use proper time format string along with "yyyy-MM-dd" while creating SimpleDateFormat instance. Please go through http://developer.android.com/reference/java/util/Date.html Hope this helps.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

plugmind avatar image
plugmind answered
I do not agree. Why are you assuming that monthly subscriptions can be referred as 30 days subscription? I wouldn't assume that. Where in IAP documentation does Amazon tell you that each subscription period is 30 days long?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

plugmind avatar image
plugmind answered
Edit: Where in IAP documentation does Amazon tell you that each monthly subscription period is 30 days long?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Plugmind, According to documentation, periods available for your Subscription Weekly: Every week on the same day from date of purchase Bi-Weekly: Every two weeks on the same day from date of purchase Monthly: Every month on the same day from date of purchase Bi-Monthly: Every two months on the same day from date of purchase Quarterly: Every three months on the same day from date of purchase Semi-Annually: Every six months on the same day from date of purchase Annually: Every twelve months on the same day from date of purchase For a monthly subscription, the validity would be till same day of next month. This simplifies the logic. So if user purchases monthly subscription on 2013-02-28, the last day of current subscription period should be 2013-03-28. Then you could show the end date as the same day of next month from the date of purchase to the user in your app. Since your app is aware of the periods of the subscription IAP items you have defined in distribution portal, you could calculate the validity duration on your own by this logic.. You are right that it's never assumed that monthly subscription is only valid for 30 days. Sorry for misunderstanding your query.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

plugmind avatar image
plugmind answered
Yeah.... and what about following cases: Start date: 2013-05-31 End date: ? Start date: 2013-01-31 End date: ?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi again, I understood your concern :). I have forwarded your query to concern team. I will post here once I get update. Thanks for baring with us.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.