#akashpatil7596_api

1 messages ยท Page 1 of 1 (latest)

formal heraldBOT
#

๐Ÿ‘‹ 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.

noble jungleBOT
#

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.

lofty goblet
#

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

elder stone
#

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',           
          }
        );
lofty goblet
#

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

elder stone
#

means If I not set default_payment_method , the subscription charge from the default_payment_method of customer automatically?

lofty goblet
#

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

elder stone
#

But what if customer changes his payment method, like change the card.

lofty goblet
#

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

elder stone
#

okay and how can I retrieve the default payment method of the customer?

lofty goblet
#

default_payment_method of the customer or subscription? They are two different things

#

Can you share what you're trying to achieve?

elder stone
#

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

lofty goblet
#

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 the default_payment_method of 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 to default_payment_method of the subscription.

Whey do you need to retrieve the default_payment_method first?

elder stone
#

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

lofty goblet
#

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:

  1. When a subscription is created via Checkout Session, store the customer ID in your database
  2. 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
  3. Update the default_payment_method of the subscription to the payment method collected in Step 2: https://docs.stripe.com/api/subscriptions/update#update_subscription-default_payment_method

Learn how to save payment details and charge your customers later.

#

There shouldn't be any need to retrieve Subscription information at any part of your integration

elder stone
#

Okay One question though, once I attach new payment method to customer, will It become default_payment_method automatically?

lofty goblet
#

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

elder stone
#

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?

lofty goblet
#

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)?

elder stone
#

sub_1P1jAqIoZDVxPDheh4QmomEj

#

I update from $999 to $239 in this subscription and no Invoice credit balance has been saved for the customer

lofty goblet
elder stone
#

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

lofty goblet
#

No problem! Happy to help ๐Ÿ˜„

elder stone
#

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?

lofty goblet
#

The invoice created after canceling the subscription should include the remaining (proration) amount

elder stone
#

you mean I cancel the subscription and then get subscription.invoice.list and check for the latest invoice?

lofty goblet
elder stone
#

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

lofty goblet
#

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

elder stone
#
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?

lofty goblet
#

stripe error : subscription.cancel is not a function
You missed one s behind the subscription - it should be plural

stripe.subscriptions.cancel(
  'sub_xxx'
);