@hanzo/commerce 4.6.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/components/add-to-cart-widget.tsx +2 -2
  2. package/components/cart-panel/index.tsx +13 -12
  3. package/components/cart-panel/products-carousel.tsx +60 -0
  4. package/components/checkout-panel/cart-accordian.tsx +47 -0
  5. package/components/checkout-panel/close-button.tsx +3 -3
  6. package/components/checkout-panel/desktop.tsx +46 -0
  7. package/components/checkout-panel/index.tsx +86 -97
  8. package/components/checkout-panel/mobile.tsx +41 -0
  9. package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/index.tsx +3 -2
  10. package/components/checkout-panel/steps/payment/cc-button.tsx +17 -0
  11. package/components/checkout-panel/{payment → steps/payment}/contact-info.tsx +7 -10
  12. package/components/checkout-panel/{payment → steps/payment}/index.tsx +27 -21
  13. package/components/checkout-panel/{payment → steps/payment}/pay-with-bank-transfer.tsx +14 -10
  14. package/components/checkout-panel/steps/payment/pay-with-card.tsx +246 -0
  15. package/components/checkout-panel/{payment → steps/payment}/pay-with-crypto.tsx +7 -19
  16. package/components/checkout-panel/{shipping-info.tsx → steps/shipping-info.tsx} +15 -22
  17. package/components/checkout-panel/{thank-you.tsx → steps/thank-you.tsx} +4 -1
  18. package/components/checkout-panel/steps/types.ts +14 -0
  19. package/package.json +5 -3
  20. package/service/impls/standalone/actual-line-item.ts +7 -1
  21. package/types/product.ts +4 -0
  22. package/{components/checkout-panel → util}/countries.ts +1 -1
  23. package/components/checkout-panel/payment/pay-with-card.tsx +0 -217
  24. package/components/checkout-panel/step-indicator.tsx +0 -30
  25. package/components/checkout-panel/step.ts +0 -11
  26. /package/components/checkout-panel/{confirm-order.tsx → _confirm-order.tsx_unused} +0 -0
  27. /package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/amex.tsx +0 -0
  28. /package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/diners-club.tsx +0 -0
  29. /package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/discover.tsx +0 -0
  30. /package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/jcb.tsx +0 -0
  31. /package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/mastercard.tsx +0 -0
  32. /package/components/checkout-panel/{payment/payment-methods → steps/payment/cards}/visa.tsx +0 -0
@@ -5,6 +5,8 @@ import {
5
5
  observable,
6
6
  } from 'mobx'
7
7
 
8
+ import type { VideoDef } from '@hanzo/ui/types'
9
+
8
10
  import type { Product, LineItem } from '../../../types'
9
11
 
10
12
  interface ActualLineItemSnapshot {
@@ -30,6 +32,8 @@ class ActualLineItem
30
32
  desc?: string
31
33
  price: number
32
34
  img?: string
35
+ video?: VideoDef
36
+ animation?: string
33
37
  timeAdded: number = 0 // timeAdded of being added to cart
34
38
 
35
39
  constructor(prod: Product, snap?: ActualLineItemSnapshot) {
@@ -41,10 +45,12 @@ class ActualLineItem
41
45
  this.desc = prod.desc
42
46
  this.price = prod.price
43
47
  this.img = prod.img
48
+ this.video = prod.video
49
+ this.animation = prod.animation
44
50
 
45
51
  if (snap) {
46
52
  this.qu = snap.quantity
47
- this.timeAdded = snap.quantity
53
+ this.timeAdded = snap.timeAdded
48
54
  }
49
55
 
50
56
  makeObservable(this, {
package/types/product.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { VideoDef } from '@hanzo/ui/types'
2
+
1
3
  interface Product {
2
4
  id: string // DB index // not a logical aspect of our domain. may not be necessary at all
3
5
  sku: string // human visible on orders etc.
@@ -8,6 +10,8 @@ interface Product {
8
10
  desc?: string
9
11
  price: number
10
12
  img?: string // if undefined: (category's img exists) ? (use it) : (use generic placeholder)
13
+ animation?: string // spline scene url
14
+ video?: VideoDef
11
15
  }
12
16
 
13
17
  export {
@@ -1,5 +1,5 @@
1
1
  //https://stefangabos.github.io/world_countries/
2
- export const countries = [
2
+ export default [
3
3
  {"id":4,"alpha2":"af","alpha3":"afg","name":"Afghanistan"},
4
4
  {"id":8,"alpha2":"al","alpha3":"alb","name":"Albania"},
5
5
  {"id":12,"alpha2":"dz","alpha3":"dza","name":"Algeria"},
@@ -1,217 +0,0 @@
1
- 'use client'
2
- import React from 'react'
3
-
4
- import type { UseFormReturn } from 'react-hook-form'
5
- // @ts-ignore
6
- import { ApplePay, GooglePay, CreditCard, PaymentForm } from 'react-square-web-payments-sdk'
7
-
8
- import { ApplyTypography, Button } from '@hanzo/ui/primitives'
9
-
10
- import { processSquareCardPayment } from '../../../util'
11
- import { useCommerce } from '../../../service/context'
12
- import type { TransactionStatus } from '../../../types'
13
-
14
- import PaymentMethods from './payment-methods'
15
- import ContactInfo from './contact-info'
16
- import { sendFBEvent, sendGAEvent } from '../../../util/analytics'
17
-
18
- const PayWithCard: React.FC<{
19
- setStep: (currentStep: number) => void
20
- transactionStatus: TransactionStatus
21
- setTransactionStatus: (status: TransactionStatus) => void
22
- storePaymentInfo: (paymentInfo: any) => Promise<void>
23
- contactForm: UseFormReturn<{
24
- name: string
25
- email: string
26
- }, any, {
27
- name: string
28
- email: string
29
- }>
30
- }> = ({
31
- setStep,
32
- transactionStatus,
33
- setTransactionStatus,
34
- storePaymentInfo,
35
- contactForm,
36
- }) => {
37
- const cmmc = useCommerce()
38
-
39
- const cardTokenizeResponseReceived = async (
40
- token: any,
41
- verifiedBuyer: any
42
- ) => {
43
- contactForm.handleSubmit(async () => {
44
- setTransactionStatus('paid')
45
- const res = await processSquareCardPayment(token.token, cmmc.cartTotal, verifiedBuyer.token)
46
- if (res) {
47
- console.log(token)
48
- await storePaymentInfo({paymentMethod: token.details.method ?? null, processed: res})
49
- setTransactionStatus('confirmed')
50
- sendGAEvent('purchase', {
51
- transaction_id: res.payment?.id,
52
- value: res.payment?.amountMoney?.amount,
53
- currency: res.payment?.amountMoney?.currency,
54
- items: cmmc.cartItems.map((item) => ({
55
- item_id: item.sku,
56
- item_name: item.title,
57
- item_category: item.categoryId,
58
- price: item.price,
59
- quantity: item.quantity
60
- })),
61
- })
62
- sendFBEvent('Purchase', {
63
- content_ids: cmmc.cartItems.map((item) => item.sku),
64
- contents: cmmc.cartItems.map(item => ({
65
- id: item.sku,
66
- quantity: item.quantity
67
- })),
68
- num_items: cmmc.cartItems.length,
69
- value: cmmc.cartTotal,
70
- currency: 'USD',
71
- })
72
- } else {
73
- setTransactionStatus('error')
74
- }
75
- })()
76
- }
77
-
78
- const createVerificationDetails = () => {
79
- const {name, email} = contactForm.getValues()
80
- return {
81
- amount: cmmc.cartTotal.toFixed(2),
82
- billingContact: {
83
- givenName: name,
84
- email,
85
- },
86
- currencyCode: 'USD',
87
- intent: 'CHARGE',
88
- }
89
- }
90
-
91
- const createPaymentRequest= () => ({
92
- countryCode: "US",
93
- currencyCode: "USD",
94
- lineItems: cmmc.cartItems.map(item => ({
95
- amount: item.price.toFixed(2),
96
- label: item.title,
97
- id: item.sku,
98
- })),
99
- requestBillingContact: false,
100
- requestShippingContact: false,
101
- total: {
102
- amount: cmmc.cartTotal.toFixed(2),
103
- label: "Total",
104
- },
105
- })
106
-
107
- return (
108
- <PaymentForm
109
- /**
110
- * Identifies the calling form with a verified application ID generated from
111
- * the Square Application Dashboard.
112
- */
113
- applicationId={process.env.NEXT_PUBLIC_SQUARE_APPLICATION_ID}
114
- /**
115
- * Invoked when payment form receives the result of a tokenize generation
116
- * request. The result will be a valid credit card or wallet token, or an error.
117
- */
118
- cardTokenizeResponseReceived={cardTokenizeResponseReceived}
119
- /**
120
- * This function enable the Strong Customer Authentication (SCA) flow
121
- *
122
- * We strongly recommend use this function to verify the buyer and reduce
123
- * the chance of fraudulent transactions.
124
- */
125
- createVerificationDetails={createVerificationDetails}
126
- /**
127
- * This function is required for digital wallets (Apple Pay, Google Pay)
128
- */
129
- createPaymentRequest={createPaymentRequest}
130
- /**
131
- * Identifies the location of the merchant that is taking the payment.
132
- * Obtained from the Square Application Dashboard - Locations tab.
133
- */
134
- locationId={process.env.NEXT_PUBLIC_SQUARE_LOCATION_ID}
135
- >
136
- <ApplyTypography className='flex flex-col gap-2 mt-6'>
137
- {transactionStatus === 'paid' ? (
138
- <h6 className='mx-auto font-nav'>Processing your payment...</h6>
139
- ) : transactionStatus === 'confirmed' ? (
140
- <div className='flex flex-col gap-4'>
141
- <h5 className='mx-auto font-nav'>Payment confirmed!</h5>
142
- <p className='mx-auto'>Thank you for your purchase.</p>
143
- <Button onClick={() => setStep(2)}>Continue</Button>
144
- </div>
145
- ) : (
146
- <>
147
- <GooglePay/>
148
- <ApplePay/>
149
-
150
- <div className='flex gap-2 whitespace-nowrap items-center my-6 sm:my-10 text-sm text-foreground/60'>
151
- <hr className='bg-foreground/60 w-full border'/> or pay with card <hr className='bg-foreground/60 w-full border'/>
152
- </div>
153
-
154
- <ContactInfo form={contactForm}/>
155
-
156
- <PaymentMethods/>
157
-
158
- {/* Imitates hanzo/ui Button and Input styles, I was unable to render the
159
- hanzo/ui button outright and keeping the submit form functionality*/}
160
- <CreditCard
161
- style={{
162
- '.input-container': {
163
- borderColor: '#404040',
164
- borderRadius: '6px',
165
- },
166
- '.input-container.is-focus': {
167
- borderColor: '#ffffff',
168
- },
169
- '.input-container.is-error': {
170
- borderColor: '#ff1600',
171
- },
172
- '.message-text': {
173
- color: '#999999',
174
- },
175
- '.message-icon': {
176
- color: '#999999',
177
- },
178
- '.message-text.is-error': {
179
- color: '#ff1600',
180
- },
181
- '.message-icon.is-error': {
182
- color: '#ff1600',
183
- },
184
- input: {
185
- backgroundColor: '#1f1f1f',
186
- color: '#FFFFFF',
187
- },
188
- 'input::placeholder': {
189
- color: '#999999',
190
- },
191
- 'input.is-error': {
192
- color: '#ff1600',
193
- },
194
- }}
195
- buttonProps={{
196
- className: 'font-nav h-10',
197
- css: {
198
- backgroundColor: '#fff',
199
- color: '#000',
200
- padding: 0,
201
- '&:hover': {
202
- backgroundColor: '#ffffffd9',
203
- },
204
- },
205
- }}
206
- />
207
- {transactionStatus === 'error' && (
208
- <p className='mx-auto text-destructive'>There was an error processing your payment.</p>
209
- )}
210
- </>
211
- )}
212
- </ApplyTypography>
213
- </PaymentForm>
214
- )
215
- }
216
-
217
- export default PayWithCard
@@ -1,30 +0,0 @@
1
- import React from 'react'
2
-
3
- import { Separator } from '@hanzo/ui/primitives'
4
- import { cn } from '@hanzo/ui/util'
5
-
6
- import type { CheckoutSteps } from './step'
7
-
8
- const StepIndicator: React.FC<{
9
- steps: CheckoutSteps
10
- currentStep: number
11
- className?: string
12
- }> = ({
13
- steps,
14
- currentStep,
15
- className=''
16
- }) => (
17
- <div className={className}>
18
- {Object.keys(steps).map((key, index) => (<>
19
- {index !== 0 && (<Separator className='w-[4rem] sm:w-[6rem]'/>)}
20
- <div className={cn(
21
- 'w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center',
22
- currentStep === parseInt(key) ? 'bg-foreground text-muted-4' : ''
23
- )}>
24
- <div className='relative text-foreground top-4 h-0 whitespace-nowrap'>{steps[parseInt(key)].label}</div>
25
- </div>
26
- </>))}
27
- </div>
28
- )
29
-
30
- export default StepIndicator
@@ -1,11 +0,0 @@
1
- interface CheckoutStep {
2
- label: string
3
- element: JSX.Element
4
- }
5
-
6
- type CheckoutSteps = Record<number, CheckoutStep>
7
-
8
- export {
9
- type CheckoutStep,
10
- type CheckoutSteps
11
- }