#yurt_ideal-sepadebit

1 messages · Page 1 of 1 (latest)

inland impBOT
#

👋 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/1432767460288888945

📝 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.

normal bough
midnight urchin
#

req_lRlYxi4UgRzEfN

normal bough
midnight urchin
#

So the use case is this - the Payment Elements saves the payment method on the customer, but then in a webhook I need to set it as the default payment method for the customer and the subscription.

normal bough
#

That sounds right to me. The error was thrown on saving the payment method to the customer, which incorrect payment method ID is used to attach to the customer. By using generated_sepa_debit, you should be able to attach the payment method successfully

midnight urchin
#

Are there other payment methods that have special rules?

normal bough
midnight urchin
#

How do I check the SetupIntent for the type of the payment method?

#

i.e. how will I know it's a BancCard or a iDeal?

midnight urchin
# normal bough In addition, I'd recommend using Setup Intent to attach the payment method to th...

I'm using a Checkout Session to generate the client secret I need for the Elements API because I need to be able to show Tax ID element in the proper countries as well.

I'm not sure how to use the SetupIntent to attach the payment method to the customer?

I'm retriving the Payment Method like so:

  const setupIntent = await stripe.setupIntents.retrieve(
    session.setup_intent.toString(),
    {
      expand: ['latest_attempt'],
    }
  );
  const paymentMethodId = setupIntent.payment_method?.toString();

normal bough
#

I'd recommend expanding the payment_method field. The payment method details will be available under payment_method field after the expansion

inland impBOT
midnight urchin
#

Will I still need to get the generated_sepa_debit from latest_attempt then?

#

I guess I'm confused as to how expanding the payment field will attach it to the customer

urban aspen
#

yurt_ideal-sepadebit

#

Expand is used to see the generated PaymentMethod. It should be attached automatically

#

You need to make sure that your original SetupIntent has the Customer id in the customer parameter, is that the case?

midnight urchin
#

I think it does
Is this the right expansion declaration?

const setupIntent = await stripe.setupIntents.retrieve(
session.setup_intent.toString(),
{
expand: ['latest_attempt', 'payment_method'],
}
);

urban aspen
#

depends what you are trying to look for. I recommend you run that request, look at the response and then see if you get what you need first

midnight urchin
#

OK, I am looking at it right now

#

yeah I see that it has the same issue, generated_sepa_debit only seems to come from latest_attempt

urban aspen
#

what is "the same issue"? Like what exactly isn't working for you?

midnight urchin
#

On my backend, I am creating a checkout session in setup mode to create a secret for the frontend to use the Payment, Address and Tax ID elements with stripe.js

Then, I listen for the event webhook for checkout.session.completed, where I would like to:

  1. Update the payment method to be the default payment method for the customer
  2. Update the subscription default payment method
  3. Check if a subscription is paused, if it is, resume the subscription, and charge the default payment method for the generated invoice

I was relying on the setupIntent.payment_method ID as the ID to set the to the default payment method for the customer and the subscription

This seemed to work fine with US credit card testing, but once I tried using a Bancard is when I ran into the issue that I need to use a different ID.

When I expand payment_method, the id is still not the correct one.

So I am wondering if I conditionally change the payment_method_id only for paymentMethod.type === 'bancontact' and paymentMethod.type === 'ideal' to use generated_sepa_debit, and if all others will work with just the payment_method.id?

urban aspen
#

gotcha, thanks for the clear summary!
And yes that would work for iDEAL and Bancontact in that case! Most are the SetupIntent's payment_method but in that case it's a separately generated one

midnight urchin
#

I suppose I am wondering if I am approaching this the right way. Is there another way to save the payment method as the customer default using the Stripe Elements settings, or the Checkout Session creation settings?

urban aspen
#

Not in that specific flow. What you are doing is correct though a bit convoluted for sure

midnight urchin
#

Is there anything in this specific setup that would prevent the use of these saved default methods (bancard and ideal) for charging the generated invoice for a subscription resuming from a paused state?

urban aspen
#

no it should work fine. You should be able to test all of this in Test mode too

midnight urchin
#

OK, I will try this and see if it functions properly

#

Just to be clear - there is no need for manually attaching the payment method ID to the customer with this workflow, correct?

urban aspen
#

correct