4
0
forked from crowetic/commerce
commerce/framework/shopify/cart/utils/checkout-create.ts
2021-02-04 17:18:33 +02:00

25 lines
613 B
TypeScript

import {
SHOPIFY_CHECKOUT_ID_COOKIE,
SHOPIFY_CHECKOUT_URL_COOKIE,
} from '@framework/const'
import checkoutCreateMutation from '@framework/utils/mutations/checkout-create'
import Cookies from 'js-cookie'
export const checkoutCreate = async (fetch: any) => {
const data = await fetch({
query: checkoutCreateMutation,
})
const checkout = data?.checkoutCreate?.checkout
const checkoutId = checkout?.id
if (checkoutId) {
Cookies.set(SHOPIFY_CHECKOUT_ID_COOKIE, checkoutId)
Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout?.webUrl)
}
return checkout
}
export default checkoutCreate