#adam-fundflows
1 messages ยท Page 1 of 1 (latest)
hello again!
what do you mean by that? like I understand your question, it doesn't make sense in context to the code shared
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,
});
}
});
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
oops sorry I was reading up on @lyric zealot 's thread on ChargeIDs
I'm just wondering if source_transaction: paymentIntent.charges.id, is the right way to pass this in, do you suggest testing this in Test Mode?
Sorry if im being difficult!! 
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
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..
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)
Okay sorry gotcha, we'll probs stick with source_transaction.
I just tried this code so far, and this is a pi_3K2K9AHBsyfQ9rBx00nKeMI3 I think payment did not go through?
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
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
Sounds good! If you need anything else just let us know!
Hi Rubeus, well haha, is it possible for me to await confirmCardPayment so that I can make transfers in the SAME api call?
๐ Stepping back in!
Hi Karbi! ๐ Actually I dont think backend app.post(/payments/create" can wait for another Frontend function to confirm this
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)
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?
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
Yes I should "get back a Payment Intent if stripe.confirmCardPayment is successful", but can I do that from the Frontend?
Yes, stripe.confirmCardPayment should resolve to a PaymentIntent
So maybe I dont need to send another POST req from Front to Back??
No, if you're confirming client side you shouldnn 't need another confirmation request server-side
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
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
Hey no worries im still learning, and there's a lot of info flying around here
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
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
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
Oh okay, the only reason why Im doing these, yes ChargeID
it is in your webhook event
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
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?
Yes this is the part where it succeeds I believe
I think its the res.status....
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
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
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
Hold on
nope, a webhook event is Stripe sending a request to your server
where-as mostly you are sending requests to Stripe's servers
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
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
I think im currently working on the code for Option 1
stepping away for a moment
stepping away but a colleague is catching up!
Hello again! I'm here if you have further questions!
๐ 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
If you need help figuring out what went wrong give me the request ID and I'll take a look.
This is the payment intent ID, which went thru, pi_3K2OyzHBsyfQ9rBx0vJU3aXj
But actually I wont see my /payment_intent/id/capture in the dashboard
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?
This is what Im passing in on Clientside ```js
.then(({ paymentIntent }) => {
console.log(paymentIntent.id)
apiInstance.get(/payment_intents/${paymentIntent.id}/capture)
.then((response) => {
Well so Im trying to retrieve the ChargeID from the Paymentintent succeeded, so I can use for Transfers
Did you find the request ID showing the 404?
In the chrome Devtools?
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
Is the 404 coming from your server or from the Stripe API?
Oh wait my firebase functions backend deploy failed. This is my error ReferenceError: paymentIntent is not defined
Do you have a request ID showing that error?
Apologies I need to figure out how to get this from the Network tab or elsewhere
You can get it in your code and log it: https://stripe.com/docs/api/request_ids#request_ids
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
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?
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
Is this somewhere where I can access it and see the error myself?
Okay so I tried plugging in the Hard coded pi_3K2OyzHBsyfQ9rBx0vJU3aXj into the paymentintents/capture call on Both sides
And I got
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.
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
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?
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)
})
Can you share the frontend code you use that accesses that URL? The code making that GET request?
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)
})
Okay, cool, now show me the frontend code that's throwing the CORS error.
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)
})
})
What is apiInstance?
Maybe its because I need to try fetch instead. export const apiInstance = axios.create({baseURL: 'https://us-central1-ourcompany-5fa49.cloudfunctions.net/api'});
Yeah, try fetch. I'm not very familiar with Axios, but it seems to be doing something wonky.
Sorry in the huge codechunk I just updated that it is apiInstance.get('/payment....)
Trying now..
I think we're getting error Unexpected token < in JSON at position 0 , I think there are other threads I can check for this
We actually have a support document that will help with that error: https://support.stripe.com/questions/how-to-fix-syntaxerror-unexpected-token-in-json-at-position-0
Thanks for all the help sorry for the trouble, I think I'll have a few things to try from all this!