#akashpatil7596_api
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/1225301730258845706
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- akashpatil7596_api, 13 hours ago, 10 messages
- akashpatil7596_api, 15 hours ago, 32 messages
- akash_subscription-refund, 17 hours ago, 37 messages
- akashpatil7596_api, 19 hours ago, 14 messages
- akashpatil7596_webhooks, 20 hours ago, 72 messages
- akashpatil7596_api, 1 day ago, 36 messages
and 2 more
I'm afraid that's not possible. Stripe's proration behaviour will always prorate according to the usage. Alternatively, you can set proration_behavior to none (Stripe will not calculate proration), then your system will refund or credit full amount manually: https://docs.stripe.com/api/subscriptions/update#update_subscription-proration_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Okay, and when I'm upgrading or downgrading I use this API, do I have to pass default_payment_method necessary?
stripe.subscriptions.update(
subscriptionData?.subscriptionId,
{
items: [
{
id: subscriptionData?.oldItemId,
deleted: true,
},
{
price: price_id,
},
],
metadata: {
operation: subscriptionData?.operation,
charity_subscription_id: subscriptionData?.charitySubscriptionId,
subscription_plan_id: subscriptionData.subscriptionPlanId,
subscription_type: subscriptionData.subsciptionType,
plan_validation: subscriptionData.planValidation,
charity_id: subscriptionData.charityId,
},
proration_behavior: 'none',
}
);
default_payment_method is used to charge to a subscription. Unless the payment method is changed (such as customer changing a payment method), it's not necessary to set default_payment_method
means If I not set default_payment_method , the subscription charge from the default_payment_method of customer automatically?
If the subscription has an existing default_payment_method, you don't have to set it again in the Update Subscription request unless there is a change in the payment method. Subscription payment will charge the payment from the existing default_payment_method on the subscription.
Do you have an existing default_payment_method set on the subscription? If so, then it's not necessary to set it again in Subscription Update request
But what if customer changes his payment method, like change the card.
That's what I said - if only customer changes the payment method, then default_payment_method should be set
If there is no change, it's not necessary to be set in the update request
okay and how can I retrieve the default payment method of the customer?
default_payment_method of the customer or subscription? They are two different things
Can you share what you're trying to achieve?
Yes,
1). first customer buy the subscription using checkout.session , so the card details he/she entered will be, the default payment method of customer and subscription, right?
2). customer than update the payment method by entering another card detail.
3). then he/she , upgrade or downgrade the subscription using subscription.update , in this case which I have to attach default_payment_method cause It's changed. So how can I retrieve the default_payment_method first? and which payment method I have to attach as you said, customer's or subscription's?
Hello
1). first customer buy the subscription using checkout.session , so the card details he/she entered will be, the default payment method, right?
The payment method will be thedefault_payment_methodof the Subscription
2). customer than update the payment method by entering another card detail.
How does the customer update the payment method? Through Payment Element or Customer Portal?
3). then he/she , upgrade or downgrade the subscription using subscription.update , in this case which I have to attach default_payment_method cause It's changed. So how can I retrieve the default_payment_method first? and which payment method I have to attach as you said, customer's or subscription's?
If a new payment method is collected, then yes - new payment method should be set todefault_payment_methodof the subscription.
Whey do you need to retrieve the default_payment_method first?
2). customer than update the payment method by entering another card detail.
How does the customer update the payment method? Through Payment Element or Customer Portal?
const paymentMethod = await this.stripe.paymentMethods.create({
type: 'card',
card: {
token: token,
},
});
// //* Retrieve subscription from stripe
const getStripeCustomer = await this.stripe.subscriptions.retrieve(
subscriptionId
);
// //* Attaching payment method to customer
const pm = await this.stripe.paymentMethods.attach(paymentMethod.id, {
customer: getStripeCustomer.customer,
});
// * Attaching payment method to Subscription * //
await this.stripe.subscriptions.update(subscriptionId, {
default_payment_method: paymentMethod.id,
});
If a new payment method is collected, then yes - new payment method should be set to default_payment_method of the subscription.
Whey do you need to retrieve the default_payment_method first? -> I want to retrive which is the default_payment_method so I can attach it to subscription.update
First and foremost - Token integration is legacy and no longer recommended. You shouldn't use it to collect a new payment method.
To collect a new payment method, Setup Intent API should be used: https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
The steps should be:
- When a subscription is created via Checkout Session, store the customer ID in your database
- When the customer wants to update a new payment method, follow this guide to collect a new payment method on the customer ID in Step 1: https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=elements
- Update the
default_payment_methodof the subscription to the payment method collected in Step 2: https://docs.stripe.com/api/subscriptions/update#update_subscription-default_payment_method
There shouldn't be any need to retrieve Subscription information at any part of your integration
Okay One question though, once I attach new payment method to customer, will It become default_payment_method automatically?
No, it won't
If you use Setup Intent API, there is no need to attach the payment method to the customer
Setup Intent will attach to the customer if the request has customer set
Okay
Hey I got one issue,
When I'm downgrading from $999.99/year to $19.99/month There are two invoice generates in subscription invoice list,
But If I'm downgrade from $999.99/year to $239.88, there is only one Invoice, and that's creating an issue for the refund to customer process, why there is one invoice only?
When I'm downgrading from $999.99/year to $19.99/month There are two invoice generates in subscription invoice list,
Can you share the example subscription ID (sub_xxx)?
sub_1P1jAqIoZDVxPDheh4QmomEj
I update from $999 to $239 in this subscription and no Invoice credit balance has been saved for the customer
In https://dashboard.stripe.com/test/logs/req_lbooZjOG35J3vB, proration_behavior is not set. If proration_behavior is not set, it'll default to create_prorations, which will create proration in the next billing cycle which is 4 Apr 2025, but not invoice the proration immediately
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
If you wish to invoice it immediately, proration_behavior should be set to always_invoice: https://docs.stripe.com/api/subscriptions/update#update_subscription-proration_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
All I'm saying is If customer moves from 999.99 to 239.88, The remaining 760.11 Amount should be credited in Invoice credit balance, why that's not happening?
Okay yes It resolved By adding : proration_behavior : 'always_invoice', thanks very much
No problem! Happy to help ๐
Hello
If user cancel subscription after certain period, It has to be cancel immediately and the remaining amount should be refunded. Is there any API for calculate remaining amount?
The invoice created after canceling the subscription should include the remaining (proration) amount
you mean I cancel the subscription and then get subscription.invoice.list and check for the latest invoice?
When you cancel the subscription, you can find the latest invoice in the response under latest_invoice: https://docs.stripe.com/api/subscriptions/object#subscription_object-latest_invoice
No additional List call is required. You can then find the proration information in the latest invoice
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Okay Last Question,
1). When I cancel The subscription, will I get latest_invoice in response?
2). And for cancel the subscription which API should I use, is this okay?
stripe.subscription.cancel("sub_xxx",{
prorate: true
})
okay, you can close the thread now.
Thankyou
1). When I cancel The subscription, will I get latest_invoice in response?
Yes
2). And for cancel the subscription which API should I use, is this okay?
The coode looks correct to me
I'd recommend giving a try in test mode
stripe.subscription.cancel("sub_xxx",{
prorate: true
})
stripe error : subscription.cancel is not a function
1). When I cancel The subscription, will I get latest_invoice in response?
Yes
-> And in that the remaining amount will be mentioned?
stripe error : subscription.cancel is not a function
You missed onesbehind the subscription - it should be plural
stripe.subscriptions.cancel(
'sub_xxx'
);