Przeglądaj źródła

feat: stripe with real products

products-stripe
ntasicc 3 lat temu
rodzic
commit
c99d3a7aae

+ 4
- 2
components/cards/order-summary-card/OrderSummaryCard.jsx Wyświetl plik

@@ -22,10 +22,12 @@ const OrderSummaryCard = ({ data }) => {
>
Order Summary
</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, mb: 1.5 }}>
Total: ${data.totalPrice}
Total: ${data.totalPrice.toFixed(2)}
</Typography>
<Divider />
<Box sx={{ textAlign: 'center', mt: 4, width: '100%' }}>

+ 4
- 5
components/products/featured-product/FeaturedProduct.jsx Wyświetl plik

@@ -6,7 +6,7 @@ import { useStore, useStoreUpdate } from '../../../store/cart-context';
import ProductImage from './ProductImage';
import ProductInfo from './ProductInfo';

const FeaturedProduct = ({ product, bColor, image, side }) => {
const FeaturedProduct = ({ product, bColor, side }) => {
const matches = useMediaQuery('(min-width: 900px)');
const data = { name: product.name, description: product.description };
const { addCartValue } = useStoreUpdate();
@@ -34,9 +34,9 @@ const FeaturedProduct = ({ product, bColor, image, side }) => {
sx={{ display: { md: 'flex' }, alignItems: { md: 'center' } }}
>
{side === 'left' ? (
<ProductImage image={image}></ProductImage>
<ProductImage image={product.image}></ProductImage>
) : !matches ? (
<ProductImage image={image}></ProductImage>
<ProductImage image={product.image}></ProductImage>
) : (
<ProductInfo
bColor={bColor}
@@ -63,7 +63,7 @@ const FeaturedProduct = ({ product, bColor, image, side }) => {
inCart={inCart}
></ProductInfo>
) : (
<ProductImage image={image}></ProductImage>
<ProductImage image={product.image}></ProductImage>
)}
</Container>
</Box>
@@ -86,7 +86,6 @@ FeaturedProduct.propTypes = {
customID: PropType.string,
}),
bColor: PropType.string,
image: PropType.string,
side: PropType.string,
};
export default FeaturedProduct;

+ 0
- 1
components/products/featured-products-list/FeaturedPorductsList.jsx Wyświetl plik

@@ -17,7 +17,6 @@ const FeaturedProductsList = ({ featuredProducts }) => {
key={i}
product={product}
bColor={i % 2 === 0 ? 'dark' : 'light'}
image="/images/Item 2.png"
side={i % 2 === 0 ? 'left' : 'right'}
></FeaturedProduct>
);

+ 1
- 1
components/review-content/ReviewContent.jsx Wyświetl plik

@@ -124,7 +124,7 @@ const ReviewContent = () => {
}}
>
<Typography sx={{ fontSize: 18, fontWeight: 600 }}>
Total: ${orderData?.totalPrice}
Total: ${orderData?.totalPrice.toFixed(2)}
</Typography>
</Box>
</Grid>

+ 6
- 6
components/shipping-content/ShippingContent.jsx Wyświetl plik

@@ -35,14 +35,14 @@ const ShippingContent = () => {
handleClose();
};

console.log(checkoutStorage);
const handleStripePayment = () => {
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', {
maxAge: 3600,

+ 10
- 1
hooks/use-stripe.js Wyświetl plik

@@ -1,6 +1,6 @@
import { loadStripe } from '@stripe/stripe-js';

export const useStripe = async ({ lineItems }) => {
export const useStripe = async ({ lineItems, userInfo }) => {
let stripePromise = null;

const getStripe = () => {
@@ -14,6 +14,15 @@ export const useStripe = async ({ lineItems }) => {

await stripe.redirectToCheckout({
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,
successUrl: `${window.location.origin}/review`,
cancelUrl: `${window.location.origin}/cart`,

+ 5
- 0
models/product.js Wyświetl plik

@@ -60,6 +60,11 @@ const ProductSchema = new mongoose.Schema({
required: [true, 'Please provide a custom id.'],
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 =

Ładowanie…
Anuluj
Zapisz