#scott-connect-standaard
1 messages · Page 1 of 1 (latest)
scott-connect-standaard
We usually strongly recommend just creating a brand new account
not using an existing Standard account that they use for other stuff
that way the activity is limited to your platform
oh ok
true
hmm
here is what my verifyStripe API route is doing so far:
import { NextApiRequest, NextApiResponse } from "next";
import { getServerAuthSession } from "../../server/common/get-server-auth-session";
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { code } = req.body;
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const result = await stripe.oauth
.token({
grant_type: "authorization_code",
code: code,
})
.catch((err: any) => {
throw new Error("Stripe oauth fail", err.message);
});
const account = await stripe.accounts
?.retrieve(result?.stripe_user_id)
?.catch((err: any) => {
throw new Error("Error fetching stripe account", err.message);
});
// Here we get the important details of the account.
const accountAnalysis = {
hasConnectedAccount: !!account?.id, // Check if account ID received is actually connected or exists.
accountId: account?.id,
hasCompletedProcess: account?.details_submitted,
isValid: account?.charges_enabled && account?.payouts_enabled,
displayName:
account?.settings?.dashboard?.display_name ||
account?.display_name ||
null,
country: account?.country,
currency: account?.default_currency,
};
// boolean - Once the account is connected, should we let it unlink?
const shouldAllowUnlink =
accountAnalysis?.hasConnectedAccount &&
(!accountAnalysis?.isValid ||
!accountAnalysis?.hasCompletedProcess ||
!accountAnalysis?.displayName);
return res
.status(200)
.json({ oauth: result, account, accountAnalysis, shouldAllowUnlink });
} catch (error) {
console.log(error);
res.status(500).json(error);
}
};
export default handler;
basically my client side, I send the user to the onboarding screen, they log in and select an account, then it redirects back to the account page in my app with url params scope and code which I pass the code along to this endpoint to get some account data that is returned for that connected account but again, this only seems to be leaning towards existing accounts
okay so you're using OAuth
you're not creating any new account in the API here
https://stripe.com/docs/connect/oauth-standard-accounts it's this doc
not to my knowledge
what do you mean?
not to my knowledge am I creating a new account, is there a way to with this oauth flow?
oh I am testing it out with the button from the docs and I see a 'Create New Account" is that what I would urge my users to do?
ok
https://stripe.com/docs/connect/standard-accounts this is the canonical integration path for a platform creating Standard accounts
that's what we recommend everyone does
https://stripe.com/docs/connect/oauth-standard-accounts is the Legacy path. It is needed in some cases (if you need access to existing data for example as an extension) though discouraged if you are accepting payments on behalf of a connected account and just want to see your own platform's activity in the account
so the first question is: what do you want to do
my goal is to allow my users to connect their stripe account to mine, so that when using my app, they can generate a new donation/tip link that they can share, which directs a non-user(donor) to a donation form, which uses PaymentElement to cover the checkout flow and creates a paymentIntent that I handle at checkout. Within the checkout form, I get the donation amount, apply a processing fee so that the app user(creator) receiving the donation doesn't have to carry those charges, then passes that to the paymentIntent so that the paymentIntent amount and the processing/platform fee is sent with that request. The processing fee goes to my account, the donation goes to the user(creator) account. I want to not take their money into mine and issue payouts so that I don't have to carry the burden of taxes on their behalf.
I was following an example that uses NextJS and it apparently uses the oauth flow to connect their accounts to mine, but I was not seeing their account connected within my stripe dashboard, so I am a bit lost
all good
so my advice is to not use OAuth at all here and follow our canonical doc https://stripe.com/docs/connect/standard-accounts which is way easier than OAuth (that's why we built it)
But the problem with the "connection" is usually with the step after the redirect.
So I guess: do you have anything you can share about your flow other than the code? Like you go to Stripe, you fill out a bunch of stuff, then you get back to your redirect URL that you configured in the Dashboard. Does that part work?
so far I think yes
okay so you get to your own URL with the ac_1234567 in the URL as a query parameter?
long video, sorry
so you get back to your url, then what?
you have code here, did you check if the code runs? Did you add logs there?
like the first thing your code does is const result = await stripe.oauth .token({ grant_type: "authorization_code", code: code, })
what is code? does it work? what is returned, does that work?
with the code param in that url on the server, when that page loads it passes that code to the endpoint I shared with you earlier, the json data you see on the page when you return is the account I tried to connect with
code in the oauth.token call is the code I pass from my url params to my endpoint
okay so the code runs and the account is connected so what's the issue?
ok actually with that last attempt I am seeing an account connected but it was 'skipped form' that I clicked and so it seems as though that is why it is restricted?
before it wasn't storing the account as connected...
for like 2 weeks i have been scratching my head wondering what I was missing but idk
it just...woked
worked
do you have an example account id acct_123 where you saw it connect and then it didn't work?
I can look at it maybe
which one?
😅
I'm asking you
like you have been testing this for days
I'm asking if you have an example acct_1234567 that you connected. The id is right there in the output on your screen after the connection
if you have one that you know you did connect but it's not in the list, I can look at it
oh no I never saved any of that, sorry
um, if the shouldAllowDisconnect boolean I return is true, but the account is connected, that would mean that the account either
1) already has a connectedAccount
2) isn't valid
3) hasn't completed onboarding, or
4) has no display name
correct?
I have no idea what shouldAllowDisconnect is
sorry we're running a bit in circles
what would I want to do in that case so that they can disconnect and try again, so I don't have a bunch of restricted accounts connected to mine
seems like this now works overall
so shouldAllowDisconnect is just a computed boolean based on some properties in the returned account info
Yes, sorry. I am trying to avoid having restricted or unfinished accounts, or otherwise invalid accounts connected, and only allow the connection to happen if it's able to take payouts
also, so with that account ID from the connected account, I can pass that to the account id field in the payment intent later on from the donation form, and the application fee would still go to me, and the donation to them, with seemingly no issue as long as their account is valid?
and only allow the connection to happen if it's able to take payouts
that doesn't really make sense honestly
Even if they can "take payouts" they might be disabled tomorrow
Also, you shouldn't be using Payouts with Standard accounts. So charges_enabled is what matters most
yep
ahh makes sense
I want t avoid payouts if possible
am I still allowed to check the balance of that account from mine? I want to display a 'wallet' on the app, even though that reflects what is in their stripe account
thank you!