#sc0rp10npy_code
1 messages ยท Page 1 of 1 (latest)
๐ 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.
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.
- sc0rp10npy_code, 23 minutes ago, 31 messages
- sc0rp10npy_code, 1 hour ago, 24 messages
What error are you seeing?
after the prebuilt checkout page, i am getting redirected to success page so it means the checkout was success right
but then on its retrieval i get this error
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',
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
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
no, you don't need to pass anything to success_url yourself. See: #1275497812997574826 message
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
๐ Stepping in for my teammate, give me a few minutes to catch up
offtopic question, how does Stripe bot decide whom to add from staff? ๐ค
sure
We handle this on our end with a schedule
ahh nice
You just need to store the PaymentMethod ID in your database and use this when creating a PaymentIntent at a later time
but in this i dont see option to pass payment id
https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
https://docs.stripe.com/payments/save-and-reuse?platform=web&ui=stripe-hosted#use-payment-method
When you create an off-session PaymentIntent, you can pass a PM: https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method
What do you mean by "payment id" exactly?
this PaymentMethod ID sorry
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)
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
Not exactly. You'll also need to confirm the PaymentIntent and pass off_session: true to indicate that your customer is not actively within your application: https://docs.stripe.com/payments/save-during-payment?platform=web&ui=elements#charge-saved-payment-method
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
yeah i created intent with off_session: true
now with off_session as true
i can charge user on their behalf right?
With off_session: 'true', you can charge the user without them having to take any other action
cool thanks
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,
});
I take it Number(box.current_box_final_price).toFixed(2) is not an integer?
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
Can you share the PaymentMethod ID you're trying to use?
pm_1PpzPaJ8kO80VBO8isyB24aL
Ah, I see
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
So, what you should do instead is create a Customer first, then pass their ID when creating the Session: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-customer
Or pass customer_creation: 'always' when creating the Session: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-customer_creation
When the Session is completed, the PaymentMethod will be automatically attached to the customer and can be re-used
but then how did it got attached to user?
see this customer id
Yeah, I think you're mixing things up. The card that's currently attached to cus_QdhFiPF4nDqsYY was created when confirming this SetupIntent: https://dashboard.stripe.com/test/logs/req_ySD441BWEAimaE
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
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
No hold on
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
Using setup mode implicitly means you're setting up the PaymentMethod for future usage
https://dashboard.stripe.com/test/logs/req_QQMugM1RoMgALh
Here is where you need to pass two additional things:
off_session: true
confirm: true
where?
Did you click on the request?
Confirming is what actually triggers the payment attempt using the PaymentMethod you provided
ah got it
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
What do you mean by "change" exactly?
As for delete, you can detach a PaymentMethod from a customer which means it can no longer be used for a charge nor re-attached to any customer: https://docs.stripe.com/api/payment_methods/detach
wait so if a user deletes a saved paymet method then they can't ever add it again?
like if I had saved card A, i want to remove card A and attach card B
If a PaymentMethod is detached and the user wants to use the same underlying card again, they would have to provide their payment method details again. At that point, a new PayentMethod object (with a new ID) will be created
ah got it
You can make a call to detach the PM for card A then have the customer go through Checkout in setup mode again so they can provide card B's details. We'll take care of creating the PM for card B when the user completes the Session