#sunagimo_api

1 messages · Page 1 of 1 (latest)

hollow steppeBOT
#

đź‘‹ 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/1361511873836613684

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

molten prism
#

In the dashboard, the card registered as a payment method is displayed.
However, it is not included in the invoice_settings of the Customer object.

#

I implemented it using the payment_method.id obtained from the SetupIntent on the frontend, but I got the following error:

The customer does not have a payment method with the ID pm_1RDjOGJeNdmp8jhmP0ddVmEa. The payment method must be attached to the customer.

Is it not possible to set the invoice settings directly without attaching the payment method to the customer first?

glass silo
#

Is it not possible to set the invoice settings directly without attaching the payment method to the customer first?

No it's not possible unless the PaymentMethod is already attached to the customer

molten prism
#

Thank you! Based on your advice, I was able to register invoice_settings.default_payment_method by first creating the customer, then calling Stripe::PaymentMethod.attach, and finally using Stripe::Customer.update!

glass silo
#

wait sorry, i'm a bit confused. You shouldn't be calling Stripe::PaymentMethod.attach directly

#

you should always be using either a SetupIntent or PaymentIntent to attach the PaymentMethod to the customer

#

are you creating one-off invoices?

molten prism
#

No, It's subscription

glass silo
#

you'll only create a customer and subscription when the customer submits their payment details

molten prism
#

Is there a way to register the card information in advance and set it as the default payment method?

glass silo
#

Can you share more on why you would want to register the card information in advance and set it as the default payment method?

Typically, the attachment to the customer is automatically done when you use the SetupIntent / PaymentIntent generated via the Subscription / Invoice. After the PaymentIntent or SetupIntent is successful, then you set the default payment method on the customer to that PaymentMethod

To be clear, you should never directly attach a PaymentMethod to a customer that has not been created through either a PaymentIntent or SetupIntent. If you directly attach a PaymentMethod to a customer that has not been created through either a PaymentIntent or SetupIntent, the PaymentMethod is not correctly set up for future usage. This could possibly result in a higher rate of declines.

molten prism
#

Initially, I registered the subscription via a setup intent, but this does not include the default payment method in the customer object. We need to register the default card because it’s necessary for displaying the customer’s default payment information in our service. On the other hand, if we can retrieve the default card from the customer object, there would be no need to register it. By the way, invoice.settings is null.

glass silo
#

If you follow this guide : https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription, what you can do is after the first invoice is paid for the subscription, you can update the customer with the default payment method. You can listen to the invoice.paid event and check if billing_reason=subscription_create

Build an integration where you can render the Payment Element prior to creating a PaymentIntent or SetupIntent.

molten prism
glass silo
#

alright, what's your question about the above customer?

molten prism
#

customers retrieve cus_S8FkTRjY3fveip
{
"id":
"cus_S8FkTRjY3fveip"
,
"object":
"customer",
"address":
null,
"balance":
0,
"created":
1744684105
,
"currency":
"jpy",
"default_source":
null,
"delinquent":
false,
"description":
null,
"discount":
null,
"email":
"mayue.arai@foriio.com",
"invoice_prefix":
"BEA933DF",
"invoice_settings": {
"custom_fields":
null,
"default_payment_method":
null,
"footer":
null,
"rendering_options":
null,
},
"livemode":
false,
"metadata": {},
"name":
"qweqwq",
"next_invoice_sequence":
2,
"phone":
null,
"preferred_locales": [],
"shipping":
null,
"tax_exempt":
"none",
"test_clock":

#

default_payment_method , invoice settings also null

#

How can I retrieve the default payment method?

glass silo
#

So it looks like you're creating a Subscription that has no amount that needs to be paid first.

I see you have a SetupIntent previously created with this customer. After the SetupIntent is successful, and the PaymentMethod has been attached to the customer, you would use https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method to update the customer's default payment method

molten prism
#

How is the PaymentMethod attached to the customer? What are the conditions for that?
Here is our current implementation:

setup_intent = Stripe::SetupIntent.create(
automatic_payment_methods: { enabled: true, allow_redirects: 'never' },
)

Stripe::Customer.create({ payment_method: paymentmethodId, email: email, name: name })

glass silo
#

ah, I see you're missing the customer parameter in the SetupIntent. If you include the customer id when creating the SetupIntent, the SetupIntent will automatically attach the payment method to the customer when it is successful

molten prism
#

So in the end, the simplest approach is to create the customer first and then create the setup intent. Thank you—this helped clarify my thoughts.