mirror of
https://github.com/vercel/commerce.git
synced 2025-03-28 08:15:54 +00:00
* Add ordercloud provider * Fix provider errors * Make submit checkout optional * Make submit checkout optional * Remove nullables when creating endpoint type * Update readme * Log checkout error * Log error * Save token to cookie * Update fetch rest * Use token at checkout Co-authored-by: Luis Alvarez <luis@vercel.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import type { SubmitCheckoutHook } from '@commerce/types/checkout'
|
|
import type { MutationHook } from '@commerce/utils/types'
|
|
|
|
import { useCallback } from 'react'
|
|
import useSubmitCheckout, { UseSubmitCheckout } from '@commerce/checkout/use-submit-checkout'
|
|
|
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
|
|
|
export const handler: MutationHook<SubmitCheckoutHook> = {
|
|
fetchOptions: {
|
|
url: '/api/checkout',
|
|
method: 'POST',
|
|
},
|
|
async fetcher({ input: item, options, fetch }) {
|
|
// @TODO: Make form validations in here, import generic error like import { CommerceError } from '@commerce/utils/errors'
|
|
// Get payment and delivery information in here
|
|
|
|
const data = await fetch({
|
|
...options,
|
|
body: { item },
|
|
})
|
|
|
|
return data
|
|
},
|
|
useHook: ({ fetch }) =>
|
|
function useHook() {
|
|
return useCallback(
|
|
async function onSubmitCheckout(input) {
|
|
const data = await fetch({ input })
|
|
|
|
return data
|
|
},
|
|
[fetch]
|
|
)
|
|
},
|
|
}
|