#adam-connect
1 messages · Page 1 of 1 (latest)
hello, pasting your code into thread too
return fetch("/create-account-hosted", {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
// body: JSON.stringify(Object.fromEntries(fd)),
}).then(function (r) {
if (r.ok) {
console.log("success")
} else {
console.log("not success")
}
// return r.json();
})
.then(function (response) {
JSON.stringify(response, null, 2);
<h2>
{accountLink}
</h2>
});
}
you're making a request to your own backend server right
?
Yes I have an endpoint index.js file that goes to firebase functions
When i use postman on the endpoint, it works and returns the accountLink object with a url to the Stripe questionnaire
what is r when you log it out inside the callback
since you are hitting that callback
Sorry, r is just short of res
sure but what is the value of it
console.log(r) or breakpoint in "not success" and log out r
yeah I'm helping you help yourself
like you know your request is failing
and trying to piece together what you get back from your fetch
second
is it because I don't have a body?
unlikely but depends on your backend and what your endpoint expects. Does your Postman request include a body/params?
and does your endpoint expect body params?
Endpoint does not expect body params, I just want the frontend to act like a simple button to open the accountLink signup page
My postman is just a blank POST to the endpoint
got it, so you should a/ add logs to your server and make sure you're hitting that endpoint, before you create any account etc
and b/ log out what your client-side code is hitting in r and work up from there
I found that removing method: 'POST', made the r go thru
Thank you, now im just trying to get the frontend to get the AccountLink so that the user can be redirected to the Stripe Express questionnaire
I can't return the url from the accountLink response. I'd like the user to be redirected to the Stripe Express/Standard questionnaire. Do you suggest returning the accountLink's url a different way in order for the user to get Redirected?
Hello! Can you share the current version of your backend code?
Also, do you want to redirect server-side or client-side?
Hi Rubeus thank you no rush, I'd just like the User to be redirected to the Stripe Standard/express questionnaire. Not sure if I need server/client-side
Okay, so once you get the accountLink client-side you can do something like window.location.href = <ACCOUNT_LINK_HERE> to redirect to it.
Ah so a link will pop up on the screen/DOM?
I notice the Response has "redirected:false, status: 200, ..." I'm wondering if its possible to change that to True
You wouldn't want that particular request to redirect though, right? You're sending the Account Link JSON back to your client, correct?
Yes it would be nice if the request could redirect via the link retrieved, because I just have 1 button to start the process
Imagine pressing the Amazon Seller signup button, and it redirects you to Stripe Standard questionnaire, that is the exact UX we'd like
So you do want a server-side redirect specifically? To clarify, either server-side or client-side can be a one button thing.
Thank you, whichever one will get the user to the Stripe Connect Standard screen,
Okay, so you can either return a redirect response from your server code and then, in your client side code, instead of using fetch() to get the URL you would change the button into a link that points directly to that URL.
Or, alternatively, you can return JSON from your server, use fetch() to get that JSON, pull out the URL, and use window.location.href to send the user to that URL.
Either way will work fine, it's up to you. 🙂
Wait but I need the fetch() in client side to talk to the server side endpoint right?
Not if you're doing a server-side redirect.
If your server returns a redirect response that points to the new URL you only need to link to that URL and the browser goes to the URL specified.
You can do something like <a href="http://example.com/url/that/redirects/to/connect/onboarding">Connect Onboarding</a> and then that URL on your server can redirect the browser directly to Connect Onboarding/the Account Link.
Does that make sense?
Yes thank you! I will try this now thank you. Does that mean I don’t need any fetch requests on the Button’s function?
And while I read up on how to do this in code, would you happen to have an example(s) of how others have done this?
Oh so you can actually point to a Server Endpoint just with an <a href url="/create-account-hosted"></a>?
Catching up since @elfin cradle had to leave - give me a minute
"Yes thank you! I will try this now thank you. Does that mean I don’t need any fetch requests on the Button’s function?"
Yup, if you're doing the server-side redirect you shouldn't need to do a fetch request
No worries thank you, the goal is just to make the Stripe Onboarding Standard/express/custom button redirect to the Stripe questionnaire from the AccountLink
And yes,
<a href url="/create-account-hosted"></a>
should work as long as you have the server-side redirect in place
Just to click this button, and the user be brought to the Onboarding,
Okay so instead of doing res.send(accountLink), I should have some sort of redirect function?
Yup!
Thank you so much! We can archive this if you like, its quite long
One thing to note is that you'll need to change to app.get if you're using a regular link.
Its on app.post right now, is that right?
app.post is only for POST method requests, like form submissions or fetch() requests.
Yeah.
<a> links make GET requests.
Oh so change the endpoint to GET
Is it possible to pass in the firebase currentUser.id of the user into the server side code?
That would be the only field we'd need to pass in, so that we know which vendors to refer to with their bank info payouts
Is this only for HTML/JS? I see here that CJ was able to make the method POST, but he's using Ruby
CJ is using a <form> with method="POST" which will create a POST request.
@rancid torrent do you know the answer to the Firebase question above?
Okay, but otherwise if i'm not passing a "body" or any fields, we can just use "a href"?
I'm in the dark on the firebase question - I'd suggest doing some searching for the best way to find the currentUser.id so then you can pass it along
Yeah, if you're not passing any data to the server you can use an anchor element (<a>).
Or you can pass data in the URL, like this: <a href="https://example.com/some/url?foo=bar&baz=whatnot">Link</a>
I can maybe pass in currentUser.id thru redux, or just thru the Firebase utils by importing firebase.auth. I just need to check if it will actually pass into a server side Post request
Actually whether or not we need to do this to have Payouts working automatically just depends on how our data archiitecture is right? I'll have to check on that
Sorry I missed these follow-ups! Are you in a good state @sick storm ?
Hi karbi no worries they're general. I still haven't gotten the redirect to work
app.get("/create-account-hosted", async (req, res) => {
const data = req.body;
console.log(res + " Yes")
try {
var account = await stripe.accounts.create({
type: "custom",
requested_capabilities: ["card_payments", "transfers"],
business_type: 'company',
})
var accountLink = await stripe.accountLinks.create({
account: account.id,
success_url: "https://example.com",
failure_url: "https://example.com",
type: "custom_account_verification",
collect: "eventually_due",
});
} catch (err) {
console.log(err);
res.status(400);
res.send({ error: err });
return;
}
res.send(accountLink)
res.redirect(accountLink.url)
})
Do you think this is the right way to redirect the user to the accountLink url for Stripe Standard/Custom onboarding?
I'd remove the res.send line entirely - you shouldn't need it
I need to head out but @mellow hemlock should be able to help you!
Thank you! I dont think the top address bar should be http://localhost:8100/create-account-hosted
I feel like it should be a Stripe Link
Hi there, the URL you shared indicates the /create-account-hosted endpoint is being called. The common issue for this scenario is you are making an API call to the incorrect endpoint.
Do you mind checking the port number your server is listening to? Would you mind verifying it is 8100 please?
It's likely you have defined within your form a relative URL path, e.g.
<form action="/create-account-hosted" method="POST">
One potential solution is to have define an absolute path, such as
<form action="http://localhost:8100/create-account-hosted" method="POST">
Hi Makoto thank you, the Server side endpoint is listening to Firebase since its a firebase function. Via this code ```
const functions = require("firebase-functions");
exports.api = functions.https.onRequest(app);
When I use postman to call the endpoint /create-account-hosted, i get the response shown in the screenshot
I get a url that leads to the Stripe connect signup, but I havent figured out what the frontend/backend code needs to look like for the redirect to the Signup
Hello Adam, I was wondering if you could provide us with the specific code on your frontend to allow further inspection please?