commerce/framework/swell/cart/utils/checkout-create.ts
ghoskin 4d85b43a30
Update Swell Provider (#359)
* fix update cart item

* update types

* update checkout

* update get-page, cleanup types

* revert change to incorrect file

* cleanup

Co-authored-by: Greg Hoskin <greghoskin@Gregs-MacBook-Pro.local>
2021-06-14 17:37:18 -03:00

29 lines
503 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) {
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