(
+ name: "LastFourDigits",
+ table: "ChargesModel",
+ type: "nvarchar(max)",
+ nullable: false,
+ defaultValue: "");
+
+ migrationBuilder.UpdateData(
+ table: "AspNetRoles",
+ keyColumn: "Id",
+ keyValue: "1b7b9c55-c746-493a-a24f-3d5ca937298e",
+ column: "ConcurrencyStamp",
+ value: null);
+
+ migrationBuilder.UpdateData(
+ table: "AspNetRoles",
+ keyColumn: "Id",
+ keyValue: "c9e08b20-d8a5-473f-9f52-572eb23c12af",
+ column: "ConcurrencyStamp",
+ value: null);
+
+ migrationBuilder.UpdateData(
+ table: "AspNetUsers",
+ keyColumn: "Id",
+ keyValue: "af9178c8-1a02-4ff8-bc0a-c8248dad6e09",
+ columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
+ values: new object[] { "e00d8d0f-1510-415a-a59f-386072484ab2", "AQAAAAIAAYagAAAAEGCyYq3h0iCXjZEzZyx1Jh4IwD6n76MXzopZNtCeBYcAr8rCBAQsgyb1KZINqIi2hA==", "02115bbb-af11-4354-8fd3-d4c121238584" });
+
+ migrationBuilder.UpdateData(
+ table: "AspNetUsers",
+ keyColumn: "Id",
+ keyValue: "ecf7503a-591c-454e-a824-048e10bd0474",
+ columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
+ values: new object[] { "10c22569-c9b6-481a-80b0-ada24d0ed3e3", "AQAAAAIAAYagAAAAEMFEklU5e/VioCDzfvR1Xf9WhF/UIsZpuI2q6ZL3m68YSyDEe9CyswhrRR3nmj5ylQ==", "12a136a8-303d-4291-9746-bbc18705a483" });
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 1,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(8956));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 2,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9034));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 3,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9037));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 4,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9039));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 5,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9041));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 6,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9043));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 7,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9055));
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "CardAddress",
+ table: "ChargesModel");
+
+ migrationBuilder.DropColumn(
+ name: "LastFourDigits",
+ table: "ChargesModel");
+
+ migrationBuilder.UpdateData(
+ table: "AspNetRoles",
+ keyColumn: "Id",
+ keyValue: "1b7b9c55-c746-493a-a24f-3d5ca937298e",
+ column: "ConcurrencyStamp",
+ value: "fb8da1f2-a9df-4faa-9786-259cbc8c6f1c");
+
+ migrationBuilder.UpdateData(
+ table: "AspNetRoles",
+ keyColumn: "Id",
+ keyValue: "c9e08b20-d8a5-473f-9f52-572eb23c12af",
+ column: "ConcurrencyStamp",
+ value: "eac9c483-2e9f-4f9e-9b97-dc1c761f76c2");
+
+ migrationBuilder.UpdateData(
+ table: "AspNetUsers",
+ keyColumn: "Id",
+ keyValue: "af9178c8-1a02-4ff8-bc0a-c8248dad6e09",
+ columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
+ values: new object[] { "b7103a3b-8f05-462d-9fc0-5d4faa4669dc", "AQAAAAEAACcQAAAAEN68b+gEQV5Vx2grBL94+BzugXFrgXko6KtdY3p/NJN17mk8QCpGlQfJ3BMe040+dg==", "99183d90-1f1c-4a8e-9891-ea8ab3b714d0" });
+
+ migrationBuilder.UpdateData(
+ table: "AspNetUsers",
+ keyColumn: "Id",
+ keyValue: "ecf7503a-591c-454e-a824-048e10bd0474",
+ columns: new[] { "ConcurrencyStamp", "PasswordHash", "SecurityStamp" },
+ values: new object[] { "61f3249f-495f-48c8-ac7e-7d21b3da82c7", "AQAAAAEAACcQAAAAELswgBNsSfJwmigdKX2rpHseOEi20F+ZUhxapu80HTnxZamC3lu1hyAGMXj4kQumMw==", "3098997b-a081-41ec-aa08-6cdea0028db7" });
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 1,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9261));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 2,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9300));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 3,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9327));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 4,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9333));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 5,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9338));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 6,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9344));
+
+ migrationBuilder.UpdateData(
+ table: "Invoices",
+ keyColumn: "Id",
+ keyValue: 7,
+ column: "PurchaseDate",
+ value: new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9357));
+ }
+ }
+}
diff --git a/GrossesMitaines/GrossesMitainesAPI/Models/ChargeReturnModel.cs b/GrossesMitaines/GrossesMitainesAPI/Models/ChargeReturnModel.cs
index b594d91..17f9824 100644
--- a/GrossesMitaines/GrossesMitainesAPI/Models/ChargeReturnModel.cs
+++ b/GrossesMitaines/GrossesMitainesAPI/Models/ChargeReturnModel.cs
@@ -8,4 +8,5 @@ public class ChargeReturnModel {
public string Email { get; set; }
public string Phone { get; set; }
public int Invoice { get; set; }
+ public string LastFourDigits { get; set; }
}
diff --git a/GrossesMitaines/GrossesMitainesAPI/Models/ChargesModel.cs b/GrossesMitaines/GrossesMitainesAPI/Models/ChargesModel.cs
index f6dbb7e..23717a5 100644
--- a/GrossesMitaines/GrossesMitainesAPI/Models/ChargesModel.cs
+++ b/GrossesMitaines/GrossesMitainesAPI/Models/ChargesModel.cs
@@ -11,4 +11,5 @@ public class ChargesModel {
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
+ public string LastFourDigits { get; set; }
}
diff --git a/GrossesMitaines/GrossesMitainesAPI/Models/SendInvoiceModel.cs b/GrossesMitaines/GrossesMitainesAPI/Models/SendInvoiceModel.cs
index aa3cf68..a5c8988 100644
--- a/GrossesMitaines/GrossesMitainesAPI/Models/SendInvoiceModel.cs
+++ b/GrossesMitaines/GrossesMitainesAPI/Models/SendInvoiceModel.cs
@@ -35,4 +35,5 @@ namespace GrossesMitainesAPI.Models;
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
+ public string LastFourDigits { get; set; }
}
\ No newline at end of file
diff --git a/GrossesMitaines/GrossesMitainesAPI/appsettings.json b/GrossesMitaines/GrossesMitainesAPI/appsettings.json
index 0b2724c..b3afa36 100644
--- a/GrossesMitaines/GrossesMitainesAPI/appsettings.json
+++ b/GrossesMitaines/GrossesMitainesAPI/appsettings.json
@@ -10,7 +10,7 @@
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=GrossesMitainesDB; Trusted_Connection=True; MultipleActiveResultSets=true"
},
"StripeTest": {
- "PublicKey": "pk_test_",
- "SecretKey": "sk_test_"
+ "PublicKey": "pk_test_51M8mzOEerenEZcQIUmJIrmsaZeeNlOil2G1JcMvvO68w50MJr8rDwUjVO44a8dDhSlsRH4GdzH9rDqtkg4Rtbzco00NqkHdn3H",
+ "SecretKey": "sk_test_51M8mzOEerenEZcQIyHb9AdeluhDsSy9PaxTeqDq6XUhSRCbbqvReHA2KoFb3a8Ru5PAzMgMlCKmj8UDpLKWzUUmr00rta511y8"
}
}
diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/PaymentForm.js b/GrossesMitaines/grosses-mitaines-ui/src/components/PaymentForm.js
index d339d67..e8e045a 100644
--- a/GrossesMitaines/grosses-mitaines-ui/src/components/PaymentForm.js
+++ b/GrossesMitaines/grosses-mitaines-ui/src/components/PaymentForm.js
@@ -1,6 +1,11 @@
-import React, { useState } from "react"
+import React, { useState, useContext } from "react"
import { CardElement, useElements, useStripe } from "@stripe/react-stripe-js"
import { Button } from "react-bootstrap"
+import Swal from "sweetalert2";
+import withReactContent from "sweetalert2-react-content";
+import { CartContext } from "../components/Cart";
+import { useNavigate } from "react-router-dom";
+
const CARD_OPTIONS = {
iconStyle: "solid",
@@ -24,16 +29,23 @@ const CARD_OPTIONS = {
-const PaymentForm = ({ cost }) => {
+const PaymentForm = ({ cost, invoice }) => {
+ const navigate = useNavigate();
- const [success, setSuccess] = useState(false);
+ const mySwal = withReactContent(Swal);
const [cardName, setCardName] = useState("");
+ const [cardPhone,setCardPhone] = useState("");
+ const [cardEmail,setCardEmail] = useState("");
+ const [isLoading, setIsLoading] = useState(false);
+
const stripe = useStripe();
const elements = useElements();
+ const cart = useContext(CartContext);
const handleSubmit = async (e) => {
e.preventDefault();
- const { error, paymentMethod } = await stripe.createPaymentMethod({
+ setIsLoading(true);
+ const { error } = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement)
})
@@ -44,32 +56,54 @@ const PaymentForm = ({ cost }) => {
}
if (!error) {
- const { id } = paymentMethod;
+ stripe.createToken(elements.getElement(CardElement), { name: cardName })
+ .then((result) => {
+ if (!result.error) {
+ invoice.token = result.token.id;
+ invoice.description = `Payement de ${cost} à GM`;
+ invoice.amountInCents = cost;
+ invoice.currencyCode = "CAD";
+ invoice.name = cardName;
+ invoice.email = cardEmail;
+ invoice.phone = cardPhone;
+ invoice.lastFourDigits = result.token.card.last4;
- const json = JSON.stringify({ amount: cost, stripeId: id });
-
-
- fetch(`https://localhost:7292/api/Payment`, {
- method: 'POST',
- credentials: 'include',
- mode: 'cors',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: json
- }).then((response) => {
- if (response.ok) {
- console.log("Successful payment");
- setSuccess(true);
- }
- else {
- console.log(response);
- }
- }).catch((error) => {
- console.log("Error: ", error);
- })
+ const json = JSON.stringify(invoice);
+ fetch(`https://localhost:7292/api/Invoice`, {
+ method: 'POST',
+ credentials: 'include',
+ mode: 'cors',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ body: json
+ }).then((response) => {
+ if (response.ok) {
+ mySwal.fire({
+ title: 'Commande envoyée avec succès!',
+ timer: 2000,
+ icon: "success"
+ }).then(
+ () => {
+ cart.emptyCart();
+ navigate('/myInvoices');
+ }
+ );
+ }
+ else {
+ mySwal.fire({
+ title: 'Erreur!',
+ timer: 2000,
+ icon: "error"
+ }).then(()=>{
+ setIsLoading(false);
+ });
+ }
+ });
+ }
+ });
}
else {
console.log(error.message);
@@ -80,24 +114,23 @@ const PaymentForm = ({ cost }) => {
return (
<>
- {!success ?
+ {
- :
-
-
- L'achat s'est déroulé avec succès
-
-
}
>
)
diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/StripeContainer.js b/GrossesMitaines/grosses-mitaines-ui/src/components/StripeContainer.js
index c5d2b93..ffec286 100644
--- a/GrossesMitaines/grosses-mitaines-ui/src/components/StripeContainer.js
+++ b/GrossesMitaines/grosses-mitaines-ui/src/components/StripeContainer.js
@@ -7,10 +7,10 @@ const PUBLIC_KEY = "pk_test_51M8mzOEerenEZcQIUmJIrmsaZeeNlOil2G1JcMvvO68w50MJr8r
const stripeTestPromise = loadStripe(PUBLIC_KEY);
-const StripeContainer = ({cost}) => {
+const StripeContainer = ({cost, invoice}) => {
return (
-
+
)
}
diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js
index c7c79db..d855385 100644
--- a/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js
+++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/ReviewInvoice.js
@@ -4,8 +4,6 @@ import ReviewProdList from "../components/ReviewProdList";
import TotalProductsPrice from "../components/TotalProductsPrice";
import { Row, Col, Button } from "react-bootstrap";
import { useNavigate } from "react-router-dom";
-import Swal from "sweetalert2";
-import withReactContent from "sweetalert2-react-content";
import { CartContext } from "../components/Cart";
import StripeContainer from "../components/StripeContainer"
@@ -13,7 +11,7 @@ const ReviewInvoice = () => {
const navigate = useNavigate();
- const mySwal = withReactContent(Swal);
+
const cart = useContext(CartContext);
@@ -90,41 +88,42 @@ const ReviewInvoice = () => {
navigate("/formulaire")
}
- const handleConfirmer = async () => {
- const json = JSON.stringify(thisInvoice);
- const response = await fetch(`https://localhost:7292/api/Invoice`, {
- method: 'POST',
- credentials: 'include',
- mode: 'cors',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: json
- })
- if (response.ok) {
- mySwal.fire({
- title: 'Commande envoyée avec succès!',
- timer: 2000,
- icon: "success"
- }).then(
- () => {
- cart.emptyCart();
- navigate('/morceaux');
- }
- )
- }
- else {
- console.log("Erreur de creation la commande #" + thisInvoice.id);
- mySwal.fire({
- title: 'Erreur!',
- timer: 2000,
- icon: "error"
- })
- }
+ // const handleConfirmer = async () => {
+ // const json = JSON.stringify(thisInvoice);
- }
+ // const response = await fetch(`https://localhost:7292/api/Invoice`, {
+ // method: 'POST',
+ // credentials: 'include',
+ // mode: 'cors',
+ // headers: {
+ // 'Accept': 'application/json',
+ // 'Content-Type': 'application/json'
+ // },
+ // body: json
+ // })
+ // if (response.ok) {
+ // mySwal.fire({
+ // title: 'Commande envoyée avec succès!',
+ // timer: 2000,
+ // icon: "success"
+ // }).then(
+ // () => {
+ // cart.emptyCart();
+ // navigate('/morceaux');
+ // }
+ // )
+ // }
+ // else {
+ // console.log("Erreur de creation la commande #" + thisInvoice.id);
+ // mySwal.fire({
+ // title: 'Erreur!',
+ // timer: 2000,
+ // icon: "error"
+ // })
+ // }
+
+ // }
return (
<>
@@ -177,21 +176,21 @@ const ReviewInvoice = () => {
-
- {/*
+
+ {/*
*/}
-
-
-
-
+
+
+
+
-
+
>
);
diff --git a/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css b/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css
index 5ecd3f4..687381a 100644
--- a/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css
+++ b/GrossesMitaines/grosses-mitaines-ui/src/stylesheets/site.css
@@ -39,7 +39,7 @@ a {
border-radius: 4px;
}
-#cardholder-name {
+.cardholder-info {
background-color: transparent;
border:none;
color:white;