#nazariksh_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1245006958885339219
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there ๐ it's hard to say without more context, but it looks like the right path here is to create a new Account Session to be used.
I tried to create new account session each time but it's giving the same error
What else is needed for more context?
Looking at your logs, I see one attempt to create an Account Session, followed by multiple attempts to access it (I think, client secrets are redacted so I'm not certain). When you encounter the error, does your flow create a new Account Session to be used?
No
This is what we are doing on server:
public async startStripeOnboarding(user_id: string) {
const user = await this.userService.findOneById(user_id);
let stripe_id = user.stripe_id;
if (!stripe_id) {
const stripe_account = await this.stripeService.stripe.accounts.create({ type: 'standard' });
stripe_id = stripe_account.id;
await this.userService.updateAndReturn(user_id, { stripe_id });
}
const accountSession = await this.stripeService.stripe.accountSessions.create({
account: stripe_id,
components: {
account_onboarding: {
enabled: true,
features: {
external_account_collection: true,
},
},
},
});
return accountSession.client_secret;
}
This is the client side:
export const Stripe = React.memo((): ReactElement => {
const { fetchStripeClientSecret } = useStartStripeOnBoarding();
const [stripeConnectInstance] = useState<StripeConnectInstance>(() =>
loadConnectAndInitialize({
publishableKey:
'our_key',
fetchClientSecret: fetchStripeClientSecret,
})
);
return (
<div className={s.wrap}>
<ConnectComponentsProvider connectInstance={stripeConnectInstance}>
<ConnectAccountOnboarding
onExit={() => {
console.log('The account has exited onboarding');
}}
/>
</ConnectComponentsProvider>
</div>
);
})
export const useStartStripeOnBoarding = () => {
const [getStripeSecret] = useLazyQuery<IGetStripeSecretResponse>(GET_SECRET);
const fetchStripeClientSecret = async () => {
const { data } = await getStripeSecret();
const token = data?.token;
if (token) return token;
throw new Error(`Token doesn't exist`);
};
return { fetchStripeClientSecret };
};
const GET_SECRET = gql query startStripeOnBoarding { token: startStripeOnBoarding };
interface IGetStripeSecretResponse {
token: string;
}
And if we are reload or recreating component in short term we getting error
Also in the server side we tried to store session token until it's expire but we get the same err
That's expected it seems, they're single use. You'll need to create a new session if you're going to be reinitializing components.
In this example that I send, client refetch token on initizliation and server creating new one
Sorry, I'm confused, you said your flow isn't fetching new sessions when it hits an error that one is expired. So it sounded like new ones aren't being fetched or created. If you add logging to your server-side code that creates a new Session, do you see it that function is being called every time your page reloads?
Yes
In this example that i send function is being called every time page reloads
Also we tried to call this function only in first load and give in other loads token that we get on first one until token didn't expire, but it's also giving err on 2 and further loads
That's expected, the Sessions are one-time use. You can't use the same client secret multiple times.
Do not save AccountSessions to your database as they expire relatively quickly, and cannot be used more than once.
https://docs.stripe.com/api/account_sessions
We already creating new one on each load, but we are getting error
Do you have a publicly accessible test page where I can see the behavior you're describing?
No
Gotcha, in that case I would recommend double checking that your code is fetching a fresh client secret for a new Account Session every time you load your components. The request pattern in your logs doesn't give me the impression that is happening.
const accountSession = await this.stripeService.stripe.accountSessions.create({
account: stripe_id,
components: {
account_onboarding: {
enabled: true,
features: {
external_account_collection: true,
},
},
},
});
I'm sure that we are refetching token on each load, but maybe some problem with creating token
Are those calls going through successfully? Are they throwing errors? If you log the result from that call do you see it returning a client secret as expected?
Yes it's going successfull
Okay, can you log that client secret on the frontend as well, and ensure it's being returned as expected?
yes
I'm going to need to see a test site then, because it sounds like everything is being done correctly.
ok we will do it
but you need to wait
first of all you need to register there(it's easy)
and than go by this link
Do you have a test user I can use?
The server is incredibly busy today, so trying to streamline this as much as possible.