#manic-pixie-dream-bananarchist_api

1 messages · Page 1 of 1 (latest)

latent sinewBOT
#

👋 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/1263305437256614001

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

faint quarry
#

Can you share with me the relevant code?

spiral basin
#

when stripe redirects to our server on checkout session completion, no session_id is included

#
    return_url: `${chipServerConfig.environmentBaseUrl[process.env.NODE_ENV]}${getRouteUrl({
      to: '/subscribe/return',
      query: { session_id: '{CHECKOUT_SESSION_ID}' },
    })}`,
#

looking at the event i linked above, this is what the return url is set to "return_url": "https://divvyhomes.com/up/subscribe/return?session_id={CHECKOUT_SESSION_ID}",

#

however looking at our server request logs, no session_id parameter is included

faint quarry
#

Ok, give me some time to investigate

#

Can you share with me the complete code of getRouteUrl function?

spiral basin
#
import { isNil, omitBy } from 'lodash';
import { stringify } from 'qs';
import type { Route } from '@app/chip/client/types/route';
import { chipBasePathname } from 'src/chip/client/constants';

export const getRouteUrl = ({ to, query: rawQuery }: Route): string => {
  const query = omitBy(rawQuery, isNil);
  const queryParams = Object.keys(query).length > 0 ? stringify(query) : undefined;
  const path = !isNil(queryParams) ? `${to}?${queryParams}` : to;
  return decodeURIComponent(`/${chipBasePathname}${path}`);
};
faint quarry
#

Wait, is this how you construct the successUrl ?

#

I need the code where you extract the session ID from return_url

spiral basin
#

oh yeah this is the construction

faint quarry
#

Ah, I know the problem

#

You should set {CHECKOUT_SESSION_ID} on success_url, not return_url

spiral basin
#

is this a regression?

#

we haven't changed any of this code in months

#

seems like the API changed

#

the documentation says this

If you’ve integrated with an embedded payment form, you can’t use the success_url parameter. You must use return_url. Learn more about customizing redirect behavior for integrations with the embedded form.

#

we're using the embedded form

faint quarry
#

Sorry, I didn't notice you are using embedded form, and yes you can set {CHECKOUT_SESSION_ID} on return_url

spiral basin
#

this is the query parsing code, fwiw


const querySchema = z.object({
  session_id: z.string(),
});

export const getServerSideProps: GetServerSideProps = async ({ req, res, query: rawQuery }) => {
  const session = await getServerSession(req, res, authOptions);
  const userId = session?.user.id;
  if (isNil(userId)) {
    throw makeChipError('Unauthorized');
  }

  const query = querySchema.safeParse(rawQuery);
  if (!query.success) {
    throw makeChipError('Invalid query', {
      info: {
        userId,
      },
    });
  }
...
})
faint quarry
#

and what's inside getServerSession ?

spiral basin
#

but i verified the parsing works successfully by just manually inputting a url
i.e. https://divvyhomes.com/up/subscribe/return?session_id=1234

#

our server picks this up, which means the only way this could happen is if the session_id is just not included

#

getServerSession is a next js module function

#

it just sets some cookies

faint quarry
#

Ok, I just tested my embedded checkout integration and I can't reproduce the problem

spiral basin
#

but our server logs show the error that's thrown from this

  const query = querySchema.safeParse(rawQuery);
  if (!query.success) {
    throw makeChipError('Invalid query', {
      info: {
        userId,
      },
    });
  }
faint quarry
#

Is there a public URL that I can visit to test your integration in test mode?

spiral basin
#

there is not

faint quarry
#

Can you set up one?

spiral basin
#

not really, the checkout session code is heavily dependent on account creation steps that happen prior

#

does it need to be in test mode?

#

you can create an account and go through the onboarding flow to get to the checkout session page

#

but it won't be in test mode

faint quarry
#

Yes, I can't make real payments so I can only test in test mode.

spiral basin
#

we could probably make it so that when you get to the session page, you can manually add a ?mode=test query parameter that will use test mode

#

what specifically are you trying to verify though? is there a way i can just do it for you?

#

we have internal credit cards that we use for testing this stuff

faint quarry
#

Or can you create a checkout session that doesn't require payment (i.e., use coupon or trial)

spiral basin
#

this isn't something i can do immediately

#

but if there's a way i can just do this for you, you can tell me what it is you're looking for

faint quarry
spiral basin
#

i'll go through the steps and screen record it

#

okay sorry for the false alarm

#

it's getting stripped on our end

#

didn't notice this the first time i went through

#

but there's some layer somewhere in our infra that's redirecting without the query param 😦

faint quarry
#

I see, looks like you can continue troubleshooting from there.

spiral basin
#

yep. thanks for the help