dotnet new sln
dotnet new webapi -o API
dotnet sln add API
dotnet new gitignore
- Install packages
cd API
dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
- Connect DB to App
- Create DbContext (StoreContext.cs)
- Get ConnectionStrings, add it to appsettings.json & inject it to Startup.cs
- Create Products table: Create Product Model & add it to DbContext
- Migrations
dotnet ef migrations add InitialCreate -o Data/Migrations
dotnet ef database update
Ctrl + P, > SQLite: Open database
- Auto create table from Migrations & Seed database
dotnet ef database drop
dotnet watch run
npx create-react-app client --template typescript --use-npm
File structure: Grouping by features https://reactjs.org/docs/faq-structure.html
- Install packages
cd API
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore
- Init data and register services in Startup.cs
- Create roles
- Create users
- Migrations and auto create Identity tables with Init data
dotnet ef migrations add IdentityAdded
dotnet watch run
- When user click Checkout => call API to create or update Payment Intent
- BE save payment intent id & client secret
- Check https://dashboard.stripe.com/ => created a payment (incomplete status)
- When user input card info & click pay => call stripe.confirmCardPayment(clientSecret) => return resultPayment => if succeeded, call API to create Order
- Although created Order, but it's status is still Pending. For secure, we shouldn't trust user. We need a confirmation from Stripe to BE, then BE will update the order's status to ReceivedPayment.
- How to implement this process? => using webhook
- Implement Webhook
- Install Stripe CLI for server
- Run
stripe listen
to getWhSecret
from Stripe - Create webhook API to receive event from Stripe by
WhSecret
- Run cmd:
stripe listen -f http://localhost:5000/api/payments/webhook -e payment_intent.succeeded
- Install
Heroku Postgres
in Resources - Add webhook endpoint for Stripe
https://tuong-restore.herokuapp.com/api/payments/webhook
-payment_intent.succeeded
=> getSigning secret = WhSecret
- Add all config for Heroku:
- StripeSettings:PublishableKey
- StripeSettings:SecretKey
- StripeSettings:WhSecret
- JWTSettings:TokenKey
- ASPNETCORE_ENVIRONMENT
- Install buildpack & push code
heroku login
heroku git:remote -a tuong-restore
heroku buildpacks:set jincod/dotnetcore
git push heroku master