#-7he-judge-_error

1 messages ยท Page 1 of 1 (latest)

hollow wadiBOT
#

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

๐Ÿ“ 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.

unreal vector
#

here's my part of this code

try {
            await this.stripe.paymentMethods.attach(paymentMethodId, {
              customer: paymentIntent.customer as string,
            });
            this.logger.log(
              `Attached payment method ${paymentMethodId} to customer ${paymentIntent.customer}`,
            );
          } catch (attachError) {
            if (attachError.code === 'resource_already_exists') {
              this.logger.log(
                `Payment method ${paymentMethodId} is already attached to customer ${paymentIntent.customer}`,
              );
            } else {
              this.logger.error(
                `Failed to attach payment method ${paymentMethodId} to customer ${paymentIntent.customer}: ${attachError.message}`,
              );
              // Skip creating subscription for this product when payment method isn't attachable
              continue;
            }
          }
hoary wolf
#

hi there, it looks like that payment method was used to confirm a payment before you attached it. can you describe why you need to attach it to this particular customer? what are you trying to accomplish?

unreal vector
#

strange behavior
it looks okay on DEV env
but got this error on PROD

#

I try to attach it, and activate subscription after

hollow wadiBOT
scenic kiln
#

๐Ÿ‘‹ Taking over this thread, cathing up now

#

The payment method has been used in making payment intent (pi_3SD26dEFwYCC7pJU1CWS2ZJF) in https://dashboard.stripe.com/logs/req_Nd8iQf8qFwgpCA on 2025-09-30 11:52:31 UTC. When the payment method has been used without prior attaching to the customer, this payment method can't be attached again, which was what your system has done on 2025-09-30 11:52:33 (2 seconds later) in https://dashboard.stripe.com/logs/req_BKSSPITe723I0E.

#

The correct flow should be attaching to the customer first, then using it to make a payment

unreal vector
#

do I need to review my logic?

scenic kiln
#

Yes. You should ensure the payment method is attached to the customer first, before using it for any payments, or you can save a payment method directly when making a payment. I think the latter will probably easier. Your system can set setup_future_usage: 'off_session' in the Payment Intent creation to indicate that you would like to save payment method at the same time: https://docs.stripe.com/payments/save-during-payment?payment-ui=elements#create-the-paymentintent. With this, you don't have to attach the payment method since setup_future_usage: 'off_session' save payment method automatically for you.

Learn how to save your customer's payment details for future purchases when they make a payment.

unreal vector
#

but I use deferred payment flow
is it possible to connect?

scenic kiln
#

Yes! With deferred intent flow, you can save the payment method when it is first used in a Payment Intent

#

I'd recommend giving it a try in test mode

hollow wadiBOT
torpid spruce
#

hello! fyi i am taking over this thread, let me know if you have any additional questions

unreal vector
#

I'm trying to fix the problem

#

if I create payment intent with subscription for ex
how could I active subscription?
because it creates subscriptions manually, if this payment intent is exists

torpid spruce
#

i don't think i understand the question entirely. could you share the exact steps you are following in your code? what API calls are you calling and in what order? typically for a Subscription you wouldn't want to create a separate Payment Intent, because we create one automatically depending on how you've configured your subscriptions

#

can you share an example subscription ID of a subscription you've created too?

unreal vector
#

look, I have subscription product in payment intent
I make succeeded payment, and event catches in webhook, and I have function manuallyCreateStripeSubscriptions

it mappes by products, and check if it's subcription - it activates it manually in real stripe

Like here

But problem, that it creates new transactions
I must avoid it

torpid spruce
#

can you share both the PaymentIntent ID and the Subscription ID from that example screenshot you shared?

#

the flow you're using in this function is pretty unusual. most of the time our users will do one of the following:

  • use a SetupIntent to collect a Payment Method, attach that to a customer, and then create a Subscription
  • create a Subscription, which automatically creates a PaymentIntent, and from there you collect the Payment Method using one of our UIs (that's the flow we outline in this guide, which I highly recommend reading)

both of these flows result in just a single payment, rather than the 2 payments you are seeing.

is there a specific reason you're using this flow of creating a PaymentIntent and then trying to create a Subscription after?

unreal vector
#

pm_1SD1EeEFwYCC7pJUc0VhhZyb

#

sub_1SD1EfEFwYCC7pJUzlpNilkD

#

I've followed this way, cause I could not do it via one transaction
And I've decided create it in webhook

But the main problem - it changes money on 2nd transaction

torpid spruce
#

I've followed this way, cause I could not do it via one transaction
can you elaborate on what this means? why do you need 2 "transactions"?

unreal vector
#

I don't need 2nd transaction
I did not know how to handle it, that's why I decided move this way

#

but I must get rid of 2nd transaction, and create subscrion just with one

torpid spruce
#

this results in just a single transaction created on the subscription.

#

as an alternative, you can technically create the subscription using the trial_period_days parameter (docs) which will create the subscription in free trial mode for the first X days you specify. this will stop your subscription from creating the second charge. but this is a highly unusual approach, and following our guides will make your system much easier to maintain over time.