#John

1 messages · Page 1 of 1 (latest)

desert inletBOT
kindred steeple
#

With cancel_at we should just use the timestamp that we give you. Can you run that code and print out the value that Math.floor(endDate.getTime() / 1000) resolves to? It sounds like that calculation may be off in some way

timid warren
#

1696515701

#

this is the value that I get

#

console.log('Math.floor(endDate.getTime() / 1000) ', Math.floor(endDate.getTime() / 1000) )

RESOLVES TO:

Math.floor(endDate.getTime() / 1000) 1696515805

AND

console.log('resolve', new Date(1696515701 * 1000).toString())

RESOLVES TO

resolve Thu Oct 05 2023 16:21:41 GMT+0200 (Central European Summer Time)

kindred steeple
#

Yep, that timestamp looks right. Can you create a subscription with that as the cancel at and send me the ID? We should just use the timestamp that you give us

timid warren
#

Hi I had to restart the editor because I could not identify the problem

#

and it worked

#

Maybe it was IDE issue

#

I cannot say unfortunately.

#

I have another question.

#

If the payment fail in the subscription

#

What are the next steps?

From my point of view I want to ->

Change the payment method and update the paymentMethodId in the subscription..

Can I use the new paymentMethod by just updating the subscription?

#

The end result is that I want to charge the client with the new payment Method

kindred steeple
#

You can set the new payment method as the default payment method for either the customer or subscription to tell stripe to charge that payment method for future subscription cycles

timid warren
#

Ok I create a subscription with a credit card and because the paymentMethod failed the subscription will have different state from ''áctive'

#

To request again payment I need to update the subscription with the new paymentMethodId

#

and the subscription will use that paymentMethodId automatically to charge the client?

#

Or I need to delete the subscription and create a new one?

kindred steeple
#

You would update the existing subscription

#

Yes, if you set that payment method as the default_payment_method for that Subscription, it will charge the user for future cycles.

timid warren
#

what about the current circle that is unpaid

#

will it charge him?

#

Or I need to follow another process

kindred steeple
#

You can actually use the payment intent from the unpaid invoice to save this new payment method. That way saves the payment method and pays the overdue payment at the same time

timid warren
#

So if the payment method fails.

  • I will request from the client to change the paymentMethod
  • I will use paymentIntent for the customer to pay the amount.

Then somehow I need to change the status of the subscription to active?

kindred steeple
#

Yes, the subscription's status is based on the status of the latest invoice/payment intent

#

So paying that paymentintent will make the subscription active again

timid warren
#

How the subscription knows about the new PaymentIntent that I will create?

kindred steeple
#

It wouldn't. I was suggesting that you use the PaymentIntent from the subscription's latest invoice

#

latest_invoice on the subscription object

#

That intent already exists and is associated with the subscription

timid warren
#

The paymentIntent has a field "invoice
"

#

I will use that Id here and I will create a paymentIntent

#

is that correct?

kindred steeple
#

No, you don't need to create a new intent here

#

Because the existing invoice is still unpaid, the payment intent is in a similar state

#

So you can use that intent when collecting this new payment method.

#

Actually, taking a step back. How are you collecting this payment method originally? Is this your own custom page or is it Stripe Checkout?

timid warren
#

I am creating a new PaymentMethod.

  • creating a new customer
  • attaching the paymentMethod to the customer
  • create subscription using
    -- customerId
    -- paymentMethodID
#

this is the process

It is custom process

#

With :
So you can use that intent when collecting this new payment method.

Do you mean I need to attach only the invoiceId to the paymentIntent?

kindred steeple
#

Gotcha, so in that case, I think it would be simpler for you to repeat that process of creating the PM and attaching it to the customer. To make the payment you could then make this call to attempt to pay the invoice with that payment method https://stripe.com/docs/api/invoices/pay#pay_invoice-payment_method

timid warren
#

So I need to send again to the customer the invoice that is attached to the existing Subscription by using the link above

#

correct?

#

with ID: "latest_invoice": "in_1NQWebFU2Rziu4OB0DDa4svE",

#

You said this is the simplest way.
What other ways we have?

kindred steeple
#

You have a few options:

  1. Re-use your custom page that created PaymentMethods, use the new PaymentMethod to pay the old invoice
  2. Send the user to the invoice's stripe-hosted page
  3. Make a custom page that confim's the invoice's payment intent
  4. Use the stripe-hosted customer portal to collect new payment details
timid warren
#

Thank you Pompey for your help

#

the 1. is the easiest

#

Actually I have one last question

#

If I use a paymentMethod that the card does not have money

#

and I try to create a subscription

#

Will the status of the subscription be different from 'active'?

kindred steeple
timid warren
#

lovely thank you a lot!