commerce/framework/saleor/utils/checkout-create.ts
2021-06-09 17:02:07 +02:00

27 lines
588 B
TypeScript

import Cookies from 'js-cookie'
import checkoutCreateMutation from './mutations/checkout-create'
import { CheckoutCreatePayload } from '../schema'
export const checkoutCreate = async (
fetch: any
): Promise<CheckoutCreatePayload> => {
const data = await fetch({
query: checkoutCreateMutation,
})
const checkout = data.checkoutCreate?.checkout
const checkoutId = checkout?.id
if (checkoutId) {
const options = {
expires: 60 * 60 * 24 * 30,
}
Cookies.set('saleorCheckoutID', checkoutId, options)
}
return checkout
}
export default checkoutCreate