From ac87c673dcaf9b31e8df833e7483be04fe8dea7e Mon Sep 17 00:00:00 2001 From: kjarret Date: Thu, 18 Jul 2024 12:22:09 +0200 Subject: [PATCH 1/3] feat(backend): :sparkles: Modify quantity of product --- backend/src/index.ts | 3 +-- backend/src/resolvers/checkout.resolver.ts | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 46e1352..3c864a5 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,10 +1,9 @@ import { ApolloServer } from "@apollo/server"; import { startStandaloneServer } from "@apollo/server/standalone"; +import * as jwt from "jsonwebtoken"; import { createClient } from "redis"; import "reflect-metadata"; import { buildSchema } from "type-graphql"; -// import { authChecker } from "./authChecker"; -import * as jwt from "jsonwebtoken"; import dataSource from "./config/datasource"; import { fillDatabaseIfEmpty } from "./fillDatabaseIfEmpty"; import { diff --git a/backend/src/resolvers/checkout.resolver.ts b/backend/src/resolvers/checkout.resolver.ts index c686e1c..7c27f2f 100644 --- a/backend/src/resolvers/checkout.resolver.ts +++ b/backend/src/resolvers/checkout.resolver.ts @@ -19,10 +19,17 @@ export default class CheckoutResolver { }, unit_amount: product.price * 100, }, + adjustable_quantity: { + enabled: true, + minimum: 1, + maximum: 6, + }, quantity: product.quantity, })), mode: "payment", success_url: "http://localhost:3000/stripe/success", + /* success_url: + "http://localhost:3000/stripe/success?session_id={CHECKOUT_SESSION_ID}", */ cancel_url: "http://localhost:3000/cart", }); return session.url; From 80656db4835054598ee1a208833e78fe74e9501b Mon Sep 17 00:00:00 2001 From: kjarret Date: Fri, 19 Jul 2024 12:39:57 +0200 Subject: [PATCH 2/3] feat: :closed_lock_with_key: Secrure stripe API key in env file and change style to cart page --- .env.apikey | 1 + .gitignore | 1 + backend/src/index.ts | 6 +-- docker-compose.yml | 8 ++-- frontend/src/components/Cart/CartPage.tsx | 49 +++++++++++++++----- frontend/src/components/Cart/CartProduct.tsx | 6 +-- 6 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 .env.apikey diff --git a/.env.apikey b/.env.apikey new file mode 100644 index 0000000..1a75eeb --- /dev/null +++ b/.env.apikey @@ -0,0 +1 @@ +STRIPE_SECRET_KEY="sk_test_51PYlpd2KBZ2YS4BjeFMlbIdT5tgEyGNqXdeJXwLfNNbSgL8rXd5Ck9KXdSsmsQAjj1NRXQ51QO3u7BFArYUEUhtD00FG9edf3A" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 577729f..3d79dfa 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ node_modules /blob-report/ /playwright/.cache/ .env +.env.apikey logs # Fait référence aux logs générés par le service ou container gateway (nginx) diff --git a/backend/src/index.ts b/backend/src/index.ts index 3c864a5..091b795 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -13,9 +13,9 @@ import { UserResolver, } from "./resolvers"; -export const stripe = require("stripe")( - "sk_test_51PYlpd2KBZ2YS4BjFB7Un6zLAG21R4hWvzlu4hMKBxRkWvn2Ubg3opMn7fq6CeDLguzWQJ15XpqcK8A4ggUhRoGt00IsQN786f" -); +require("dotenv").config(); + +export const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY); export const redisClient = createClient({ url: "redis://redis", diff --git a/docker-compose.yml b/docker-compose.yml index 498454a..f0cf94b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ services: - backend: - build: + build: context: ./backend # Fait référence au fichier nommé DockerFile par défaut du répertoire courant. Exécute les instructions à l'intérieur. dockerfile: Dockerfile # Indication explicite que l'on cible le fichier nommé Dockerfile. ports: @@ -13,12 +12,13 @@ services: interval: 5s timeout: 5s retries: 10 + env_file: .env.apikey depends_on: db: condition: service_healthy frontend: - build: + build: context: ./frontend # Fait référence au fichier nommé DockerFile par défaut du répertoire courant. Exécute les instructions à l'intérieur. dockerfile: Dockerfile # Indication explicite que l'on cible le fichier nommé Dockerfile. restart: always @@ -52,7 +52,7 @@ services: imagesupload: build: ./imagesupload - # build: + # build: # context: ./imagesupload # dockerfile: Dockerfile volumes: diff --git a/frontend/src/components/Cart/CartPage.tsx b/frontend/src/components/Cart/CartPage.tsx index 0cc1d04..f80cbb8 100644 --- a/frontend/src/components/Cart/CartPage.tsx +++ b/frontend/src/components/Cart/CartPage.tsx @@ -14,20 +14,45 @@ const CartPage = () => { }; return ( -
-

Mon Panier

+
{cart.length === 0 ? ( -

Votre panier est vide.

+ + + + + + + + + + + +
+ Mon Panier +
+ Votre panier est vide. +
) : ( -
- {cart.map((product) => ( - - ))} -
+
+ + + + + + + + {cart.map((product) => ( + + + + ))} + +
+ Mon Panier +
+ +
+
); From 22e51df5bdb93b26e28592453fc4277628cd1e05 Mon Sep 17 00:00:00 2001 From: kjarret Date: Fri, 19 Jul 2024 12:50:43 +0200 Subject: [PATCH 3/3] Stop tracking .env.apikey --- .env.apikey | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .env.apikey diff --git a/.env.apikey b/.env.apikey deleted file mode 100644 index 1a75eeb..0000000 --- a/.env.apikey +++ /dev/null @@ -1 +0,0 @@ -STRIPE_SECRET_KEY="sk_test_51PYlpd2KBZ2YS4BjeFMlbIdT5tgEyGNqXdeJXwLfNNbSgL8rXd5Ck9KXdSsmsQAjj1NRXQ51QO3u7BFArYUEUhtD00FG9edf3A" \ No newline at end of file