mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 04:37:51 +00:00
22 lines
644 B
TypeScript
22 lines
644 B
TypeScript
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 });
|
|
}
|
|
}
|