#adam-transfer-info
1 messages · Page 1 of 1 (latest)
@livid horizon You likely always want source_transaction so that you don't have to float the funds
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
if you use source_transaction it's enough
Okay, do you think its possible to listen to CHARGE ID after confirmCardPayment?
charge id is something you would get server-side instead
Okay, it just looks like the confirmCardPayment happens first, and then Stripe creates a chargeID and the Succeeded for the Payment
it all happens together really, those are screenshots of events, which are separate and don't matter in your case
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
You would be better off just trying yourself it takes 30s to confirm a card payment and then look at it server-side
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
Then after ConfirmCradParyment, I do the transfer
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
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)
}
)
you'll see there's a charges collection with the charge id right in it
it's also documented https://stripe.com/docs/api/payment_intents/object#payment_intent_object-charges
In the transfers, I dont think I can grab information from Stripe,
I would have to do res.send(paymentIntent.chargeID or something
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
I think at our Payment stage, we cant get the ChargeID yet from the res.send because it hasnt been confirmed yet by confirmCardPayment
Okay so I think that means a separate endpoint for retrieving the PI
Okay let me see
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?
Hi yes, I thought the only way for me to get info from an endpoint was res.send
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
We'll keep this in mind, when you say "listen to PI succeeded" this tells me I need another endpoint to get the charges.object, so I can pass to client, which lets me pass to Transfers
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)
}
)
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.
Thats just my current knowledge on how to bring data into another endpoint, perhaps next() is something i can look into
It looked like you could do another res when you use next. Yes await was probs going to be my next choice
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
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
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?
So perhaps I can just place this all under 1 endpoint, and do confirmCardPayment ServerSide, or everything Serverside for that matter
Let me just step away on this