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.jsonfile and define aConnectionStringvalue based on your selected database. (I have previously defined two examples, one forMySqland the other forSqlServer). -
Open the
Program.csfile 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 forMySqlandSqlServer). -
Open a command prompt or terminal and navigate to the
Paymentdirectory (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.InfrastructureThis will create the database based on the existing database configuration in the backend project.
-
Open the
launchSettings.jsonfile located in thePropertiesfolder of thePayment.Apiproject and set the desired address and port in the"applicationUrl"property to specify where the backend API should listen for requests (the default ports are5000forhttpand5001forhttps). -
Build and run the
Payment.Apiproject.
-
Open a command prompt or terminal and navigate to the
payment-clientdirectory. -
Run the following command to install the necessary dependencies:
npm install -
Open the
src/environments/environment.tsfile in thepayment-clientproject. Set thebaseUrlproperty to the address and port where the backend API is running. This will allow the frontend to communicate with the backend (the default port is5000forhttp). -
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:4200to access thePaymentfrontend project.
To add a new payment provider to the backend, follow these steps:
-
Create a class that implements the
IPaymentProviderinterface. 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
Nameproperty ofIPaymentProvider. Assign it in the constructor of new class.The name should be same as the
Providerentry value, under thePaymentSettingsentry ofappsettings.jsonfile. -
Create a class that implements the
IPaymentResponseinterface. 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
PaymentProviderFactoryExtensionclass. Open theWeb -> Payment.Api -> Extensions -> PaymentProviderFactoryExtension.csfile and add the registration for the new provider in theAddPaymentProviderFactorymethod. -
Update the
appsettings.jsonfile with the necessary settings for the new payment provider. Add the required configuration under thePaymentSettingssection.
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! 🙏