So I'm trying to create a monthly subscription that will cancel in 2020-10-10
I pass such an object:
return stripe.subscriptions.create ({
customer: customer.id,
items: [{plan: plan.id}],
expand: ["latest_invoice.payment_intent"],
cancel_at: new Date('2020-10-10').getTime()
}
But on the Stripe dashboard, the subscription is as follows:
And I don't understand how I need to send the subscription cancellation date to cancel the subscription on the date I want Thanks in advance for any help!
The JS
Date.getTime()
method returns the time in milliseconds. The stripe api is expecting the time in seconds.
The simple conversion for milliseconds to seconds is:
Time in milliseconds / 1000 = Time in seconds
Your code should be:
const cancelAt = (new Date('2020-10-10').getTime()) / 1000;
return stripe.subscriptions.create ({
customer: customer.id,
items: [{plan: plan.id}],
expand: ["latest_invoice.payment_intent"],
cancel_at: cancelAt
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments