mirror of
https://github.com/vercel/commerce.git
synced 2025-05-11 12:17:51 +00:00
checkout
This commit is contained in:
parent
9b9f9496c3
commit
be65e581f3
@ -3,4 +3,5 @@ TWITTER_CREATOR="@vercel"
|
||||
TWITTER_SITE="https://nextjs.org/commerce"
|
||||
SITE_NAME="Next.js Commerce"
|
||||
|
||||
CMS_URL="http://localhost:3000"
|
||||
APP_URL="http://localhost:3000"
|
||||
CMS_URL="http://localhost:8000"
|
||||
|
21
app/api/checkout/route.ts
Normal file
21
app/api/checkout/route.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { ajax } from 'lib/shopify/ajax';
|
||||
import { cookies } from 'next/headers';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(): Promise<NextResponse> {
|
||||
const cartId = cookies().get('cartId')?.value;
|
||||
|
||||
if (!cartId) {
|
||||
return NextResponse.json({ message: 'Cart not found.' }, { status: 404 });
|
||||
}
|
||||
|
||||
try {
|
||||
const session = await ajax<any>('POST', `${process.env.CMS_URL}/api/carts/${cartId}/checkout`, {
|
||||
url: process.env.APP_URL
|
||||
});
|
||||
|
||||
return NextResponse.redirect(session.url, 303);
|
||||
} catch (err: any) {
|
||||
return NextResponse.json({ message: err.message }, { status: err.statusCode });
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user