Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version

This commit is contained in:
MarcEricMartel 2022-12-09 17:32:45 -08:00
commit 36d34968fd
11 changed files with 1630 additions and 93 deletions

View File

@ -173,7 +173,8 @@ public class InvoiceController : Controller {
Phone = sinv.Phone, Phone = sinv.Phone,
Email = sinv.Email, Email = sinv.Email,
Description = sinv.Description, Description = sinv.Description,
CurrencyCode = sinv.CurrencyCode CurrencyCode = sinv.CurrencyCode,
LastFourDigits = sinv.LastFourDigits,
}; };
inv.Payment = chr; inv.Payment = chr;
@ -190,13 +191,6 @@ public class InvoiceController : Controller {
if (charge.FailureMessage is not null && charge.FailureMessage != "") if (charge.FailureMessage is not null && charge.FailureMessage != "")
return Json(charge.ToJson()); return Json(charge.ToJson());
try {
_context.Invoices.Update(inv);
_context.SaveChanges();
} catch (Exception ex) {
_logger.LogError(20, ex.Message);
return BadRequest(ex.Message);
}
if (user.Result is not null) { // Gestion de l'adresse client. if (user.Result is not null) { // Gestion de l'adresse client.
inv.LinkedAccount = user.Result; inv.LinkedAccount = user.Result;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,195 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace GrossesMitainesAPI.Migrations
{
/// <inheritdoc />
public partial class newstuff : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "CardAddress",
table: "ChargesModel",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
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));
}
/// <inheritdoc />
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));
}
}
}

View File

@ -8,4 +8,5 @@ public class ChargeReturnModel {
public string Email { get; set; } public string Email { get; set; }
public string Phone { get; set; } public string Phone { get; set; }
public int Invoice { get; set; } public int Invoice { get; set; }
public string LastFourDigits { get; set; }
} }

View File

@ -11,4 +11,5 @@ public class ChargesModel {
public string Name { get; set; } public string Name { get; set; }
public string Email { get; set; } public string Email { get; set; }
public string Phone { get; set; } public string Phone { get; set; }
public string LastFourDigits { get; set; }
} }

View File

@ -35,4 +35,5 @@ namespace GrossesMitainesAPI.Models;
public string Name { get; set; } public string Name { get; set; }
public string Email { get; set; } public string Email { get; set; }
public string Phone { get; set; } public string Phone { get; set; }
public string LastFourDigits { get; set; }
} }

View File

@ -10,7 +10,7 @@
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=GrossesMitainesDB; Trusted_Connection=True; MultipleActiveResultSets=true" "DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=GrossesMitainesDB; Trusted_Connection=True; MultipleActiveResultSets=true"
}, },
"StripeTest": { "StripeTest": {
"PublicKey": "pk_test_", "PublicKey": "pk_test_51M8mzOEerenEZcQIUmJIrmsaZeeNlOil2G1JcMvvO68w50MJr8rDwUjVO44a8dDhSlsRH4GdzH9rDqtkg4Rtbzco00NqkHdn3H",
"SecretKey": "sk_test_" "SecretKey": "sk_test_51M8mzOEerenEZcQIyHb9AdeluhDsSy9PaxTeqDq6XUhSRCbbqvReHA2KoFb3a8Ru5PAzMgMlCKmj8UDpLKWzUUmr00rta511y8"
} }
} }

View File

@ -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 { CardElement, useElements, useStripe } from "@stripe/react-stripe-js"
import { Button } from "react-bootstrap" 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 = { const CARD_OPTIONS = {
iconStyle: "solid", 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 [cardName, setCardName] = useState("");
const [cardPhone,setCardPhone] = useState("");
const [cardEmail,setCardEmail] = useState("");
const [isLoading, setIsLoading] = useState(false);
const stripe = useStripe(); const stripe = useStripe();
const elements = useElements(); const elements = useElements();
const cart = useContext(CartContext);
const handleSubmit = async (e) => { const handleSubmit = async (e) => {
e.preventDefault(); e.preventDefault();
const { error, paymentMethod } = await stripe.createPaymentMethod({ setIsLoading(true);
const { error } = await stripe.createPaymentMethod({
type: "card", type: "card",
card: elements.getElement(CardElement) card: elements.getElement(CardElement)
}) })
@ -44,32 +56,54 @@ const PaymentForm = ({ cost }) => {
} }
if (!error) { 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 }); const json = JSON.stringify(invoice);
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);
})
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 { else {
console.log(error.message); console.log(error.message);
@ -80,24 +114,23 @@ const PaymentForm = ({ cost }) => {
return ( return (
<> <>
{!success ? {
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<fieldset className="FormGroup"> <fieldset className="FormGroup">
<input className="FormRow" placeholder="Cardholder Name" id="cardholder-name" type="text" value={cardName} onChange={e => setCardName(e.target.value)} /> <input className="FormRow cardholder-info" placeholder="Nom sur la carte" id="cardholder-name" type="text" value={cardName} onChange={e => setCardName(e.target.value)} />
<input className="FormRow cardholder-info" placeholder="Téléphone de facturation" id="cardholder-phone" type="text" value={cardPhone} onChange={e => setCardPhone(e.target.value)} />
<input className="FormRow cardholder-info" placeholder="Addresse courriel de facturation" id="cardholder-email" type="text" value={cardEmail} onChange={e => setCardEmail(e.target.value)} />
<div className="FormRow"> <div className="FormRow">
<CardElement options={CARD_OPTIONS} /> <CardElement options={CARD_OPTIONS} />
</div> </div>
</fieldset> </fieldset>
<div className="Payment-btn-container"> <div className="Payment-btn-container">
<Button className="Payment-btn" type="submit">Payer</Button> <Button className="Payment-btn" disabled={isLoading} type="submit">Payer</Button>
{
isLoading && <div>Paiement en cours...</div>
}
</div> </div>
</form> </form>
:
<div>
<h2>
L'achat s'est déroulé avec succès
</h2>
</div>
} }
</> </>
) )

View File

@ -7,10 +7,10 @@ const PUBLIC_KEY = "pk_test_51M8mzOEerenEZcQIUmJIrmsaZeeNlOil2G1JcMvvO68w50MJr8r
const stripeTestPromise = loadStripe(PUBLIC_KEY); const stripeTestPromise = loadStripe(PUBLIC_KEY);
const StripeContainer = ({cost}) => { const StripeContainer = ({cost, invoice}) => {
return ( return (
<Elements stripe={stripeTestPromise}> <Elements stripe={stripeTestPromise}>
<PaymentForm cost={cost}/> <PaymentForm cost={cost} invoice={invoice} />
</Elements> </Elements>
) )
} }

View File

@ -4,8 +4,6 @@ import ReviewProdList from "../components/ReviewProdList";
import TotalProductsPrice from "../components/TotalProductsPrice"; import TotalProductsPrice from "../components/TotalProductsPrice";
import { Row, Col, Button } from "react-bootstrap"; import { Row, Col, Button } from "react-bootstrap";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
import { CartContext } from "../components/Cart"; import { CartContext } from "../components/Cart";
import StripeContainer from "../components/StripeContainer" import StripeContainer from "../components/StripeContainer"
@ -13,7 +11,7 @@ const ReviewInvoice = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const mySwal = withReactContent(Swal);
const cart = useContext(CartContext); const cart = useContext(CartContext);
@ -90,41 +88,42 @@ const ReviewInvoice = () => {
navigate("/formulaire") navigate("/formulaire")
} }
const handleConfirmer = async () => {
const json = JSON.stringify(thisInvoice);
const response = await fetch(`https://localhost:7292/api/Invoice`, { // const handleConfirmer = async () => {
method: 'POST', // const json = JSON.stringify(thisInvoice);
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 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 ( return (
<> <>
@ -177,21 +176,21 @@ const ReviewInvoice = () => {
<TotalProductsPrice <TotalProductsPrice
/> />
</div> </div>
<Row className="invoice-buttons"> <Row className="invoice-buttons">
{/* <Col xs={6}> {/* <Col xs={6}>
<Button className="invoice-button confirmer" onClick={handleConfirmer}>Confirmer</Button> <Button className="invoice-button confirmer" onClick={handleConfirmer}>Confirmer</Button>
</Col> */} </Col> */}
<Col xs={12}> <Col xs={12}>
<Button className="invoice-button modifier" onClick={handleModify}>Modifier</Button> <Button className="invoice-button modifier" onClick={handleModify}>Modifier</Button>
</Col> </Col>
</Row> </Row>
</Col> </Col>
<Col xs={6} md={8}> <Col xs={6} md={8}>
<ReviewProdList <ReviewProdList
/> />
</Col> </Col>
</Row> </Row>
<StripeContainer cost={total} /> <StripeContainer cost={total} invoice={thisInvoice} />
</> </>
); );

View File

@ -39,7 +39,7 @@ a {
border-radius: 4px; border-radius: 4px;
} }
#cardholder-name { .cardholder-info {
background-color: transparent; background-color: transparent;
border:none; border:none;
color:white; color:white;