Skip to content

Commit

Permalink
Fix redirect checkout (vercel#502)
Browse files Browse the repository at this point in the history
* Fix redirect checkout

* Don't use checkout for saleor
  • Loading branch information
goncy authored Sep 24, 2021
1 parent c440ff0 commit 8e7b942
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { uuid } from 'uuidv4'

const fullCheckout = true

const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req,
res,
config,
Expand Down Expand Up @@ -87,4 +87,4 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
res.end()
}

export default submitCheckout
export default getCheckout
4 changes: 2 additions & 2 deletions framework/bigcommerce/api/endpoints/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { GetAPISchema, createEndpoint } from '@commerce/api'
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
import type { CheckoutSchema } from '../../../types/checkout'
import type { BigcommerceAPI } from '../..'
import submitCheckout from './submit-checkout'
import getCheckout from './get-checkout'

export type CheckoutAPI = GetAPISchema<BigcommerceAPI, CheckoutSchema>

export type CheckoutEndpoint = CheckoutAPI['endpoint']

export const handlers: CheckoutEndpoint['handlers'] = { submitCheckout }
export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }

const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint,
Expand Down
4 changes: 2 additions & 2 deletions framework/commerce/api/endpoints/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const checkoutEndpoint: GetAPISchema<
// Create checkout
if (req.method === 'GET') {
const body = { ...req.body, cartId }
return await handlers['getCheckout']?.({ ...ctx, body })
return await handlers['getCheckout']({ ...ctx, body })
}

// Create checkout
if (req.method === 'POST') {
if (req.method === 'POST' && handlers['submitCheckout']) {
const body = { ...req.body, cartId }
return await handlers['submitCheckout']({ ...ctx, body })
}
Expand Down
6 changes: 3 additions & 3 deletions framework/commerce/types/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Address } from './customer/address'
import type { Card } from './customer/card'

// Index
export type Checkout = unknown;
export type Checkout = any

export type CheckoutTypes = {
card?: Card
Expand Down Expand Up @@ -45,8 +45,8 @@ export type SubmitCheckoutHandler<T extends CheckoutTypes = CheckoutTypes> =
}

export type CheckoutHandlers<T extends CheckoutTypes = CheckoutTypes> = {
getCheckout?: GetCheckoutHandler<T>
submitCheckout: SubmitCheckoutHandler<T>
getCheckout: GetCheckoutHandler<T>
submitCheckout?: SubmitCheckoutHandler<T>
}

export type CheckoutSchema<T extends CheckoutTypes = CheckoutTypes> = {
Expand Down
4 changes: 2 additions & 2 deletions framework/saleor/api/endpoints/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>

export type CheckoutEndpoint = CheckoutAPI['endpoint']

const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({ req, res, config }) => {
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ req, res, config }) => {
try {
const html = `
<!DOCTYPE html>
Expand Down Expand Up @@ -43,7 +43,7 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
}
}

export const handlers: CheckoutEndpoint['handlers'] = { submitCheckout }
export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }

const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint,
Expand Down
3 changes: 1 addition & 2 deletions framework/saleor/commerce.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"provider": "saleor",
"features": {
"wishlist": false,
"customCheckout": true
"wishlist": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import associateCustomerWithCheckoutMutation from '../../../utils/mutations/associate-customer-with-checkout'
import type { CheckoutEndpoint } from '.'

const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req,
res,
config,
Expand Down Expand Up @@ -35,4 +35,4 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
}
}

export default submitCheckout
export default getCheckout
4 changes: 2 additions & 2 deletions framework/shopify/api/endpoints/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { GetAPISchema, createEndpoint } from '@commerce/api'
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
import type { CheckoutSchema } from '../../../types/checkout'
import type { ShopifyAPI } from '../..'
import submitCheckout from './submit-checkout'
import getCheckout from './get-checkout'

export type CheckoutAPI = GetAPISchema<ShopifyAPI, CheckoutSchema>

export type CheckoutEndpoint = CheckoutAPI['endpoint']

export const handlers: CheckoutEndpoint['handlers'] = { submitCheckout }
export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }

const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint,
Expand Down
4 changes: 2 additions & 2 deletions framework/swell/api/endpoints/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CheckoutSchema } from '@commerce/types/checkout'
import { SWELL_CHECKOUT_URL_COOKIE } from '../../../const'
import checkoutEndpoint from '@commerce/api/endpoints/checkout'

const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req,
res,
config,
Expand All @@ -17,7 +17,7 @@ const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
res.redirect('/cart')
}
}
export const handlers: CheckoutEndpoint['handlers'] = { submitCheckout }
export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }

export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
export type CheckoutEndpoint = CheckoutAPI['endpoint']
Expand Down
4 changes: 2 additions & 2 deletions framework/vendure/api/endpoints/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api'
import { CheckoutSchema } from '@commerce/types/checkout'
import checkoutEndpoint from '@commerce/api/endpoints/checkout'

const submitCheckout: CheckoutEndpoint['handlers']['submitCheckout'] = async ({
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
req,
res,
config,
Expand Down Expand Up @@ -48,7 +48,7 @@ export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>

export type CheckoutEndpoint = CheckoutAPI['endpoint']

export const handlers: CheckoutEndpoint['handlers'] = { submitCheckout }
export const handlers: CheckoutEndpoint['handlers'] = { getCheckout }

const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = withCommerceConfig({
},
rewrites() {
return [
(isBC || isShopify || isSwell || isVendure) && {
(isBC || isShopify || isSwell || isVendure || isSaleor) && {
source: '/checkout',
destination: '/api/checkout',
},
Expand Down

0 comments on commit 8e7b942

Please sign in to comment.