#tzarbuba-paymentintent-capture

1 messages · Page 1 of 1 (latest)

trim plaza
#

@past oracle that usually happens when you try to capture a PaymentIntent after a transaction but you didn't check if it succeeded first. The card likely got declined and it's asking for new card details

past oracle
#

how can I check if it is succeeded?

past oracle
#

so I have to handle it through webhook?

#

after creating payment intents I do have event type payment_intent.created

const paymentIntent = await stripe.paymentIntents.create({
            customer: customer_id,
            amount: amount,
            metadata: { type: 'lessons-payment' },
            description,
            currency: 'usd',
            payment_method_types: ['card'],
            capture_method: 'manual',
        });

        const intent = await stripe.paymentIntents.capture(paymentIntent.id, {
            amount_to_capture: amount,
});
trim plaza
#

yeah you're misunderstanding most of it

#

the first part is creating a PaymentIntent. The second part is capturing a successfully paid PaymentIntent. You're completely missing the part where you collect card details client-side and confirm the PaymentIntent first

#

you really need to read the doc I shared end to end first and make it work. Once that works you can then update it to handle separate authorization and capture

past oracle
#

as my demo is I don't have FE, isn't possible everything to be on BE

#

like creating the card attaching it to a customer creating payment method and then charge the paymentintent

#

this is incomplete code, I'm triggering this endpoint with postman

    try {
        const paymentMethod = await stripe.paymentMethods.create({
            type: 'card',
            card: {
                number: '4242424242424242',
                exp_month: 1,
                exp_year: 2023,
                cvc: '314',
            },
        });

        const paymentMethodAttached = await stripe.paymentMethods.attach(paymentMethod.id, {
            customer: customer_id,
        });

        await stripe.customers.update(customer_id, {
            invoice_settings: {
                default_payment_method: paymentMethodAttached.id,
            },
        });

        const charge = await stripe.charges.create({
            amount,
            currency: 'usd',
            source: 'visa',
            description,
        });

        const paymentIntent = await stripe.paymentIntents.create({
            customer: customer_id,
            amount,
            metadata: { type: 'lessons-payment' },
            description,
            currency: 'usd',
            payment_method_types: ['card'],
            capture_method: 'manual',
        });

        const intent = await stripe.paymentIntents.capture(paymentIntent.id, {
            amount_to_capture: amount,
        });

        res.json({ intent });
    } catch (error) {
        res.json({ error });
}
#

not sure of the flow

ember lava
#

jumping in as koopajah had to step away

past oracle
#

🙂

#

okay

ember lava
#

out of curiosity, how are you planning to collect the card details from your customers if you don't have a frontend? Or is that another team/person who is developing that?

past oracle
#

to be fair, this is one of the tasks from stripe certificate program

#

I already did an task that had FE with react element and it was pretty much straight flow

ember lava
#

if i understood the problem correctly, you ran that code snippet above, and you got this error "This PaymentIntent could not be captured because it has a status of requires_payment_method. Only a PaymentIntent with one of the following statuses may be captured: requires_capture."?

past oracle
#

aye

ember lava
#

do you have a request id or PaymentIntent id which you can share with me so that I can take a closer look?

past oracle
#

yeah, I created plenty

#

pi_3KGvIVJwGZkZkKXw01Ty3t0q

#

I never actually charge the payment intent

ember lava
past oracle
#

ok

ember lava
#

the PaymentIntent will not automatically use the PaymentMethod attached to the Customer

#

let me know whether that works

past oracle
#
            "param": "payment_method",
            "type": "invalid_request_error",
#

i set it like this const paymentIntent = await stripe.paymentIntents.create({ customer: customer_id, amount, metadata: { type: 'lessons-payment' }, description, currency: 'usd', payment_method_types: ['card'], capture_method: 'manual', payment_method: [0], });

ember lava
#

[0] isn't valid JS code

#

the [0] which i put in my earlier message was to refer to a link at the bottom

#

a PaymentMethod id would look like pm_1KGr1iJwGZkZkKXw4ryKjIr5

past oracle
#

"payment_method": null,?

#

sorry I'm not getting you

ember lava
#

payment_method: [0] is not valid because payment_method expects a string that looks like e.g. pm_1KGr1iJwGZkZkKXw4ryKjIr5

#

does this make sense so far?

past oracle
#

yes

#

i could use card id

ember lava
#

you would want to use the PaymentMethod id of the card attached to the customer

#

give it a try and let me know how it goes

past oracle
#

'pm_1KGw99JwGZkZkKXwPOAIKoA0'

            type: 'card',
            card: {
                number: '4242424242424242',
                exp_month: 1,
                exp_year: 2023,
                cvc: '314',
            },
        });```
#
            "doc_url": "https://stripe.com/docs/error-codes/payment-intent-unexpected-state",
            "message": "This PaymentIntent could not be captured because it has a status of requires_confirmation. Only a PaymentIntent with one of the following statuses may be captured: requires_capture.",```
#

sorry, but I'm unable to continue, it's 4am, I will get some rest and tomorrow will continue

ember lava
#

sure