fullcart
Version:
Add stripe checkout to any website
23 lines (18 loc) • 593 B
text/typescript
import { type Cart } from '../schemas/cartSchema'
import type { Config } from '../schemas/configSchema'
import type { Customer } from '../schemas/customerSchema'
export const buildCart = (config: Config, customer: Customer) => {
const { products, ...options } = config
const lines = customer.lines
const enrichedLines = lines
.map((line) => ({
...line,
product: products?.find((product) => product.id === line.productId),
}))
.filter((line) => line.product !== undefined)
const cart = {
...options,
lines: enrichedLines,
}
return cart as Cart
}