#ashish_subscription-renewal
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1270417217909166311
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hey @digital mountain ! What does "payment is getting failed" mean exactly? You shared a request id which is great but it's just a manual click on a TestClock in the Dashboard. So having a more specific question with clearer details would help
There is no log of that payment but I managed to get event id evt_1Pkpr7A9qVxHukS4QzwIsuWt
yeah sorry I am asking for a lot of details and you shared one id with no info. Sorry there are dozens of ways to use Stripe and I need you to provide a bit of a summary of waht the issue is here
I wanted to create a update subscription endpoint. I want any changes in the subscription to happen only after the current billing cycle. So I did the following created a schedule with start date as end date of current plan and cancelled the current plan by setting end at current billing cycle
That's working fine, the existing plan gets cancelled and then the new plan starts but the payment gets failed
This is latest event id which says event invoice payment failed
evt_1PkqIaA9qVxHukS4gkyo8cJx
Thanks for your time and help
Gotcha. My guess is that you misunderstood how the concept of a "default payment method" works and you didn't set one on your Customer or the associated Subscription/SubscriptionSchedule. See https://docs.stripe.com/billing/subscriptions/payment-methods-setting
ashish_subscription-renewal
I checked await stripe.paymentMethods.list({
customer: customerId,});
In the response I can see the card
okay so that worked?
No, it didn't. There is card associated to that customer yet it's failing
Okay so you didn't read the doc I just shared yet. Make sure to carefully go through it first
I read the doc but couldn't understand where I'm going wrong. Sorry I pretty new to this, please bear with me
Here is the code I used, if that could give you more idea
paymentRoutes.post('/update-subscription-plans', async (c) => {
try {
const { customerId, subscriptionId, newPriceId } = await c.req.json();
// Fetch the current subscription
const subscription = await stripe.subscriptions.retrieve(subscriptionId);
const isInTrial = subscription.trial_end && subscription.trial_end > Math.floor(Date.now() / 1000);
const currentPeriodEnd = isInTrial ? subscription.trial_end : subscription.current_period_end;
const schedules = await stripe.subscriptionSchedules.list({
customer: customerId,
});
const existingSchedule = schedules.data.find(schedule => schedule.subscription === subscriptionId);
const newPhase = {
items: [{ price: newPriceId }],
};
let result;
if (existingSchedule) {
result = await stripe.subscriptionSchedules.update(existingSchedule.id, {
phases: [
...existingSchedule.phases.map(phase => ({
items: phase.items.map(item => ({ price: item.price })),
start_date: phase.start_date,
end_date: phase.end_date,
})),
newPhase,
],
});
} else {
// Create a new schedule if no existing schedule for the subscription
result = await stripe.subscriptionSchedules.create({
customer: customerId,
start_date: currentPeriodEnd!-1,
end_behavior:'release',
phases: [
{
items:[{price:newPriceId}],
proration_behavior:'none'
},
],
});
await stripe.subscriptions.update(subscriptionId, {
cancel_at_period_end: true,
})
You have a Customer cus_123. That Customer has a saved card called a PaymentMethod pm_ABC
That PaymentMethod is not the default. You have to be explicit, as the developer, so that when you try to charge that card you tell us "please charge pm_ABC on Customer cus_123"
My guess is you created a brand new SubscriptionSchedule and forgot to tell us about which card to use
Ohh let me check and get back to you
Set this: https://docs.stripe.com/api/subscription_schedules/create#create_subscription_schedule-default_settings-default_payment_method on your new SubscriptionSchedule
Hey @blissful hound, thanks for pointing out. But there is only one issue for the first time schedule it is creating a new subscription id but for subsequent changes it is using the new subscription id only
Anyway to change this behavior to use only one subscription id through out?
Hi, I'm stepping in and catching up.
Cool
Can you share the specific request ids and the new subscription id that is being created? It seems like you're just attempting to update an exsiting subscription but you're saying that action is creating a new subscription?
I'm not sure of the request ids. But here is the customer id: cus_Qc1aIZuM1UzHxD. Which could give you more idea of what happened.
old subscription id: sub_1PknX5A9qVxHukS4q2wwtpIy
new subscription id for all subsequent changes: sub_1PkqtZA9qVxHukS42qhu9hKG
I even shared the code I was using above, if that helps in anyway
Looking
Ok, it seems like you're creating a subscription, then setting the cancel end period to true: https://dashboard.stripe.com/test/logs/req_NWXrm3nofS6wKH. Then, you're updating the schedules? I'm trying to reproduce this on my end but having a very hard time understanding the steps you took. Can you lay out the exact steps you're taking? Like steps 1, create a subscription.. Step 2, update the subscription etc with much more details?
Did u mean this?
Sry for delay. I'm not getting notifications
no, not the code but explicitly stating what you're doing so I can reproduce this on my end.
Oh ok
First I'm checking whether there is any schedule associated with given customer id and subscription id.
If it exists then I'm calling schedulesUpdate. If it's not there then I'm calling createSchedule with customerId which is creating a new subscription
Hmm, can you share the exact steps with the requests you're making for the above customer? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
The issue is that I need to replicate this on my end to understand what is going on, and it is hard to follow what is happening with the amount of update requests you've made on the above example.
๐ . I'll try to narrow down
Thank you!
One question
When we do stripe.subscriptions.retrieve() does it give the past scheduled plans too or the one which gonna executed?
I'm unsure what that means but it would return the subscription if you passed on the request: https://docs.stripe.com/api/subscriptions/retrieve no matter it's status.
I need some more time to narrow down. I'll be back asap at max by tmrw