Paiement fonctionne

This commit is contained in:
Victor Turgeon 2022-12-08 20:27:06 -05:00
parent 10abe82b83
commit 4705da96db
9 changed files with 1562 additions and 39 deletions

View File

@ -173,7 +173,8 @@ public class InvoiceController : Controller {
Phone = sinv.Phone,
Email = sinv.Email,
Description = sinv.Description,
CurrencyCode = sinv.CurrencyCode
CurrencyCode = sinv.CurrencyCode,
LastFourDigits = sinv.LastFourDigits,
};
inv.Payment = chr;
@ -190,13 +191,6 @@ public class InvoiceController : Controller {
if (charge.FailureMessage is not null && charge.FailureMessage != "")
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.
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

@ -17,10 +17,10 @@ namespace GrossesMitainesAPI.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.10")
.HasAnnotation("ProductVersion", "7.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("GrossesMitainesAPI.Data.InventoryUser", b =>
{
@ -101,7 +101,7 @@ namespace GrossesMitainesAPI.Migrations
{
Id = "ecf7503a-591c-454e-a824-048e10bd0474",
AccessFailedCount = 0,
ConcurrencyStamp = "61f3249f-495f-48c8-ac7e-7d21b3da82c7",
ConcurrencyStamp = "10c22569-c9b6-481a-80b0-ada24d0ed3e3",
Email = "admin@admin.com",
EmailConfirmed = false,
FirstName = "Roger",
@ -109,10 +109,10 @@ namespace GrossesMitainesAPI.Migrations
LockoutEnabled = false,
NormalizedEmail = "ADMIN@ADMIN.COM",
NormalizedUserName = "ADMIN",
PasswordHash = "AQAAAAEAACcQAAAAELswgBNsSfJwmigdKX2rpHseOEi20F+ZUhxapu80HTnxZamC3lu1hyAGMXj4kQumMw==",
PasswordHash = "AQAAAAIAAYagAAAAEMFEklU5e/VioCDzfvR1Xf9WhF/UIsZpuI2q6ZL3m68YSyDEe9CyswhrRR3nmj5ylQ==",
PhoneNumber = "111-111-1111",
PhoneNumberConfirmed = false,
SecurityStamp = "3098997b-a081-41ec-aa08-6cdea0028db7",
SecurityStamp = "12a136a8-303d-4291-9746-bbc18705a483",
TwoFactorEnabled = false,
UserName = "Admin"
},
@ -120,7 +120,7 @@ namespace GrossesMitainesAPI.Migrations
{
Id = "af9178c8-1a02-4ff8-bc0a-c8248dad6e09",
AccessFailedCount = 0,
ConcurrencyStamp = "b7103a3b-8f05-462d-9fc0-5d4faa4669dc",
ConcurrencyStamp = "e00d8d0f-1510-415a-a59f-386072484ab2",
Email = "paul@exemple.com",
EmailConfirmed = false,
FirstName = "Paul",
@ -128,10 +128,10 @@ namespace GrossesMitainesAPI.Migrations
LockoutEnabled = false,
NormalizedEmail = "PAUL@EXEMPLE.COM",
NormalizedUserName = "PASLA",
PasswordHash = "AQAAAAEAACcQAAAAEN68b+gEQV5Vx2grBL94+BzugXFrgXko6KtdY3p/NJN17mk8QCpGlQfJ3BMe040+dg==",
PasswordHash = "AQAAAAIAAYagAAAAEGCyYq3h0iCXjZEzZyx1Jh4IwD6n76MXzopZNtCeBYcAr8rCBAQsgyb1KZINqIi2hA==",
PhoneNumber = "222-222-2222",
PhoneNumberConfirmed = false,
SecurityStamp = "99183d90-1f1c-4a8e-9891-ea8ab3b714d0",
SecurityStamp = "02115bbb-af11-4354-8fd3-d4c121238584",
TwoFactorEnabled = false,
UserName = "PasLa"
});
@ -143,7 +143,7 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Appartment")
.HasColumnType("nvarchar(max)");
@ -227,11 +227,15 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<long>("AmountInCents")
.HasColumnType("bigint");
b.Property<string>("CardAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("CurrencyCode")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -244,6 +248,10 @@ namespace GrossesMitainesAPI.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("LastFourDigits")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -267,7 +275,7 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("EmailAddress")
.IsRequired()
@ -321,7 +329,7 @@ namespace GrossesMitainesAPI.Migrations
LastName = "Admin",
LinkedAccountId = "ecf7503a-591c-454e-a824-048e10bd0474",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9261),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(8956),
ShippingAddressId = 1,
Status = 0
},
@ -333,7 +341,7 @@ namespace GrossesMitainesAPI.Migrations
LastName = "Admin",
LinkedAccountId = "ecf7503a-591c-454e-a824-048e10bd0474",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9300),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9034),
ShippingAddressId = 1,
Status = 1
},
@ -345,7 +353,7 @@ namespace GrossesMitainesAPI.Migrations
LastName = "Admin",
LinkedAccountId = "ecf7503a-591c-454e-a824-048e10bd0474",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9327),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9037),
ShippingAddressId = 1,
Status = 3
},
@ -357,7 +365,7 @@ namespace GrossesMitainesAPI.Migrations
LastName = "Admin",
LinkedAccountId = "ecf7503a-591c-454e-a824-048e10bd0474",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9333),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9039),
ShippingAddressId = 1,
Status = 4
},
@ -369,7 +377,7 @@ namespace GrossesMitainesAPI.Migrations
LastName = "Admin",
LinkedAccountId = "ecf7503a-591c-454e-a824-048e10bd0474",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9338),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9041),
ShippingAddressId = 1,
Status = 5
},
@ -380,7 +388,7 @@ namespace GrossesMitainesAPI.Migrations
FirstName = "Jérémy",
LastName = "Le Petit",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9344),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9043),
ShippingAddressId = 2,
Status = 0
},
@ -392,7 +400,7 @@ namespace GrossesMitainesAPI.Migrations
LastName = "A.",
LinkedAccountId = "af9178c8-1a02-4ff8-bc0a-c8248dad6e09",
PhoneNumber = "111-111-1111",
PurchaseDate = new DateTime(2022, 12, 4, 9, 8, 50, 6, DateTimeKind.Local).AddTicks(9357),
PurchaseDate = new DateTime(2022, 12, 8, 20, 10, 28, 658, DateTimeKind.Local).AddTicks(9055),
ShippingAddressId = 3,
Status = 3
});
@ -404,7 +412,7 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("InvoiceModelId")
.HasColumnType("int");
@ -558,7 +566,7 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Category")
.IsRequired()
@ -1057,14 +1065,12 @@ namespace GrossesMitainesAPI.Migrations
new
{
Id = "c9e08b20-d8a5-473f-9f52-572eb23c12af",
ConcurrencyStamp = "eac9c483-2e9f-4f9e-9b97-dc1c761f76c2",
Name = "Administrateur",
NormalizedName = "ADMINISTRATEUR"
},
new
{
Id = "1b7b9c55-c746-493a-a24f-3d5ca937298e",
ConcurrencyStamp = "fb8da1f2-a9df-4faa-9786-259cbc8c6f1c",
Name = "Client",
NormalizedName = "CLIENT"
});
@ -1076,7 +1082,7 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
@ -1101,7 +1107,7 @@ namespace GrossesMitainesAPI.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");

View File

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

View File

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

View File

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

View File

@ -34,12 +34,17 @@ const PaymentForm = ({ cost, invoice }) => {
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();
setIsLoading(true);
const { error } = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement)
@ -54,14 +59,14 @@ const PaymentForm = ({ cost, invoice }) => {
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 = invoice.emailAddress;
invoice.phone = invoice.phoneNumber;
invoice.email = cardEmail;
invoice.phone = cardPhone;
invoice.lastFourDigits = result.token.card.last4;
const json = JSON.stringify(invoice);
@ -83,7 +88,7 @@ const PaymentForm = ({ cost, invoice }) => {
}).then(
() => {
cart.emptyCart();
navigate('/morceaux');
navigate('/myInvoices');
}
);
}
@ -92,6 +97,8 @@ const PaymentForm = ({ cost, invoice }) => {
title: 'Erreur!',
timer: 2000,
icon: "error"
}).then(()=>{
setIsLoading(false);
});
}
});
@ -110,13 +117,18 @@ const PaymentForm = ({ cost, invoice }) => {
{
<form onSubmit={handleSubmit}>
<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">
<CardElement options={CARD_OPTIONS} />
</div>
</fieldset>
<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>
</form>
}

View File

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