| > | > | ||||
| Order Summary | Order Summary | ||||
| </Typography> | </Typography> | ||||
| <Typography sx={{ mt: 4 }}>Items total:${data.totalPrice}</Typography> | |||||
| <Typography sx={{ mt: 4 }}> | |||||
| Items total:${data.totalPrice.toFixed(2)} | |||||
| </Typography> | |||||
| <Typography sx={{ mt: 1.5 }}>Shipping Costs: FREE</Typography> | <Typography sx={{ mt: 1.5 }}>Shipping Costs: FREE</Typography> | ||||
| <Typography sx={{ mt: 1.5, mb: 1.5 }}> | <Typography sx={{ mt: 1.5, mb: 1.5 }}> | ||||
| Total: ${data.totalPrice} | |||||
| Total: ${data.totalPrice.toFixed(2)} | |||||
| </Typography> | </Typography> | ||||
| <Divider /> | <Divider /> | ||||
| <Box sx={{ textAlign: 'center', mt: 4, width: '100%' }}> | <Box sx={{ textAlign: 'center', mt: 4, width: '100%' }}> |
| import ProductImage from './ProductImage'; | import ProductImage from './ProductImage'; | ||||
| import ProductInfo from './ProductInfo'; | import ProductInfo from './ProductInfo'; | ||||
| const FeaturedProduct = ({ product, bColor, image, side }) => { | |||||
| const FeaturedProduct = ({ product, bColor, side }) => { | |||||
| const matches = useMediaQuery('(min-width: 900px)'); | const matches = useMediaQuery('(min-width: 900px)'); | ||||
| const data = { name: product.name, description: product.description }; | const data = { name: product.name, description: product.description }; | ||||
| const { addCartValue } = useStoreUpdate(); | const { addCartValue } = useStoreUpdate(); | ||||
| sx={{ display: { md: 'flex' }, alignItems: { md: 'center' } }} | sx={{ display: { md: 'flex' }, alignItems: { md: 'center' } }} | ||||
| > | > | ||||
| {side === 'left' ? ( | {side === 'left' ? ( | ||||
| <ProductImage image={image}></ProductImage> | |||||
| <ProductImage image={product.image}></ProductImage> | |||||
| ) : !matches ? ( | ) : !matches ? ( | ||||
| <ProductImage image={image}></ProductImage> | |||||
| <ProductImage image={product.image}></ProductImage> | |||||
| ) : ( | ) : ( | ||||
| <ProductInfo | <ProductInfo | ||||
| bColor={bColor} | bColor={bColor} | ||||
| inCart={inCart} | inCart={inCart} | ||||
| ></ProductInfo> | ></ProductInfo> | ||||
| ) : ( | ) : ( | ||||
| <ProductImage image={image}></ProductImage> | |||||
| <ProductImage image={product.image}></ProductImage> | |||||
| )} | )} | ||||
| </Container> | </Container> | ||||
| </Box> | </Box> | ||||
| customID: PropType.string, | customID: PropType.string, | ||||
| }), | }), | ||||
| bColor: PropType.string, | bColor: PropType.string, | ||||
| image: PropType.string, | |||||
| side: PropType.string, | side: PropType.string, | ||||
| }; | }; | ||||
| export default FeaturedProduct; | export default FeaturedProduct; |
| key={i} | key={i} | ||||
| product={product} | product={product} | ||||
| bColor={i % 2 === 0 ? 'dark' : 'light'} | bColor={i % 2 === 0 ? 'dark' : 'light'} | ||||
| image="/images/Item 2.png" | |||||
| side={i % 2 === 0 ? 'left' : 'right'} | side={i % 2 === 0 ? 'left' : 'right'} | ||||
| ></FeaturedProduct> | ></FeaturedProduct> | ||||
| ); | ); |
| }} | }} | ||||
| > | > | ||||
| <Typography sx={{ fontSize: 18, fontWeight: 600 }}> | <Typography sx={{ fontSize: 18, fontWeight: 600 }}> | ||||
| Total: ${orderData?.totalPrice} | |||||
| Total: ${orderData?.totalPrice.toFixed(2)} | |||||
| </Typography> | </Typography> | ||||
| </Box> | </Box> | ||||
| </Grid> | </Grid> |
| handleClose(); | handleClose(); | ||||
| }; | }; | ||||
| console.log(checkoutStorage); | |||||
| const handleStripePayment = () => { | const handleStripePayment = () => { | ||||
| stripe({ | stripe({ | ||||
| lineItems: [ | |||||
| { | |||||
| price: 'price_1Lg4MsDY7dvAcw2f1CGQaFFR', | |||||
| quantity: 1, | |||||
| }, | |||||
| ], | |||||
| lineItems: checkoutStorage.products.map((el) => ({ | |||||
| price: el.product.stripeID, | |||||
| quantity: el.quantity, | |||||
| })), | |||||
| userInfo: checkoutStorage.userInfo, | |||||
| }); | }); | ||||
| setCookie(null, 'review-session', 'active', { | setCookie(null, 'review-session', 'active', { | ||||
| maxAge: 3600, | maxAge: 3600, |
| import { loadStripe } from '@stripe/stripe-js'; | import { loadStripe } from '@stripe/stripe-js'; | ||||
| export const useStripe = async ({ lineItems }) => { | |||||
| export const useStripe = async ({ lineItems, userInfo }) => { | |||||
| let stripePromise = null; | let stripePromise = null; | ||||
| const getStripe = () => { | const getStripe = () => { | ||||
| await stripe.redirectToCheckout({ | await stripe.redirectToCheckout({ | ||||
| mode: 'payment', | mode: 'payment', | ||||
| customer_email: userInfo.email, | |||||
| metadata: { | |||||
| name: userInfo.fullName, | |||||
| address: userInfo.address, | |||||
| addressLine2: userInfo.address2, | |||||
| city: userInfo.city, | |||||
| country: userInfo.country, | |||||
| postcode: userInfo.postcode, | |||||
| }, | |||||
| lineItems, | lineItems, | ||||
| successUrl: `${window.location.origin}/review`, | successUrl: `${window.location.origin}/review`, | ||||
| cancelUrl: `${window.location.origin}/cart`, | cancelUrl: `${window.location.origin}/cart`, |
| required: [true, 'Please provide a custom id.'], | required: [true, 'Please provide a custom id.'], | ||||
| unique: [true, 'Custom id must be unique'], | unique: [true, 'Custom id must be unique'], | ||||
| }, | }, | ||||
| stripeID: { | |||||
| type: String, | |||||
| required: [true, 'Please provide a stripe id.'], | |||||
| unique: [true, 'Stripe id must be unique'], | |||||
| }, | |||||
| }); | }); | ||||
| const Product = | const Product = |