#Hemant - subscription end date
1 messages · Page 1 of 1 (latest)
Putting your further info here:
But it sets the subscription end date as
Jan 24, 54591
But it sets the subscription end date as
Jan 24, 54591
then i tried some work around like this :LocalDateTime currentDateTime = LocalDateTime.now(); LocalDateTime advanceDateTime = LocalDateTime.now().plusMonths(6); ZonedDateTime advanceZonedDateTime = advanceDateTime.atZone(ZoneId.of("Australia/Sydney")); ZonedDateTime currentZonedDateTime = currentDateTime.atZone(ZoneId.of("Australia/Sydney")); Long advanceTimeInMillis = advanceZonedDateTime.toInstant().toEpochMilli(); Long currentTimeInMillis = currentZonedDateTime.toInstant().toEpochMilli(); Long diffTimeInMillis = advanceTimeInMillis - currentTimeInMillis; Subscription subscription = Subscription.retrieve(session.getSubscription()); subscription.getStartDate();// subscription.setEndedAt(timeInMillis);
Map<String, Object> params = new HashMap<>(); try { params.put("cancel_at", diffTimeInMillis + subscription.getStartDate()); } catch (Exception e) {
Can you please tell me what is wrong i am doing ?
Where are you getting diffTimeInMillis?
i got current LocalTime added 6 months to it and then got its time in millis
My current guess is you are using a different tick rate when calculating this time stamp
can i share the complete code here?
Our timestamps are standard unix timestamps. The count of seconds since Midnight January 1st, 1970
Yes, Java also does that
Can you share just the snippet of code where you calculate the timestamp that you are sending us?
Session session = (Session) stripeObject;
LocalDateTime currentDateTime = LocalDateTime.now();
LocalDateTime advanceDateTime = LocalDateTime.now().plusMonths(6);
ZonedDateTime advanceZonedDateTime = advanceDateTime.atZone(ZoneId.of("Australia/Sydney"));
ZonedDateTime currentZonedDateTime = currentDateTime.atZone(ZoneId.of("Australia/Sydney"));
Long advanceTimeInMillis = advanceZonedDateTime.toInstant().toEpochMilli();
Long currentTimeInMillis = currentZonedDateTime.toInstant().toEpochMilli();
Long diffTimeInMillis = advanceTimeInMillis - currentTimeInMillis;
Subscription subscription = Subscription.retrieve(session.getSubscription());
subscription.getStartDate();
// subscription.setEndedAt(timeInMillis);
Map<String, Object> params = new HashMap<>();
try {
params.put("cancel_at", diffTimeInMillis + subscription.getStartDate());
} catch (Exception e) {
Some specific libraries do not
Session session = (Session) stripeObject;
LocalDateTime currentDateTime = LocalDateTime.now();
LocalDateTime advanceDateTime = LocalDateTime.now().plusMonths(6);
ZonedDateTime advanceZonedDateTime = advanceDateTime.atZone(ZoneId.of("Australia/Sydney"));
ZonedDateTime currentZonedDateTime = currentDateTime.atZone(ZoneId.of("Australia/Sydney"));
Long advanceTimeInMillis = advanceZonedDateTime.toInstant().toEpochMilli();
Long currentTimeInMillis = currentZonedDateTime.toInstant().toEpochMilli();
Long diffTimeInMillis = advanceTimeInMillis - currentTimeInMillis;
Subscription subscription = Subscription.retrieve(session.getSubscription());
subscription.getStartDate();
// subscription.setEndedAt(timeInMillis);
Map<String, Object> params = new HashMap<>();
try {
params.put("cancel_at", diffTimeInMillis + subscription.getStartDate());
} catch (Exception e) {
i wanted to do it like this :
Session session = (Session) stripeObject;
// LocalDateTime currentDateTime = LocalDateTime.now();
LocalDateTime advanceDateTime = LocalDateTime.now().plusMonths(6);
ZonedDateTime advanceZonedDateTime = advanceDateTime.atZone(ZoneId.of("Australia/Sydney"));
// ZonedDateTime currentZonedDateTime = currentDateTime.atZone(ZoneId.of("Australia/Sydney"));
Long advanceTimeInMillis = advanceZonedDateTime.toInstant().toEpochMilli();
// Long currentTimeInMillis = currentZonedDateTime.toInstant().toEpochMilli();
// Long diffTimeInMillis = advanceTimeInMillis - currentTimeInMillis;
Subscription subscription = Subscription.retrieve(session.getSubscription());
subscription.getStartDate();
// subscription.setEndedAt(timeInMillis);
Map<String, Object> params = new HashMap<>();
try {
params.put("cancel_at", advanceTimeInMillis);
} catch (Exception e) {
but this didnt work
let me remove comments for you to make it easy to read
Session session = (Session) stripeObject;
LocalDateTime advanceDateTime = LocalDateTime.now().plusMonths(6);
ZonedDateTime advanceZonedDateTime = advanceDateTime.atZone(ZoneId.of("Australia/Sydney"));
Long advanceTimeInMillis = advanceZonedDateTime.toInstant().toEpochMilli();
Subscription subscription = Subscription.retrieve(session.getSubscription());
subscription.getStartDate();
Map<String, Object> params = new HashMap<>();
try {
params.put("cancel_at", advanceTimeInMillis);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
Subscription updatedSubscription = subscription.update(params);
So you need to divide your timestamp by 1000
Or just not get it in miliseconds
We are expecting a timestamp in seconds, if you send miliseconds, that will refer to a timestamp that is one thousand times further in to the future
Done. Thanks @slim pond . It worked
Great to hear!
Hi @slim pond , another query , how can i retrieve Product description in the same checkout event ?
The product against which this subscription has been created
You can retrieve the Checkout Session with its ID https://stripe.com/docs/api/checkout/sessions/retrieve
And then check the Checkout Session's line_items to see what was a part of that Checkout Session
https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-line_items
I have this session "com.stripe.model.checkout.Session" , how can i find the Product out of it ?
That session has an ID correct? It should look like this cs_123...
Yes, after you retrieve the Session, the product should be under LineItem
Hey, i get null LineItem , here is my code :
LineItemCollection lineItems = session.getLineItems();
if (lineItems != null) {
List<com.stripe.model.LineItem> lineItemList = lineItems.getData();
for (com.stripe.model.LineItem lineItem : lineItemList) {
Price price = lineItem.getPrice();
product = price.getProductObject().getDescription();
System.out.println(product);
}
}
👋 I'm hopping in since @slim pond had to head out
Yes please
Are you saying you're not getting back any line items when you retrieve your checkout session?
yes , thats correct
i get the subscription object out of session but not Lineitems
I need to get the product , which i suppose available under LineItems only
When you're retrieving the Checkout Session have you made sure to expand line_items?
What do you mean, thats how i got checkout session :
case "checkout.session.completed":
System.out.println("eventId: " + event.getId());
System.out.println("stripeObject: " + stripeObject);
Session session = (Session) stripeObject;
String product = null;
LocalDateTime advanceDateTime = LocalDateTime.now().plusMonths(6);
if (session.getSubscription() != null) {
EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
StripeObject stripeObject = null;
if (dataObjectDeserializer.getObject().isPresent()) {
stripeObject = dataObjectDeserializer.getObject().get();
This is stripeObject
Ah, so you're just looking at the Checkout Session returned from the checkout.session.completed event? If you want to get the line items you'll need to re-retrieve the Checkout Session and expand (see https://stripe.com/docs/expand ) line_items since it's not included by default
Sorry to bother your @dull musk . Is this the right approach :
SessionRetrieveParams params = SessionRetrieveParams.builder().addExpand("line_items").build();
Session session1 = (Session) stripeObject;
System.out.println("Stripe Session Id: " + session1.getId());
Session session = Session.retrieve(session1.getId(), params, null);
or i just dont need to do the last line as all
Yes, that would be the right idea (you do need that list line to do the retrieve)