mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 07:45:53 +00:00
29 lines
516 B
TypeScript
29 lines
516 B
TypeScript
import { SWELL_CHECKOUT_URL_COOKIE } from '../../const'
|
|
|
|
import Cookies from 'js-cookie'
|
|
|
|
export const checkoutCreate = async (fetch: any) => {
|
|
const cart = await fetch({
|
|
query: 'cart',
|
|
method: 'get',
|
|
})
|
|
|
|
if (!cart) {
|
|
const cart = await fetch({
|
|
query: 'cart',
|
|
method: 'setItems',
|
|
variables: [[]],
|
|
})
|
|
}
|
|
|
|
const checkoutUrl = cart?.checkout_url
|
|
|
|
if (checkoutUrl) {
|
|
Cookies.set(SWELL_CHECKOUT_URL_COOKIE, checkoutUrl)
|
|
}
|
|
|
|
return cart
|
|
}
|
|
|
|
export default checkoutCreate
|