Welcome to the Payment
System! This project demonstrates a payment system that focuses on multi-payment providers. It utilizes the Factory Pattern and Adapter Pattern to create a flexible environment where new payment providers can be easily added and used for the payment process. The project also includes a simple frontend built with Angular, showcasing a simple shoe store that works with the backend to allow customers to add products to their cart, proceed to checkout, and complete the payment process. Additionally, it provides a payment history feature.
The Payment
test project consists of the following components:
The Payment.Domain
project contains the domain models that represent the core entities and concepts of the payment system.
The Payment.Application
project is the application layer that contains classes and interfaces related to the application logic. It includes view models, services and repository interfaces, factory and adapter pattern interfaces, and AutoMapper profile classes.
The Payment.Infrastructure
project is the infrastructure layer responsible for interacting with external services (such Adyen or PayPal) and managing persistence. It includes services that interact with payment providers and implementations of repositories.
The Payment.Api
project is the API project that exposes endpoints for interacting with the payment system. It handles request processing, dependency injection registration, and integrates the different layers of the system.
The Payment.Tests
project contains all the unit tests for the various components of the Payment
project. It ensures the correctness and reliability of the implemented functionality.
The payment-client
folder contains the Angular client application that provides the user interface for the shoe store and payment process. It communicates with the backend API to perform payment-related operations and display the payment history.
To run the Payment
project, follow these steps:
-
Ensure that you have a relational database (such as MySQL or SqlServer) set up and running.
-
Open the
appsettings.json
file and define aConnectionString
value based on your selected database. (I have previously defined two examples, one forMySql
and the other forSqlServer
). -
Open the
Program.cs
file and, in the register section where the DbContext is being registered usingAddDbContext
, perform the configuration based on your selected database. Note that you need to first install the appropriate Provider for that database as aNuGet Package
. (By default, I have installed the Providers forMySql
andSqlServer
). -
Open a command prompt or terminal and navigate to the
Payment
directory (the root directory of all projects). -
Run the following command to generate migration files for selected database.
dotnet ef migrations add Init -s Payment.Api -p Payment.Infrastructure
-
After that, Run the following command to apply the database migrations and create the necessary database and tables:
dotnet ef database update -s Payment.Api -p Payment.Infrastructure
This will create the database based on the existing database configuration in the backend project.
-
Open the
launchSettings.json
file located in theProperties
folder of thePayment.Api
project and set the desired address and port in the"applicationUrl"
property to specify where the backend API should listen for requests (the default ports are5000
forhttp
and5001
forhttps
). -
Build and run the
Payment.Api
project.
-
Open a command prompt or terminal and navigate to the
payment-client
directory. -
Run the following command to install the necessary dependencies:
npm install
-
Open the
src/environments/environment.ts
file in thepayment-client
project. Set thebaseUrl
property to the address and port where the backend API is running. This will allow the frontend to communicate with the backend (the default port is5000
forhttp
). -
After the dependencies are installed, run the following command to start the Angular development server:
ng serve
-
Open your web browser and navigate to the
http://localhost:4200
to access thePayment
frontend project.
To add a new payment provider to the backend, follow these steps:
-
Create a class that implements the
IPaymentProvider
interface. This class will encapsulate the logic for interacting with the specific payment provider's API.Make sure to assign a name of new provider to
Name
property ofIPaymentProvider
. Assign it in the constructor of new class.The name should be same as the
Provider
entry value, under thePaymentSettings
entry ofappsettings.json
file. -
Create a class that implements the
IPaymentResponse
interface. This class will be responsible for converting the response received from the new payment provider's API into a common response format defined by the domain. -
Register the new payment provider in the
PaymentProviderFactoryExtension
class. Open theWeb -> Payment.Api -> Extensions -> PaymentProviderFactoryExtension.cs
file and add the registration for the new provider in theAddPaymentProviderFactory
method. -
Update the
appsettings.json
file with the necessary settings for the new payment provider. Add the required configuration under thePaymentSettings
section.
Example configuration for a new payment provider in the appsettings.json
file:
{
"PaymentSettings": {
"Provider": "new-payment-provider-name",
"NewPaymentProviderSettings": {
"ApiKey": "your-api-key",
"OtherSettings": "other-values"
}
}
}
Make sure to replace "your-api-key"
and "OtherSettings"
with the actual values and settings required for the new payment provider.
Thank You! 🙏