diff --git a/packages/auth/components/login.tsx b/packages/auth/components/login.tsx
index 31aa2bcc..7f73b324 100644
--- a/packages/auth/components/login.tsx
+++ b/packages/auth/components/login.tsx
@@ -98,14 +98,16 @@ const Login: React.FC<{
) : (
-
- {returnToUrl && (
-
router.push(returnToUrl)}>
-
-
- )}
- {!hideHeader &&
Login }
-
+ {!hideHeader && (
+
+ {returnToUrl && (
+
router.push(returnToUrl)}>
+
+
+ )}
+
Login
+
+ )}
{redirectUrl === 'checkout' &&
You will be redirected to checkout after login.
}
- or -
diff --git a/packages/auth/package.json b/packages/auth/package.json
index 76672c13..c00ea959 100644
--- a/packages/auth/package.json
+++ b/packages/auth/package.json
@@ -1,6 +1,6 @@
{
"name": "@hanzo/auth",
- "version": "2.0.0",
+ "version": "2.0.1",
"description": "Library with Firebase authentication.",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
diff --git a/packages/commerce/components/checkout/contact-info.tsx b/packages/commerce/components/checkout/contact-info.tsx
deleted file mode 100644
index e340e430..00000000
--- a/packages/commerce/components/checkout/contact-info.tsx
+++ /dev/null
@@ -1,83 +0,0 @@
-'use client'
-
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from '@hanzo/ui/primitives/form'
-import { Input, Button } from '@hanzo/ui/primitives'
-import { User } from 'lucide-react'
-import { EnhHeadingBlockComponent, type EnhHeadingBlock } from '@hanzo/ui/blocks'
-import type { UseFormReturn } from 'react-hook-form'
-
-const ContactInfo: React.FC<{
- form: UseFormReturn<{
- name: string;
- email: string;
- }, any, {
- name: string;
- email: string;
- }>,
- selectPaymentMethod: (method: 'crypto' | 'bank') => Promise
,
-}> = ({
- form,
- selectPaymentMethod,
-}) => {
- return (
-
-
- )
-}
-
-export default ContactInfo
\ No newline at end of file
diff --git a/packages/commerce/components/checkout/index.tsx b/packages/commerce/components/checkout/index.tsx
index 42304e4d..a3ec33af 100644
--- a/packages/commerce/components/checkout/index.tsx
+++ b/packages/commerce/components/checkout/index.tsx
@@ -1,13 +1,9 @@
'use client'
-import { useEffect, useState } from 'react'
+import { useState } from 'react'
import { ChevronLeft } from 'lucide-react'
import { observer } from 'mobx-react-lite'
-import { zodResolver } from '@hookform/resolvers/zod'
-import * as z from 'zod'
-import { useForm } from 'react-hook-form'
-
import { Button, Main, Separator, Toaster } from '@hanzo/ui/primitives'
import { cn } from '@hanzo/ui/util'
import { useAuth } from '@hanzo/auth/service'
@@ -15,85 +11,41 @@ import { LoginComponent, AuthWidget } from '@hanzo/auth/components'
import ShippingInfo from './shipping-info'
import ThankYou from './thank-you'
-import PayWithCrypto from './pay-with-crypto'
-import PayByBankTransfer from './pay-by-bank-transfer'
-import ContactInfo from './contact-info'
import { Cart } from '..'
-import { useCommerce } from '../../service/context'
-
-const contactFormSchema = z.object({
- name: z.string().min(2, 'Name must be at least 2 characters.'),
- email: z.string().email(),
-})
+import Payment from './payment'
const Checkout: React.FC<{toggleCheckout: () => void}> = observer(({toggleCheckout}) => {
const auth = useAuth()
- const cmmc = useCommerce()
const [currentStep, setCurrentStep] = useState(1)
- const [paymentMethod, setPaymentMethod] = useState<'crypto' | 'bank' | undefined>()
const [orderId, setOrderId] = useState()
- const contactForm = useForm>({
- resolver: zodResolver(contactFormSchema),
- defaultValues: {
- name: auth.user?.displayName ?? '',
- email: auth.user?.email ?? '',
- },
- })
-
- useEffect(() => {
- if (auth.loggedIn) {
- contactForm.setValue('name', auth.user?.displayName ?? '')
- contactForm.setValue('email', auth.user?.email ?? '')
- }
- }, [auth.loggedIn])
-
- const selectPaymentMethod = async (method: 'crypto' | 'bank') => {
- contactForm.handleSubmit(async () => {
- if (auth.user) {
- if (!!orderId) {
- await cmmc.updateOrder(orderId, auth.user.email, method)
- } else {
- const id = await cmmc.createOrder(auth.user.email, method)
- setOrderId(id)
- }
- }
- setPaymentMethod(method)
- setCurrentStep(2)
- })()
- }
-
-
const step1 = auth.loggedIn ? (
-
+
) : (
)
- const step2 = paymentMethod === 'crypto' ? (
-
- ) : (
-
- )
-
- const step3 = (
-
+ const step2 = (
+
)
- const step4 =
+ const step3 =
- const steps = [step1, step2, step3, step4]
+ const steps = [step1, step2, step3]
return (
-
+
-
+
{
setCurrentStep(0)
toggleCheckout()
@@ -109,18 +61,18 @@ const Checkout: React.FC<{toggleCheckout: () => void}> = observer(({toggleChecko
-
+
{steps[currentStep - 1]}
diff --git a/packages/commerce/components/checkout/pay-by-bank-transfer.tsx b/packages/commerce/components/checkout/pay-by-bank-transfer.tsx
deleted file mode 100644
index cb02c5ef..00000000
--- a/packages/commerce/components/checkout/pay-by-bank-transfer.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-'use client'
-
-import type { ReactNode } from 'react'
-import { Copy } from 'lucide-react'
-
-import { Button, Tabs, TabsContent, TabsList, TabsTrigger, toast } from '@hanzo/ui/primitives'
-import { EnhHeadingBlockComponent, type EnhHeadingBlock, type Block } from '@hanzo/ui/blocks'
-
-const InfoField: React.FC<{label: string, value: ReactNode, copyValue: string}> = ({label, value, copyValue}) => {
- const copyToClipboard = (label: string, text: string) => {
- navigator.clipboard.writeText(text)
- toast({title: `${label} copied to clipboard`})
- }
-
- return (
-
-
{label}
-
- {value}
- copyToClipboard(label, copyValue)}>
-
-
-
-
- )
-}
-
-const PayByBankTransfer: React.FC<{setCurrentStep: (step: number) => void}> = ({setCurrentStep}) => {
- return (<>
-
-
- USD
- EUR/GBP
-
-
-
- Bank of America NA 222 Broadway New York, New York. 10038
}
- copyValue='Bank of America, NA 222 Broadway, New York, New York. 10038'
- />
- Hanzo, Inc 4811 Mastin Street Merriam, KS 66203 }
- copyValue='Hanzo, Inc, 4811 Mastin Street, Merriam, KS 66203'
- />
-
-
-
-
-
-
-
-
- Clear Junction Limited 4th floor Imperial House
}
- copyValue='Clear Junction Limited, 4th floor, Imperial House'
- />
-
-
-
-
-
-
-
-
-
-
- setCurrentStep(1)} className='mx-auto w-full'>Back
- setCurrentStep(3)} className='mx-auto w-full'>Continue
-
- >)
-}
-
-export default PayByBankTransfer
diff --git a/packages/commerce/components/checkout/payment/contact-info.tsx b/packages/commerce/components/checkout/payment/contact-info.tsx
new file mode 100644
index 00000000..90480775
--- /dev/null
+++ b/packages/commerce/components/checkout/payment/contact-info.tsx
@@ -0,0 +1,59 @@
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from '@hanzo/ui/primitives/form'
+import { Input } from '@hanzo/ui/primitives'
+import type { UseFormReturn } from 'react-hook-form'
+
+const ContactInfo: React.FC<{
+ form: UseFormReturn<{
+ name: string
+ email: string
+ }, any, {
+ name: string
+ email: string
+ }>,
+}> = ({
+ form,
+}) => {
+ return (
+
+
+ )
+}
+
+export default ContactInfo
\ No newline at end of file
diff --git a/packages/commerce/components/checkout/payment/index.tsx b/packages/commerce/components/checkout/payment/index.tsx
new file mode 100644
index 00000000..0047edf8
--- /dev/null
+++ b/packages/commerce/components/checkout/payment/index.tsx
@@ -0,0 +1,117 @@
+'use client'
+
+import { useEffect, useState } from 'react'
+import { observer } from 'mobx-react-lite'
+
+import { zodResolver } from '@hookform/resolvers/zod'
+import * as z from 'zod'
+import { useForm } from 'react-hook-form'
+
+import { Tabs, TabsContent, TabsList, TabsTrigger } from '@hanzo/ui/primitives'
+import { useAuth } from '@hanzo/auth/service'
+import PayWithCrypto from './pay-with-crypto'
+import PayWithBankTransfer from './pay-with-bank-transfer'
+import PayWithCard from './pay-with-card'
+import { useCommerce, type TransactionStatus } from '../../..'
+
+const contactFormSchema = z.object({
+ name: z.string().min(1, 'Enter your full name.'),
+ email: z.string().email(),
+})
+
+const Payment: React.FC<{
+ setCurrentStep: (currentStep: number) => void
+ orderId?: string
+ setOrderId: (orderId?: string) => void
+}> = observer(({
+ setCurrentStep,
+ orderId,
+ setOrderId
+}) => {
+ const cmmc = useCommerce()
+ const auth = useAuth()
+ const [transactionStatus, setTransactionStatus] = useState('unpaid')
+
+ const contactForm = useForm>({
+ resolver: zodResolver(contactFormSchema),
+ defaultValues: {
+ name: auth.user?.displayName ?? '',
+ email: auth.user?.email ?? '',
+ },
+ })
+
+ useEffect(() => {
+ if (auth.loggedIn) {
+ contactForm.setValue('name', auth.user?.displayName ?? '')
+ contactForm.setValue('email', auth.user?.email ?? '')
+ }
+ }, [auth.loggedIn])
+
+ const storePaymentInfo = async (paymentInfo: any) => {
+ if (auth.user) {
+ const {name, email} = contactForm.getValues()
+ let id
+ if (!orderId) {
+ id = await cmmc.createOrder(email ? email : auth.user.email, name)
+ setOrderId(id)
+ }
+ if (id) {
+ await cmmc.updateOrderPaymentInfo(id, paymentInfo)
+ }
+ }
+ }
+
+ return (
+
+
+
+ PAY WITH CARD
+
+
+ PAY WITH CRYPTO
+
+
+ BANK TRANSFER
+
+
+
+
+
+
+
+
+
+
+
+
+ )
+})
+
+export default Payment
diff --git a/packages/commerce/components/checkout/payment/pay-with-bank-transfer.tsx b/packages/commerce/components/checkout/payment/pay-with-bank-transfer.tsx
new file mode 100644
index 00000000..01bba1d1
--- /dev/null
+++ b/packages/commerce/components/checkout/payment/pay-with-bank-transfer.tsx
@@ -0,0 +1,106 @@
+'use client'
+
+import type { ReactNode } from 'react'
+import { Copy } from 'lucide-react'
+import type { UseFormReturn } from 'react-hook-form'
+
+import { Button, Tabs, TabsContent, TabsList, TabsTrigger, toast } from '@hanzo/ui/primitives'
+import ContactInfo from './contact-info'
+
+const InfoField: React.FC<{
+ label: string,
+ value: ReactNode,
+ copyValue: string
+}> = ({
+ label,
+ value,
+ copyValue
+}) => {
+ const copyToClipboard = (label: string, text: string) => {
+ navigator.clipboard.writeText(text)
+ toast({title: `${label} copied to clipboard`})
+ }
+
+ return (
+
+
{label}
+
+ {value}
+ copyToClipboard(label, copyValue)}>
+
+
+
+
+ )
+}
+
+const PayWithBankTransfer: React.FC<{
+ setCurrentStep: (step: number) => void
+ storePaymentInfo: (paymentInfo: any) => Promise
+ contactForm: UseFormReturn<{
+ name: string
+ email: string
+ }, any, {
+ name: string
+ email: string
+ }>
+}> = ({
+ setCurrentStep,
+ storePaymentInfo,
+ contactForm
+}) => {
+ const payByBankTransfer = async () => {
+ contactForm.handleSubmit(async () => {
+ await storePaymentInfo({paymentMethod: 'bank-transfer'})
+ setCurrentStep(2)
+ })()
+ }
+
+ return (
+
+
+
+
+ USD
+ EUR/GBP
+
+
+
+ Bank of America NA 222 Broadway New York, New York. 10038
}
+ copyValue='Bank of America, NA 222 Broadway, New York, New York. 10038'
+ />
+ Hanzo, Inc 4811 Mastin Street Merriam, KS 66203 }
+ copyValue='Hanzo, Inc, 4811 Mastin Street, Merriam, KS 66203'
+ />
+
+
+
+
+
+
+
+
+ Clear Junction Limited 4th floor Imperial House
}
+ copyValue='Clear Junction Limited, 4th floor, Imperial House'
+ />
+
+
+
+
+
+
+
+
+
+ Continue
+
+ )
+}
+
+export default PayWithBankTransfer
diff --git a/packages/commerce/components/checkout/payment/pay-with-card.tsx b/packages/commerce/components/checkout/payment/pay-with-card.tsx
new file mode 100644
index 00000000..5d8e0eab
--- /dev/null
+++ b/packages/commerce/components/checkout/payment/pay-with-card.tsx
@@ -0,0 +1,193 @@
+'use client'
+
+// @ts-ignore
+import { ApplePay, GooglePay, CreditCard, PaymentForm } from 'react-square-web-payments-sdk'
+import type { UseFormReturn } from 'react-hook-form'
+import { ApplyTypography, Button } from '@hanzo/ui/primitives'
+import { useCommerce, type TransactionStatus } from '../../..'
+import PaymentMethods from './payment-methods'
+import { processSquareCardPayment } from '../../../util'
+import ContactInfo from './contact-info'
+
+const PayWithCard: React.FC<{
+ setCurrentStep: (currentStep: number) => void
+ transactionStatus: TransactionStatus
+ setTransactionStatus: (status: TransactionStatus) => void
+ storePaymentInfo: (paymentInfo: any) => Promise