#adam-fundflows

1 messages ยท Page 1 of 1 (latest)

karmic harness
#

hello again!
what do you mean by that? like I understand your question, it doesn't make sense in context to the code shared

zinc steppe
#

Hello ๐Ÿ‘‹, I do see that the payment_intent.succeeded has the client_secret field, and it also has the charges field so I can pass the chargeID to the Transfers

#

So im just reading up on how to make the chargeID "passable" to the Transfer functions below this

#

This is all what happens when you press the "Purchase" button so far. ```js
app.post("/payments/create", async (req, res) => {
try {
const { amount, shipping, vendors } = req.body;
const paymentIntent = await stripe.paymentIntents.create({
shipping,
amount,
currency: "usd",
payment_method_types: ['card'],
});
res.status(200).send(paymentIntent.client_secret);
// How do we get paymentIntent succeeded so that we can
// grab the charge from it?
for (const [vendorId, value] of Object.entries(vendors)) {
const transfer = await stripe.transfers.create({
amount: value,
currency: 'usd',
destination: vendorId,
source_transaction: "CHARGEID",
});
}
} catch (err) {
res.status(500).json({
statusCode: 500,
message: err.message,
});
}
});

karmic harness
#

so yeah to reword what you are saying, yes when you get a PaymentIntent event (for a successful PI), you can then create a Transfer in your code. You have the full PaymentIntent there with a Charge ID on it

zinc steppe
karmic harness
#

a colleague is stepping in, they'll catch up

#

do you have a new question?

zinc steppe
#

Sorry if im being difficult!! 4242underline

umbral hemlock
#

source_transaction: {{CHARGE_ID}} is one way to tie a transfer back to a charge, but it will also tie the transfer to the availability of the funds on the original charge. As an example, if you have Charge A that will be available in two days, you can still immediately make the transfer with source_transaction: {{CHARGE A}} but the funds won't be available in the connect account until the original charge is available

#

If you JUST want to tie a transfer to a charge (without tying it to availability) you can use transfer_group instead

zinc steppe
#

Okay, we're not too sure about this flow. I just referred to this previous thread

#

Ideally we would probably delay Transfers by a week anyway soo..

umbral hemlock
#

Sorry if I wasn't clear - if I were you, I'd just use source_transaction so you don't have to float the funds as koopajah mentioned, but if your goal is JUST to tie the charge to the transfer then there are other ways to do that (transfer_group)

zinc steppe
#

I just tried this code so far, and this is a pi_3K2K9AHBsyfQ9rBx00nKeMI3 I think payment did not go through?

umbral hemlock
#

Sorry, I completely missed this follow up message looking now!

#

You never provided any payment information or tried to confirm it, so payment hasn't been attempted yet

zinc steppe
#

This can be archived, I just found the payment and Transfer wont go thru because, Confirming paymentIntent needs to happen before doing Transfers

#

Ill try to make a youtube video on this later

indigo nacelle
#

Sounds good! If you need anything else just let us know!

zinc steppe
#

Hi Rubeus, well haha, is it possible for me to await confirmCardPayment so that I can make transfers in the SAME api call?

umbral hemlock
#

๐Ÿ‘‹ Stepping back in!

zinc steppe
#

Hi Karbi! ๐Ÿ‘‹ Actually I dont think backend app.post(/payments/create" can wait for another Frontend function to confirm this

umbral hemlock
#

Yeah, was just about to say - the only way to do the transfer in the same API call as confirmation is to use destination charges (while will do the transfer for you)

zinc steppe
#

Is it possible to grab ChargeID in the frontend to send to another backend api call to do the transfers? Is that retrieve paymentIntent? or retrieving the payment_intent.succeeded event?

umbral hemlock
#

You should get back a Payment Intent if stripe.confirmCardPayment is successful, so you can pull the ID out from there

#

You could also choose to do it upon receiving the payment_intent.succeeded event

zinc steppe
umbral hemlock
#

Yes, stripe.confirmCardPayment should resolve to a PaymentIntent

zinc steppe
#

So maybe I dont need to send another POST req from Front to Back??

umbral hemlock
#

No, if you're confirming client side you shouldnn 't need another confirmation request server-side

zinc steppe
#

So I just console.logged this

#

However it didnt return a Charge

#

How could I retrieve the charge.succeeded object from Stripe? This is what I see on Dashboard

umbral hemlock
#

Let's back up for a minute

#

It's my fault I forgot you needed the Charge ID and not the Payment Intent ID since you want to populate source_transaction on the Transfer. You won't be able to get the Charge ID from the front-end confirmation request

zinc steppe
#

Hey no worries im still learning, and there's a lot of info flying around here

umbral hemlock
#

and so taking a step back, if your goal is just to make the transfer as soon as payment is complete, I'd suggest you just listen for the payment_intent.succeeded or charge.succeeded event and make the transfer upon receiving it

zinc steppe
#

Could I just do confirmPayment instead of confirmCardPayment? I am actually unsure of the purpose behind either, I just want the ChargeID. Im referring to stripeJS docs

karmic harness
#

I'm around now

#

and hello again

#

you use confirmCardPayment() with CardElement
and confirmPayment() with PaymentElement

#

but wait

#

if you want the Charge ID, why are you digging into Stripe.js docs

#

you already have the Charge ID

zinc steppe
#

Oh okay, the only reason why Im doing these, yes ChargeID

karmic harness
#

it is in your webhook event

zinc steppe
#

Wait I dont have a webhook i dont think

#

I see the ChargeID in the pay_int_succ but I need to grab it either from frontend or backend I think

#

Or the charge.succeeded

karmic harness
#

yeah so let's start here

#

since you're jumping a bit ahead

#

how do you make a PaymentIntent into status: succeeded in your code?

I saw your code comment

    // How do we get paymentIntent succeeded so that we can
    // grab the charge from it?  
#

but you have a payment_intent.succeeded webhook event, so are you able to make PaymentIntents succeed?

zinc steppe
karmic harness
#

no I mean

#

what in your code is causing it to go into status: succeeded

zinc steppe
#

I think its the res.status....

karmic harness
#

that creates a PaymentIntent in status: requires_payment_method

#

so somewhere else you are "confirming" the PaymentIntent

#

where is that

#

it would be in your client-side code

#

where-ever you are calling your /payments/create endpoint from

zinc steppe
#

Then maybe its stripe.createPaymentMethod or stripe.confirmCardPayment

#
 .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(({ paymentIntent }) => {
#

Wait

karmic harness
#

so there

#

you are calling confirmCardPayment()

#

which you said you don't

#

but great news! you are!

#

which is the right thing to do

#

so that answers your question of "how do I make a PaymentIntent go into successful"

you confirm it with confirmCardPayment() which you are using

zinc steppe
#

Hold on

karmic harness
#

nope, a webhook event is Stripe sending a request to your server

where-as mostly you are sending requests to Stripe's servers

zinc steppe
#

Wait so then I just need to see if I can grab the ChargeID from the frontend here

#

or maybe since Stripe is the one that creates the event I think, maybe I need to retrieve it in another API call

karmic harness
#

you cannot grab the Charge ID from the frontend

Option 1
on the frontend you have a PaymentIntent ID

send that to your server, in your server, fetch the PaymentIntent object and that will contain the Charge ID

Option 2
implement webhooks, Stripe sends a request to your webhook endpoint with the full PaymentIntent object

zinc steppe
#

stepping away for a moment

karmic harness
#

stepping away but a colleague is catching up!

indigo nacelle
#

Hello again! I'm here if you have further questions!

zinc steppe
#

๐Ÿ‘‹ Good evening, there is something wrong with this since I got 404```js
app.get(/payment_intents/${paymentIntent.id}/capture, async (req, res) => {
res.status(200).send(charges.id);
});

#

Checking my dashboard now

indigo nacelle
#

If you need help figuring out what went wrong give me the request ID and I'll take a look.

zinc steppe
#

This is the payment intent ID, which went thru, pi_3K2OyzHBsyfQ9rBx0vJU3aXj

#

But actually I wont see my /payment_intent/id/capture in the dashboard

indigo nacelle
#

Make sure you adjust the filter to show GET requests.

#

Is Connect involved? Are you trying to fetch the Payment Intent from the wrong account?

zinc steppe
#

This is what Im passing in on Clientside ```js
.then(({ paymentIntent }) => {
console.log(paymentIntent.id)
apiInstance.get(/payment_intents/${paymentIntent.id}/capture)
.then((response) => {

zinc steppe
indigo nacelle
#

Did you find the request ID showing the 404?

zinc steppe
#

Looking through now

#

https://us-central1-ourcompany-5fa49.cloudfunctions.net/api/payment_intents/pi_3K2OyzHBsyfQ9rBx0vJU3aXj/capture

#

It looks like it sent the right paymentintentID (i think) which im happy about

#

But it was still 404

indigo nacelle
#

Is the 404 coming from your server or from the Stripe API?

zinc steppe
#

Oh wait my firebase functions backend deploy failed. This is my error ReferenceError: paymentIntent is not defined

indigo nacelle
#

Do you have a request ID showing that error?

zinc steppe
indigo nacelle
zinc steppe
#

Im actually trying to work out where to put this code at the moment, Im trying serverside

#

But Im pretty sure console.logs go on the clientside 100% of the time

#

Wait

indigo nacelle
#

Sorry, hang on, I think I might be confused about what's going on. Can you describe the entire flow of both your front end and back end code and where it's failing?

zinc steppe
#

When I get the GET 404 in the console, its from xhr.js:177, does xhrmean its not in my code?

#

Anyways 1) I think my backend endpoint is not recieving our GET request from Clientside

indigo nacelle
#

Is this somewhere where I can access it and see the error myself?

zinc steppe
#

Okay so I tried plugging in the Hard coded pi_3K2OyzHBsyfQ9rBx0vJU3aXj into the paymentintents/capture call on Both sides

#

And I got

indigo nacelle
#

Okay, so you've got a CORS error and a 500 from your server. Seems like stuff you need to debug on your end not directly related to Stripe.

zinc steppe
#

But what would make this GET request different from any other ones we have?

#

Only the fact that the paymentintent.id will be dynamic each request in order to capture ChargeID for the transfers

indigo nacelle
#

Can you give me an example of a GET request that succeeded?

#

Like, can you show me the code that's making a successful GET request and the code that's making the GET requests that are failing?

zinc steppe
#

Going to Stripe Onboarding works```js
app.get("/create-account-hosted", async (req, res) => {
var account = await stripe.accounts.create({
type: "express"
})
var accountLink = await stripe.accountLinks.create({
account: account.id,
success_url: "https://example.com",
failure_url: "https://example.com",
type: "account_onboarding",
});
res.send(accountLink.url)
})

indigo nacelle
#

Can you share the frontend code you use that accesses that URL? The code making that GET request?

zinc steppe
#

This is the frontend for that```js
const CreateAccount = async (response) => {
present("Going to Stripe Connect Signup...", 4000);
fetch(
"https://us-central1-mallshop-5fa49.cloudfunctions.net/api/create-account-hosted"
).then((response) => {
if (response.ok){
return response.json();
} else {
throw new Error('BAD HTTP REQ')
}
})
.then((jsonData) => {
console.log(jsonData);
console.log(jsonData.account.id);
window.location.href = jsonData;

    }).catch ((err) =>{
        console.log('error', err.message)
    })
indigo nacelle
#

Okay, cool, now show me the frontend code that's throwing the CORS error.

zinc steppe
#
        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(({ paymentIntent }) => {
                                console.log(paymentIntent.id)
                                apiInstance.get(`/payment_intents/pi_3K2OyzHBsyfQ9rBx0vJU3aXj/capture`)
                                .then((response) => {
                                    if (response.ok){
                                        return response.json();

                                      } else {
                                        throw new Error('BAD HTTP REQ')
                                      }
                                }).then((jsonData) => {
                                    console.log(jsonData);

                                }).catch ((err) =>{
                                    console.log('error', err.message)
                                })
                            })
indigo nacelle
#

What is apiInstance?

zinc steppe
#

Maybe its because I need to try fetch instead. export const apiInstance = axios.create({baseURL: 'https://us-central1-ourcompany-5fa49.cloudfunctions.net/api'});

indigo nacelle
#

Yeah, try fetch. I'm not very familiar with Axios, but it seems to be doing something wonky.

zinc steppe
zinc steppe
#

I think we're getting error Unexpected token < in JSON at position 0 , I think there are other threads I can check for this

indigo nacelle
zinc steppe
#

Thanks for all the help sorry for the trouble, I think I'll have a few things to try from all this!