#nazariksh_api

1 messages ยท Page 1 of 1 (latest)

upbeat leafBOT
#

๐Ÿ‘‹ 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.

vagrant junco
#

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.

unique lake
#

I tried to create new account session each time but it's giving the same error

#

What else is needed for more context?

vagrant junco
#

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?

unique lake
#

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

vagrant junco
unique lake
#

In this example that I send, client refetch token on initizliation and server creating new one

vagrant junco
#

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?

unique lake
#

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

vagrant junco
#

That's expected, the Sessions are one-time use. You can't use the same client secret multiple times.

unique lake
#

We already creating new one on each load, but we are getting error

vagrant junco
#

Do you have a publicly accessible test page where I can see the behavior you're describing?

unique lake
#

No

vagrant junco
#

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.

unique lake
#

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

vagrant junco
#

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?

unique lake
#

Yes it's going successfull

vagrant junco
#

Okay, can you log that client secret on the frontend as well, and ensure it's being returned as expected?

unique lake
#

yes

vagrant junco
#

I'm going to need to see a test site then, because it sounds like everything is being done correctly.

unique lake
#

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

vagrant junco
#

Do you have a test user I can use?

#

The server is incredibly busy today, so trying to streamline this as much as possible.

upbeat leafBOT
edgy horizonBOT
unique lake
#

Password@1

vagrant junco
#

Now where do I go/what do I do?

#

If you can provide full replication steps, that would be very helpful.