#adam-connect

1 messages · Page 1 of 1 (latest)

bright solstice
#

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

#

?

sick storm
#

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

bright solstice
#

what is r when you log it out inside the callback

#

since you are hitting that callback

sick storm
#

Sorry, r is just short of res

bright solstice
#

sure but what is the value of it

#

console.log(r) or breakpoint in "not success" and log out r

sick storm
#

I'm actually not sure

#

Okay

bright solstice
#

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?

sick storm
#

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

bright solstice
#

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

sick storm
#

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?

elfin cradle
#

Hello! Can you share the current version of your backend code?

#

Also, do you want to redirect server-side or client-side?

sick storm
#

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

elfin cradle
#

Okay, so once you get the accountLink client-side you can do something like window.location.href = <ACCOUNT_LINK_HERE> to redirect to it.

sick storm
#

I notice the Response has "redirected:false, status: 200, ..." I'm wondering if its possible to change that to True

elfin cradle
#

You wouldn't want that particular request to redirect though, right? You're sending the Account Link JSON back to your client, correct?

sick storm
#

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

elfin cradle
#

So you do want a server-side redirect specifically? To clarify, either server-side or client-side can be a one button thing.

sick storm
elfin cradle
#

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. 🙂

sick storm
elfin cradle
#

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?

sick storm
#

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?

sick storm
rancid torrent
#

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

sick storm
#

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

rancid torrent
#

And yes,
<a href url="/create-account-hosted"></a>
should work as long as you have the server-side redirect in place

sick storm
# sick storm

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?

rancid torrent
#

Yup!

sick storm
#

Thank you so much! We can archive this if you like, its quite long

rancid torrent
#

👍 sounds good!

#

hope the rest of your integration goes smoothly 🙂

elfin cradle
#

One thing to note is that you'll need to change to app.get if you're using a regular link.

sick storm
#

Its on app.post right now, is that right?

elfin cradle
#

app.post is only for POST method requests, like form submissions or fetch() requests.

#

Yeah.

#

<a> links make GET requests.

sick storm
#

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

sick storm
elfin cradle
#

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?

sick storm
rancid torrent
#

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

elfin cradle
#

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>

sick storm
sick storm
rancid torrent
#

Sorry I missed these follow-ups! Are you in a good state @sick storm ?

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?

rancid torrent
#

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!

sick storm
#

I feel like it should be a Stripe Link

mellow hemlock
#

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">

sick storm
#

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

mellow hemlock
#

Hello Adam, I was wondering if you could provide us with the specific code on your frontend to allow further inspection please?