#adam-transfer-info

1 messages · Page 1 of 1 (latest)

night roost
#

@livid horizon You likely always want source_transaction so that you don't have to float the funds

livid horizon
#

Okay, does it matter if your Transfers are in a transfer group or not?

#

Currently, each purchase a customer makes will result in different transaction IDs

night roost
#

if you use source_transaction it's enough

livid horizon
#

Okay, do you think its possible to listen to CHARGE ID after confirmCardPayment?

night roost
#

charge id is something you would get server-side instead

livid horizon
#

Okay, it just looks like the confirmCardPayment happens first, and then Stripe creates a chargeID and the Succeeded for the Payment

night roost
#

it all happens together really, those are screenshots of events, which are separate and don't matter in your case

livid horizon
#

Okay, im just trying to get an idea of what it even looks like, to grab the chargeID, Serverside

#

Looks like Discord Search is down, Ill look for what others have done later

night roost
#

You would be better off just trying yourself it takes 30s to confirm a card payment and then look at it server-side

livid horizon
#

Okay Im assuming I can grab the ChargeID at some timepoint after this Payment?

#

Bc the PaymentIntent needs to happen before ConfirmingCardPayment, so Im not sure how to wait for the ChargeID to come thru

night roost
#

that is the PI creation

#

but yes, after the confirmation you can

livid horizon
#

Then after ConfirmCradParyment, I do the transfer

night roost
#

Please don't share pictures of code, as a dev, we want real text code we can copy paste

#

But step 1 here is to try on your end as the developer. It's really easy to just look at the PI after confirmation server-side and look at the object

livid horizon
#

And for discord search ```js
app.post("/transfers", async (req, res) => {
const { sellers } = req.body;
const transfers = Object.entries(sellers).map(([vendorId, cut]) => {
const transfer = stripe.transfers.create({
amount: cut * 100,
currency: 'usd',
destination: vendorId,
});
return transfer;
});
res.json(transfers)
}
)

night roost
#

you'll see there's a charges collection with the charge id right in it

livid horizon
#

In the transfers, I dont think I can grab information from Stripe,

#

I would have to do res.send(paymentIntent.chargeID or something

night roost
#

not really no

#

you would have to retrieve the PaymentIntent to then get the info you need

#

you can't trust client-side data like that

livid horizon
#

Okay so I think that means a separate endpoint for retrieving the PI

night roost
#

no it doesn't

#

it means adding more code before stripe.transfers.create()

livid horizon
#

Okay let me see

thorny forum
#

Hey Adam, I'm going to take over for @night roost, getting caught up now. Looks like you're still trying to get the Charge ID for the Transfer on your server?

livid horizon
#

Hi yes, I thought the only way for me to get info from an endpoint was res.send

night roost
#

yeah I worry you're a bit lost/confused about client/server back and forth

#

this is really not Stripe related at this point and so in those endpoints you control the whole code. IF you wanted to do more API requests, save data in your database, etc. you can (and should)

#

You also need to make sure your transfer creation logic isn't just a POST request like this. What if the customer closes their tab after paying but before you've done this code? Usually you have a webhook handler to do this for you. So you listen to payment_intent.succeeded which would have the PaymentIntent info, including the charge id, and then you can create the Transfer(s) you need

#

if you do this in an app.post() to me it means it can only happen from the client which is dangerous

livid horizon
#

I cant just make a const of charges.data and pull it out of nowhere as far as I know```js
app.post("/transfers", async (req, res) => {
const { sellers, charges } = req.body;
const piChargeID = charges.data
const transfers = Object.entries(sellers).map(([vendorId, cut]) => {
const transfer = stripe.transfers.create({
amount: cut * 100,
currency: 'usd',
destination: vendorId,
source_transaction: piChargeID
});
return transfer;
});
res.json(transfers)
}
)

night roost
#

yeah absolutely not

#

you're mixing everything up

#

you seem set on always having to go back to your client, that's not how you integrate the majority of your code

#

You really should not do something, go back to the client, send things to another app.post, then go back to the client, etc.

#

That's not really how a normal integration works unfortunately

#

So when I said "listen to PI succeeded" what I mean is writing a webhook handler. Something that happens async, without any browser action at all.

livid horizon
#

Thats just my current knowledge on how to bring data into another endpoint, perhaps next() is something i can look into

night roost
#

not sure what .next() has to do with it

#

Have you used await before?

livid horizon
night roost
#

Seems like what's blocking you, you do everything in some async flow.
You want to have sequential code that will do things such as retrieve the PaymentIntent => extract the Charge id => Create a transfer

livid horizon
#

Ill look into adding this under my /payments/create endpoint```js
res.status(200).send(paymentIntent.client_secret);
// await PI SUCCEEDED
// Then somehow send this data to /transfers

night roost
#

eyah you really need to take a complete step back from those endpoints, this is not at all how you should build your code unfortunately

#

I'm not sure how to explain this differently unfortunately 😦
Is there someone else on your team or at your company that could pair with you for a few hours to explain all of this?

livid horizon
#

Let me just step away on this