mirror of
https://github.com/vercel/commerce.git
synced 2025-03-27 15:55:54 +00:00
* commercejs: Initial commit with basic product list * ui: Handle no variants on product * commercejs: Support individual product pages * commercejs: Use separate sdkFetch function * commercejs: Show option hex colors based on option name * commercejs: Support product search and filter * commercejs: Enable carts feature * commercejs: Remove unused API endpoints * commercejs: Fix adding variants to cart * commercejs: Fix types for update cart hook * commercejs: Update README * commercejs: Add sorting to product search * commercejs: Add generic types to cart actions * commercejs: Better cart normalization * commercejs: Provide typing for sdkFetch function * commercejs: Refactor product search logic * commercejs: Update commercejs types package and export types from local directory * commercejs: Remove unused checkout hooks * commercejs: Enhance fetcher to allow custom API routes * commercejs: Fix product types * commercejs: Add checkout functionality * commercejs: Add commercejs to README list of providers * commercejs: Add login/logout auth hooks * commercejs: Adds comment to sdkFetch function * commercejs: Bring back empty useSignup hook to fix build * commercejs: Refactor useCheckout hook logic * commercejs: Add errors to fetcher function if using invalid resource/method * commercejs: Remove use of hex colors for color variants * ui: Fix undefined error when no variants * commercejs: Handle add to cart when no variants * commercejs: Enable customer auth feature * commercejs: Rename public key env variable as commercejs * commercejs: Remove duplicate customer fields * commercejs: Use variants API to generate product variants * commercejs: Fetch all products using sort order * commercejs: Fix use of normalizeProduct function * commercejs: Disable customer auth * commercejs: Show selected variant details in cart view * commercejs: Update to latest commercejs types * commercejs: Fix login email * commercejs: Remove unnecessary ts-ignore * api: Allow parameter to be passed to login API * api: Allow login handler to accept GET requests * commercejs: Add login API for login callback email link * commercejs: Remove unused argument to API * commercejs: Add hook to fetch logged in customer * commercejs: Rename token to match SDK name * commercejs: Enable logout * commercejs: Fix VERCEL_URL env variable * commercejs: Fix using vercel deployment url * commercejs: Add deployment url env vars to templates * Replace yarn with npm * commercejs: Allow checkout submit even without card/address details * ui: Add loading and cart refresh to checkout * commercejs: Leave link to issue on TODO comment * Update docs/README/env.template for commercejs provider * ui: Prevent toggle loading after component unmount * commercejs: Handle product without images * ui: Explicity set loading to false after checkout * Revert "api: Allow parameter to be passed to login API" This reverts commit c3713ec6e23f1b423a071a31221069995d419486. * commercejs: Handle login using API redirect * commercejs: Adds shipping and billing details to checkout data * commercejs: Fix types for fetcher and submit checkout * commercejs: Update README with demo url * commercejs: Update checkout hooks to use checkout context * commercejs: Update checkout logic to use customer fields * ui: Clear checkout fields context after checkout * commercejs: Remove unused clear checkout function * commercejs: Import constants directly
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import type { CardFields } from '@commerce/types/customer/card'
|
|
import type { AddressFields } from '@commerce/types/customer/address'
|
|
import type { CommercejsCheckoutCapture } from '../types/checkout'
|
|
|
|
/**
|
|
* Creates a checkout payload suitable for test checkouts.
|
|
* 1. Hard-codes the payment values for the Commerce.js test gateway.
|
|
* 2. Hard-codes the email until an email field exists on the checkout form.
|
|
* 3. Gets as much as much checkout info as possible from the checkout form, and uses fallback values.
|
|
*/
|
|
export function normalizeTestCheckout({
|
|
paymentInfo,
|
|
shippingInfo,
|
|
shippingOption,
|
|
}: {
|
|
paymentInfo?: CardFields
|
|
shippingInfo?: AddressFields
|
|
shippingOption: string
|
|
}): CommercejsCheckoutCapture {
|
|
const firstName =
|
|
shippingInfo?.firstName || paymentInfo?.firstName || 'Nextjs'
|
|
const lastName = shippingInfo?.lastName || paymentInfo?.lastName || 'Commerce'
|
|
const fullName = `${firstName} ${lastName}`
|
|
const postalCode = shippingInfo?.zipCode || paymentInfo?.zipCode || '94103'
|
|
const street =
|
|
shippingInfo?.streetNumber || paymentInfo?.streetNumber || 'Test Street'
|
|
const townCity = shippingInfo?.city || paymentInfo?.city || 'Test Town'
|
|
|
|
return {
|
|
payment: {
|
|
gateway: 'test_gateway',
|
|
card: {
|
|
number: '4242 4242 4242 4242',
|
|
expiry_month: '01',
|
|
expiry_year: '2024',
|
|
cvc: '123',
|
|
postal_zip_code: postalCode,
|
|
},
|
|
},
|
|
customer: {
|
|
email: 'nextcommerce@test.com',
|
|
firstname: firstName,
|
|
lastname: lastName,
|
|
},
|
|
shipping: {
|
|
name: fullName,
|
|
street,
|
|
town_city: townCity,
|
|
country: 'US',
|
|
},
|
|
billing: {
|
|
name: fullName,
|
|
street,
|
|
town_city: townCity,
|
|
postal_zip_code: postalCode,
|
|
county_state: 'California',
|
|
country: 'US',
|
|
},
|
|
fulfillment: {
|
|
shipping_method: shippingOption,
|
|
},
|
|
}
|
|
}
|