#SammySprinkler - refresh_url
1 messages · Page 1 of 1 (latest)
Hello
Okay so let's break this down a bit.
The refresh URL is a redirect back to your server to re-generate an AccountLink. This is because they expire if they've already been used or the lifetime has elapsed
So you need to send the user back to your site, call a function to regenerate the accountLink, and then redirect them to that.
So with generating the AccountLink, I have to provide a refresh_link which will generate another account link essentially being an infinite loop but it isn't because it only runs upon an experation event
Well you want to allow your onboarding users a way to get a new AccountLink if the one they have is expired. It doesn't have to be an automatic redirect, you could use a button or some other piece of UI if you want.
I believe I understand exactly what needs to be done but am a bit inexperienced and you may not be able to help my specific case. But I am using cloud functions for my endpoints and since I must pass in a Url for the refresh_url and can't just pass in my cloud function to generate a new url. Is there a way for me to pass parameters inside my url to my cloud function? May just be simple syntax I don't know
Ah, I'm not sure how you would handle that with cloud functions.
So can your users just send a POST request to the cloud function endpoint and receive a new accountLink URL?
Yes they can but how do I pass that into the refresh_url parameter when the cloud function being called is already the one they're inside so I can't create an accountLink and then somehow go back and pass that link as the refresh_url into the alrerady created link
Hmmm I'm a bit confused by what you're asking too, really sorry. Why would you pass a link into refresh_url it doesn't make sense to me
Every time you send an account to the onboarding page you create an AccountLink where you set success_url and refresh_url to URLs that make sense for your integration, the former is where you process the user landing after successfully setting all of their details and the latter is where you process the user coming back and needing a brand new AccountLink (which would be the same operation as the first one)
Its no problem, I just really appreciate the help and this is mainly my incorrect understanding but I thought the refresh_url expected to be given a url
yes, that parameter expects a URL, the same as success_url
I think my issue is the url returns a json with the refresh url and the status but I can't seem to grab that url while setting the refresh url
I'm really sorry, I... don't understand what that means at all right now
can you share some exact code? That might help
can you share a non picture of the code?
exports.stripeGetAccountLink = functions.https.onRequest( async (req, res) =>{
const accountLink = await stripe.accountLinks.create({
account: "acct_1KGr2lRBqHE8Zf27",
refresh_url: "https://us-central1-the-stride-app-7eda9.cloudfunctions.net/stripeGetAccountLink",
return_url: "https://thestrideapp.page.link/pleasework",
type: "account_onboarding",
},
function (err, accountLink) {
if(err!= null) {
res.json({
status: "fail"
})
console.log(err);
}
else {
res.json({
accountUrl: accountLink.url,
status: "success",
})
console.log("Successfully created new account");
}
}
)
})
(sorry to be annoying, you can wrap code in three ` before and after to make it readable
const accountLink = await stripe.accountLinks.create({
account: "acct_1KGr2lRBqHE8Zf27",
refresh_url: "https://us-central1-the-stride-app-7eda9.cloudfunctions.net/stripeGetAccountLink",
return_url: "https://thestrideapp.page.link/pleasework",
type: "account_onboarding",
},
function (err, accountLink) {
if(err!= null) {
res.json({
status: "fail"
})
console.log(err);
}
else {
res.json({
accountUrl: accountLink.url,
status: "success",
})
console.log("Successfully created new account");
}
}
)
})```
This function creates an account link and then returns JSON to your app/client to have the URL to redirect to right?
Now when Stripe sends the customer back to https://thestrideapp.page.link/pleasework then you need to do something similar, but instead of returning JSON, you would redirect the browser back to the new AccountLink's url
Well so that is a dynamic link to redirect them back to our app once they have completed the forms in which case I wouldn't want to redirect them back to the accountLink correct? Because isn't it the refresh_url that is supposed to redirect them back to the accountlink?
So I think you are completely misunderstanding all of this, but I don't understand why/what part. It's so strange, your sentence looks almost correct, but subtly wrong. Not trying to offend, I hope that's clear, I'm just thoroughly lost
Imagine I am on example.com and I click a button where you create an AccountLink for me to go to Stripe and enter my detail. When you do, you set success_url: 'example.com/success' and refresh_url: 'example.com/refresh'
You create the link, you send me to Stripe. There, I do something that forces me to need a new link (many things can cause that). In that case, Stripe sends me back to example.com/refresh which is your own code where we expect your code/app to create a new AccountLink and then send me back to Stripe again. As many times as needed since I might go back to the refresh_url many times
Basically an AccountLink's url is one-time use. If I go there and reload the page, the link is expired already (since I used it once) and so I get sent to refresh_url
So would I need to create a new Endpoint just for the refresh_url, basically meaning I wouldn't pass in a url to refresh_url and instead would pass it a function?
I don't understand what it means to "pass it a function"
Pass it the url for a separate cloud function
then yes. Or you tweak your cloud function to handle this. For example your mobile app can pass a parameter saying "please return the URL, don't redirect" and if the parameter is missing you redirect, that way you only need one function
I believe I know exactly what needs to be done but how can I just return the url alone, not as a json or with any other info? When I try to just return acountLink.url, it times out every time
it depends a bit on your stack but for example https://stackoverflow.com/a/45897350/1606729
Ufffda I got it working it really just came down to my lack of knowledge on node.js, but I really appreciate you helping me out and stepping past just stripe to help on a more basic level but it really was just changing it to res.redirect