mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 13:41:22 +00:00
* Changed to query page by id * Fixed page query, Changed use-search GraphQl query * Update use-search.tsx * remove unused util * Changed cookie expiration * Update tsconfig.json * Fix add to cart & prepare for user activation * Update helpers.ts * Update helpers.ts * Changes, fix Shopify GraphQL deprecations * Update checkout-to-cart.ts * Default to BigCommerce * Update index.ts * Fixed types
34 lines
785 B
TypeScript
34 lines
785 B
TypeScript
import Cookies from 'js-cookie'
|
|
|
|
import {
|
|
SHOPIFY_CHECKOUT_ID_COOKIE,
|
|
SHOPIFY_CHECKOUT_URL_COOKIE,
|
|
SHOPIFY_COOKIE_EXPIRE,
|
|
} from '../const'
|
|
|
|
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: SHOPIFY_COOKIE_EXPIRE,
|
|
}
|
|
Cookies.set(SHOPIFY_CHECKOUT_ID_COOKIE, checkoutId, options)
|
|
Cookies.set(SHOPIFY_CHECKOUT_URL_COOKIE, checkout.webUrl, options)
|
|
}
|
|
|
|
return checkout
|
|
}
|
|
|
|
export default checkoutCreate
|