#Hemant - subscription end date

1 messages · Page 1 of 1 (latest)

slim pond
#

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) {
supple plover
#

Can you please tell me what is wrong i am doing ?

slim pond
#

Where are you getting diffTimeInMillis?

supple plover
#

i got current LocalTime added 6 months to it and then got its time in millis

slim pond
#

My current guess is you are using a different tick rate when calculating this time stamp

supple plover
#

can i share the complete code here?

slim pond
#

Our timestamps are standard unix timestamps. The count of seconds since Midnight January 1st, 1970

supple plover
#

Yes, Java also does that

slim pond
#

Can you share just the snippet of code where you calculate the timestamp that you are sending us?

supple plover
# supple plover can i share the complete code here?

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) {
slim pond
#

Some specific libraries do not

supple plover
# slim pond Can you share just the snippet of code where you calculate the timestamp that yo...

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);
slim pond
#

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

supple plover
#

got u , let me make it seconds

#

and check

supple plover
#

Done. Thanks @slim pond . It worked

slim pond
#

Great to hear!

supple plover
#

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

slim pond
supple plover
#

I have this session "com.stripe.model.checkout.Session" , how can i find the Product out of it ?

slim pond
#

That session has an ID correct? It should look like this cs_123...

supple plover
#

yes

#

Is this available under LineItem ?

slim pond
#

Yes, after you retrieve the Session, the product should be under LineItem

supple plover
#

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);
                }
            }
dull musk
#

👋 I'm hopping in since @slim pond had to head out

supple plover
#

Yes please

dull musk
#

Are you saying you're not getting back any line items when you retrieve your checkout session?

supple plover
#

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

dull musk
#

When you're retrieving the Checkout Session have you made sure to expand line_items?

supple plover
#

EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
StripeObject stripeObject = null;
if (dataObjectDeserializer.getObject().isPresent()) {
stripeObject = dataObjectDeserializer.getObject().get();

dull musk
#

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

Learn how to reduce the number of requests you make to the Stripe API by expanding objects in responses.

supple plover
#

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);
supple plover
dull musk
#

Yes, that would be the right idea (you do need that list line to do the retrieve)