The Payment Gateway API provides merchant to process payment on customer. API accepts credit card data such as credit number, Cvv, expiry month and year. There are 4 endpoints
1. Authorize
2. Capture
3. Refund
4. Void
- Only In-Memory data store has been used. For production purpose that can be replaced by using SQL Server. This can be achieved by updating connection string in appsettings.json. This is already setup in Startup.cs
- Implemented minimum validation to avoid complexity
- Authorization Edge case is implemented by using hard coded BlackListCard list
- For Capture Edge Case seed method is used to save customer and transactionId
bc97198e-7ff2-45d1-96b8-408781ffb878
will be used - For Refund Edge case seed method is used to save customer and transactionId
e96e72cf-2cc3-4b8c-9dec-b056979dccaa
will be used
- Authentication for Merchant can be added.
- Validation can be improved e.g if Month/Year is expired and many more.
- Visual Studio Code or 2019
- Docker
- Powershell
- EF Core : database mapper for .NET
- Serilog : for logging
- Swashbuckle.Aspnetcore : for Swagger tooling for API's built with ASP.NET Core
Run the below command to build the solution locally;
Execute build.ps1 to compile application and package release artifacts. Outputs to /dist/
folder.
Below are some examples;
- Full Build:
PS> .\build.ps1
- Debug Build:
PS> .\build.ps1 -Config "Debug"
- Skip Tests:
PS> .\build.ps1 -SkipTests
The build script also outputs the code coverage result. The coverage report files can be found under dist\Coverage
folder. After the build process is executed you can open the coverage report using dist\Coverage\index.html
To Build, (re)create container image for service(s), run the below command:
docker-compose build
To start, and attach to container for service(s), run:
docker-compose up
dotnet build PaymentGatewayAPI.sln
dotnet test PaymentGatewayAPI.sln
Run below command;
cd "src\PaymentGatewayAPI\"
dotnet run WebApi.csproj
- sample payload for
POST /api/authorize/
API
{
"cardNumber": "4000 0000 0000 0119",
"expiryMonth":"03",
"expiryYear":"2021",
"Cvv": 123,
"Amount": 10,
"currency": "gbp"
}
- sample payload for
POST /api/capture/
,POST /api/refund/
API
{
"transactionId": "79bf18b4-63fb-4c6d-aa4b-380d15a41b56",
"amount": 6
}
- sample payload for
POST /api/void/
API
{
"transactionId": "79bf18b4-63fb-4c6d-aa4b-380d15a41b56"
}