Просмотр исходного кода

feat: stripe with real products

products-stripe
ntasicc 3 лет назад
Родитель
Сommit
c99d3a7aae

+ 4
- 2
components/cards/order-summary-card/OrderSummaryCard.jsx Просмотреть файл

> >
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%' }}>

+ 4
- 5
components/products/featured-product/FeaturedProduct.jsx Просмотреть файл

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;

+ 0
- 1
components/products/featured-products-list/FeaturedPorductsList.jsx Просмотреть файл

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>
); );

+ 1
- 1
components/review-content/ReviewContent.jsx Просмотреть файл

}} }}
> >
<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>

+ 6
- 6
components/shipping-content/ShippingContent.jsx Просмотреть файл

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,

+ 10
- 1
hooks/use-stripe.js Просмотреть файл

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`,

+ 5
- 0
models/product.js Просмотреть файл

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 =

Загрузка…
Отмена
Сохранить