#John
1 messages · Page 1 of 1 (latest)
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
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)
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
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
Yep, the two common things to do with failed payments are:
- Retry the payment (often with Smart Retries) https://stripe.com/docs/billing/subscriptions/overview#settings
- Ask the user to add a new payment method
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
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?
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.
what about the current circle that is unpaid
will it charge him?
Or I need to follow another process
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
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?
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
How the subscription knows about the new PaymentIntent that I will create?
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
The paymentIntent has a field "invoice
"
I will use that Id here and I will create a paymentIntent
is that correct?
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?
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?
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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?
You have a few options:
- Re-use your custom page that created PaymentMethods, use the new PaymentMethod to pay the old invoice
- Send the user to the invoice's stripe-hosted page
- Make a custom page that confim's the invoice's payment intent
- Use the stripe-hosted customer portal to collect new payment details
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'?
For a new subscription if the card is declined, the subscription's status won't be active. For existing subscriptions, the subscription's status depends on what you have set in your billing settings https://dashboard.stripe.com/settings/billing/automatic
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
lovely thank you a lot!