#adamerrinwright-retrieve-paymentintent

1 messages · Page 1 of 1 (latest)

young mica
#

@livid ridge What are you really trying to do? Why do you need to retrieve a PI client-side from a charge, i don't really grasp the question

young mica
#

@livid ridge any more details?

livid ridge
young mica
#

yeah that's not how it works really

livid ridge
#

This is my flow so far ```js
apiInstance.post("/payments/create", {
amount: total * 100,
shipping: {
name: recipientName,
address: {
...shippingAddress,
},
},
vendors: sellers
})

        .then(({ data: clientSecret }) => {
            stripe.createPaymentMethod({
                    type: "card",
                    card: cardElement,
                    billing_details: {
                        name: nameOnCard,
                        address: {
                            ...billingAddress,
                        },
                    },
                })
                
                .then(({ paymentMethod }) => {
                    stripe.confirmCardPayment(clientSecret, {
                            payment_method: paymentMethod.id,
                            receipt_email: email, // Check if email is going thru.
                        })
                        .then(({ data: clientSecret}) => {
                            // console.log(paymentIntent)
                            stripe
                            .retrievePaymentIntent({clientSecret})
                            .then((result) => {
                                if (result){
                                    return result;

                                  } else {
                                    throw new Error('BAD HTTP REQ')
                                  }
young mica
#

stripe.retrievePaymentIntent is client-side, this is definitely not where you would do any of this

livid ridge
#

Sorry I meant Capture const paymentIntent = await stripe.paymentIntents.capture(

young mica
#

then you don't need a Charge id either, you just need to call this server-side and that takes the PaymentIntent id as the first parameter, the pi_123

livid ridge
#

Okay, so I cant capture a PaymentIntent.chargeID with StripeJS's retrievePaymentIntent or confirmCardPayment?

lean flower
#

Hello! I'm taking over for @young mica, let me catch up... 🙂

#

To clarify, you're trying to capture a Charge client side that's already been authorized? As in you're placing a hold on funds and capturing them later?

livid ridge
#

So that I can do stripe.retrievePaymentIntent(paymentIntentSuccessID) something like that

lean flower
livid ridge
#

Ive never played with this setting let me check... No its on Automatic

lean flower
#

Okay, so you're not placing a hold on funds. I'm not sure I understand what you're trying to do. Can you provide more details?

livid ridge
lean flower
#

But you're trying to get the Charge ID client-side?

livid ridge
#

Well since this StripeJS stripe.confirmCardPayment(clientSecret, {... performs a POST req

#

I thought that I should also be able to take this StripeJS code stripe.retrievePaymentIntent(clientSecret) to perform another Req for the payment_intent.succeeded object

#

Because with this Return it looks like I could retrieve the ChargeID through that

lean flower
#

But why?

#

I don't understand why you want to do this client-side.

livid ridge
lean flower
#

Sorry, I mean, what are you doing to do with the Charge ID client-side once you have it?

livid ridge
lean flower
#

You mentioned something about Transfers, but that doesn't make sense to me as you can't create a Transfer or do anything with them client-side.

#

You should not capture Payment Intents server-side unless the customer is not present and you're doing an off-session transaction.

livid ridge
lean flower
#

Why not send the Payment Intent ID to your server-side code instead and then get the Charge ID server-side before creating the Transfer?

livid ridge
lean flower
#

I do not recommend that flow. You should only deal with the Payment Intent client-side and do the rest server-side.

livid ridge
livid ridge
lean flower
#

It's basically the code you shared above, but instead of passing the Charge ID to your /v1/transfers endpoint you transfer the Payment Intent ID. Then, server-side, you fetch the Payment Intent using that ID, grab the Charge ID from the result, and create a Transfer with it.

livid ridge
#

Trying this now

livid ridge
#

So Im trying to wait for the confirmCardPayment to return the paymentIntentID so I can pass it to the fetch(/pintents/pi_qh29cnr8qfqv8nv/capturel

#

I feel like I already did this yesterday, hold on let me work on this

onyx sky
#

hello again @livid ridge

#

I'm on here

#

looks like you have next steps

livid ridge
#

Hello, its getting cold out there, yes currently trying things

livid ridge
#

When you retrieve the PaymentIntent object from the confirmCardPayment is it possible to wait for it to succeed so that the Charge.id will be in the JSON?

onyx sky
#

no

#

you don't get the Charges array back in the client-side retrueve

#

as we explained, you ahve to fetch it server-side

young mica
#

you don't event need the charge id at all to capture anything

young mica
#

@livid ridge are you unblocked

livid ridge
#

So now I believe Im getting a CORS error for sending Frontend from my Localhost

#

Current Frontend code```js
.then(({ paymentMethod }) => {
stripe.confirmCardPayment(clientSecret, {
payment_method: paymentMethod.id,
receipt_email: email, // Check if email is going thru. It is in the field.
})
.then(({ paymentIntent }) => {
fetch(https://us-central1-ourcompany-5fa49.cloudfunctions.net/api/payment_intents/${paymentIntent.id}/capture, {
}) .then(res => res.text()) // convert to plain text
.then(text => console.log(text))

#

current Backend code ```js
app.get("/payment_intents/:id/capture", async (req, res) => {
const id = req.params.id; // <-- as simple as that
console.log(res)
res.send(paymentIntent);
});

#

Im gonna try on Live site to see if i can get past CORS error, then I guess Ill try something else if that doesnt work

young mica
#

yeah you seem to post to a different domain than you're on

#

this is more a normal/basic JS error, it's not Stripe related

livid ridge
#

Thanks for the help rubeus, koopajah, and hmunoz, I'll keep checking this out!