This project is an online payment platform that enables merchants to process payments, retrieve payment details, and process refunds via a simple API. The platform is built using Go and the Echo framework, with PostgreSQL as the database.
Before you begin, ensure you have the following installed on your local machine:
- Go: Version 1.18 or higher
- PostgreSQL: Version 13 or higher
- WireMock: As a bank simulator, follow the installation instructions from the official WireMock website.
The application requires the following environment variables to be set:
ENVIRONMENT=
SECRET_KEY=
GO_ENV=
LOG_LEVEL=
PORT=
VERSION_API=
POSTGRES_SERVER=
POSTGRES_DATABASE=payment-platform
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_CONNECT_TIMEOUT=
POSTGRES_MAX_OPEN_CONNS=
POSTGRES_MAX_IDLE_CONNS=
POSTGRES_CONN_MAX_LIFETIME=
POSTGRES_QUERY_TIMEOUT=
PAYMENT_BANK_URL=
PAYMENT_BANK_TIMEOUT=- ENVIRONMENT: The environment in which the application is running (e.g., development, production).
- SECRET_KEY: A secret key used for encryption and security.
- GO_ENV: Go environment (e.g., development, production).
- LOG_LEVEL: The log level for the application (e.g., debug, info, error).
- PORT: The port on which the API will run.
- VERSION_API: API version (e.g., v1).
- POSTGRES_SERVER: The PostgreSQL server address.
- POSTGRES_DATABASE: The name of the database (should be set to
payment-platform). - POSTGRES_USER: The PostgreSQL user.
- POSTGRES_PASSWORD: The PostgreSQL user's password.
- POSTGRES_CONNECT_TIMEOUT: Timeout in seconds for connecting to the PostgreSQL database.
- POSTGRES_MAX_OPEN_CONNS: Maximum number of open connections to the database.
- POSTGRES_MAX_IDLE_CONNS: Maximum number of idle connections in the connection pool.
- POSTGRES_CONN_MAX_LIFETIME: Maximum amount of time a connection may be reused.
- POSTGRES_QUERY_TIMEOUT: Timeout in seconds for queries to the PostgreSQL database.
- PAYMENT_BANK_URL: The URL of the WireMock bank simulator.
- PAYMENT_BANK_TIMEOUT: Timeout in seconds for requests to the bank simulator.
-
Clone the Repository:
git clone https://github.com/your-repository/online-payment-platform.git cd online-payment-platform -
Install Dependencies:
Make sure all dependencies are installed by running:
go mod tidy; go mod vendor -
Set Up PostgreSQL:
Create a PostgreSQL database named
payment-platformand ensure your environment variables are correctly configured to connect to it.createdb payment-platform
-
Run Database backup:
schema.sql:Run the
schema.sqlfile to create the necessary tables in thepayment-platformdatabase.psql -d payment-platform -a -f schema.sql
-
Set Up WireMock:
Follow the WireMock installation guide to set up the bank simulator. Ensure that the
PAYMENT_BANK_URLenvironment variable points to your local WireMock instance.
To start the application, run:
go run main.goThe application will start on the port specified by the PORT environment variable.
The following endpoints are available in the API:
-
Process Payment
- Method:
POST - Endpoint:
/api/v1/payment/process - Description: Processes a payment through the online payment platform.
- Method:
-
Get Payment Details
- Method:
GET - Endpoint:
/api/v1/payment/:id - Description: Retrieves details of a previously made payment using a unique payment identifier.
- Method:
-
Process Refund
- Method:
POST - Endpoint:
/api/v1/payment/:id/refund - Description: Processes a refund for a specific transaction.
- Method:
-
Login User
- Method:
POST - Endpoint:
/api/v1/user/login - Description: Logs in a user to the online payment platform.
- Note: Default user credentials are
peterandshhh!.
- Method:
All endpoints require a valid JWT token to be passed in the Authorization header. The token can be obtained by logging in with the user credentials.
After the application is up and running, you can use tools like Postman or cURL to interact with the API endpoints. Ensure that WireMock is running as your bank simulator to properly test payment processing and refunds.
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are welcome.