#sc0rp10npy_code

1 messages ยท Page 1 of 1 (latest)

tough cloakBOT
#

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

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

jovial schoonerBOT
#

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.

frosty idol
#

What error are you seeing?

strong forge
#

after the prebuilt checkout page, i am getting redirected to success page so it means the checkout was success right

#
StripeInvalidRequestError: No such checkout.session: cus_QdhFiPF4nDqsYY
    at StripeError.generate (file:///Users/sc0rp10n/MyStuff/freelancing/eko-maistas/node_modules/stripe/esm/Error.js:7:20)
    at res.toJSON.then.StripeAPIError.message (file:///Users/sc0rp10n/MyStuff/freelancing/eko-maistas/node_modules/stripe/esm/RequestSender.js:102:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'StripeInvalidRequestError',
  raw: {
    code: 'resource_missing',
    doc_url: 'https://stripe.com/docs/error-codes/resource-missing',
    message: 'No such checkout.session: cus_QdhFiPF4nDqsYY',
    request_log_url: 'https://dashboard.stripe.com/test/logs/req_OfZBtSEiv6UE3C?t=1724185881',
    type: 'invalid_request_error',
frosty idol
#

You're passing customer ID instead of checkout session ID.
cus_xx prefix is used for customer objects

cs_test or cs_live prefix is used for checkout object

strong forge
#

in this part

const session = await stripe.checkout.sessions.create({
                payment_method_types: ["card"],
                mode: "setup",
                success_url: `${process.env.WEB_URL}/success?session_id=` + id,
                cancel_url: `${process.env.WEB_URL}/cancel`,
                customer_email: email,
            });

for session id i have to pass my own created id right?
then i thought to pass customer id itself

frosty idol
strong forge
#

oh so i let the variable be there

#

ohh

#

ok so after this

const session = await stripe.checkout.sessions.retrieve(session_id);
            const setupIntent = await stripe.setupIntents.retrieve(
                session.setup_intent
            );

i get setupIntent.payment_method ?

#

i have created session, retrieved setupIntent id and i got payment method from it

what do I have to do after this?

i want to save the card token to charge user off_session later every month

tough cloakBOT
whole stratus
#

๐Ÿ‘‹ Stepping in for my teammate, give me a few minutes to catch up

strong forge
#

offtopic question, how does Stripe bot decide whom to add from staff? ๐Ÿค”

whole stratus
strong forge
#

ahh nice

whole stratus
#

You just need to store the PaymentMethod ID in your database and use this when creating a PaymentIntent at a later time

strong forge
whole stratus
#

What do you mean by "payment id" exactly?

strong forge
#

this PaymentMethod ID sorry

whole stratus
#

Okay, we're looking at the same docs. When you create the PI, you will pass payment_method: 'pm_123abc' if you want to charge a specific PaymentMethod that's already attached to the customer (it was attached when they completed the Checkout Session)

strong forge
#

so

const paymentIntent = await stripe.paymentIntents.create({
  amount: {x_amount},
  currency: 'usd',
  automatic_payment_methods: {
    enabled: true,
  },
  payment_method: "payment method ID"
});

so just this

whole stratus
#

This doc is generally about saving payment details during a payment, which uses PaymentIntents instead of SetupIntents but the portion of the guide that describes how to create off-session payments using previously-saved PaymentMethods is the same regardless of whether an SI or PI was used to save the PM in the first place

strong forge
#

now with off_session as true
i can charge user on their behalf right?

whole stratus
#

With off_session: 'true', you can charge the user without them having to take any other action

strong forge
#

why this error?

StripeInvalidRequestError: Invalid integer: 15.21

#

@whole stratus

#
const paymentIntent = await stripe.paymentIntents.create({
    amount: Number(box.current_box_final_price).toFixed(2),
    currency: "usd",
    customer: user.stripe_customer_id,
    payment_method: user.payment,
});
whole stratus
#

I take it Number(box.current_box_final_price).toFixed(2) is not an integer?

strong forge
#

its 15.21 thats passed

#

so i have to pass 15 or 16?

#

ok so i had to multiply by 100

#

now I get this error
StripeInvalidRequestError: The provided PaymentMethod cannot be attached. To reuse a PaymentMethod, you must attach it to a Customer first.

why so? i already created the setup intent while passing the customer id

whole stratus
#

Can you share the PaymentMethod ID you're trying to use?

strong forge
#

pm_1PpzPaJ8kO80VBO8isyB24aL

whole stratus
#

Ah, I see

strong forge
#

the customer id
cus_QdhFiPF4nDqsYY

#

its attached though

whole stratus
#

That's a different PM ID

#

If you expand the PaymentMethod in the Dashboard, you'll see that PM ID is different from what you shared above

#

I think you're mixing things up. When creating a setup mode CheckoutSession, a Customer is not automatically created. I see you created a Session and passed customer_email but this does not automatically create a customer

#

When the Session is completed, the PaymentMethod will be automatically attached to the customer and can be re-used

strong forge
#

but then how did it got attached to user?

strong forge
whole stratus
#

When you created that SetupIntent, you included customer: "cus_QdhFiPF4nDqsYY". This means the PM created when the SI was confirmed was automatically attached to this customer. THis SI was confirmed via the CardElement, not Checkout

strong forge
#

oh its old one

#

lemme try again

#

@whole stratus ok so now why does the output of payment_intent says this?
status: 'requires_confirmation',

{
  id: 'pi_3Pq09hJ8kO80VBO81eAVTKfG',
  object: 'payment_intent',
  amount: 1521,
  amount_capturable: 0,
  amount_details: { tip: {} },
  amount_received: 0,
  application: null,
  application_fee_amount: null,
  automatic_payment_methods: { allow_redirects: 'always', enabled: true },
  canceled_at: null,
  cancellation_reason: null,
  capture_method: 'automatic_async',
  client_secret: 'pi_3Pq09hJ8kO80VBO81eAVTKfG_secret_vouEtAzKgGoWM2yH5apZQ6quG',
  confirmation_method: 'automatic',
  created: 1724191437,
  currency: 'usd',
  customer: 'cus_QdhFiPF4nDqsYY',
  description: null,
  invoice: null,
  last_payment_error: null,
  latest_charge: null,
  livemode: false,
  metadata: {},
  next_action: null,
  on_behalf_of: null,
  payment_method: 'pm_1Pq054J8kO80VBO8yrCx0bXj',
  payment_method_configuration_details: { id: 'pmc_1PghgRJ8kO80VBO8ydENM4WY', parent: null },
  payment_method_options: {
    card: {
      installments: null,
      mandate_options: null,
      network: null,
      request_three_d_secure: 'automatic'
    }
  },
  payment_method_types: [ 'card' ],
  processing: null,
  receipt_email: null,
  review: null,
  setup_future_usage: null,
  shipping: null,
  source: null,
  statement_descriptor: null,
  statement_descriptor_suffix: null,
  status: 'requires_confirmation',
  transfer_data: null,
  transfer_group: null
}
#

oh wait i forgot to do offsession thing

whole stratus
#

No hold on

strong forge
#
const session = await stripe.checkout.sessions.create({
    payment_method_types: ["card"],
    mode: "setup",
    success_url: `${process.env.WEB_URL}/success?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${process.env.WEB_URL}/cancel`,
    // customer_email: email,
    customer: id,
});

i have to add off_session: true, here right?

#

nope it gives error

whole stratus
#

Using setup mode implicitly means you're setting up the PaymentMethod for future usage

strong forge
#

where?

whole stratus
#

Did you click on the request?

strong forge
#

yeah got it

#

so what does confirm do?

whole stratus
#

Confirming is what actually triggers the payment attempt using the PaymentMethod you provided

strong forge
#

cool yes it worked

#

thanks

strong forge
#

also what is the process to change or delete saved payment method?

we have option in settings to change and delete saved payment method too

whole stratus
#

What do you mean by "change" exactly?

strong forge
strong forge
whole stratus
whole stratus
strong forge
#

got it

#

thanks