API to create, query and refund payments processed through a bank simulation powered by Stripe.
The architecture is orchestrated using Docker Compose, which has the following components:
-
Online Payment Platform API. API service used to create, query and refund payments through a bank simulator.
-
Online Payment Webhooks. Webhoook handling service dedicated to listen for incoming events and update the status from actions performed using the Online Payment Platform API, such as creating or refunding a transaction.
-
PostgreSQL. Database service used to persist transactions created through the platform.
-
Stripe CLI. External service used as a bank simulator to handle successful/unsuccessful purchases as well as refunds. This project takes advantage of Stripe's
Test mode
as a way to mock payments and refunds.
For more information about the API resources supported by this service, click here.
Follow these instructions in order to be able to run the project locally or through a containerized environment.
- Create an account in order to take advantage of
Test mode
, click here. - In case you want to run the project locally, follow this guide to install and log into Stripe CLI.
- Follow the instructions found in the official docs to install Docker.
- After installing Docker, follow the steps found in the official docs to install Docker Compose.
In case you are interested in local development, follow these steps to install PostgreSQL:
- Install PostgreSQL here, depending on your OS.
- Access PostgreSQL through the terminal using the default user:
psql postgres
. - Create the database for the platform and access it:
CREATE DATABASE payment_platform;
\c payment_platform;
- Create the
transactions_history
table:
CREATE TABLE IF NOT EXISTS transactions_history (
transaction_id VARCHAR PRIMARY KEY,
status VARCHAR(20) NOT NULL,
failure_reason VARCHAR(50),
payment_provider VARCHAR(20) NOT NULL,
description VARCHAR(100) NOT NULL,
amount NUMERIC NOT NULL,
currency CHAR(3) NOT NULL,
type VARCHAR(10) NOT NULL,
additional_fields JSONB
);
In case you are interested in local development, make sure to install the latest version of Golang found on the official docs.
Once you have installed the prerequisites above, run this command to get a copy of the project:
git clone https://github.com/aledeltoro/simple-online-payment-platform.git
Create a .env
file at the root of the project based on the .env.example
file in the repo. After that, fill in the missing environment variables, which are:
- STRIPE_SECRET_KEY. Get the
Test mode
secret key from Stripe's dashboard here. - STRIPE_WEBHOOK_SECRET_KEY. Get the
Test mode
webhook secret key from the code example generated by Stripe in their dashboard. Click here.
In case you want to start local development, follow theses steps:
- Install Go dependencies:
go mod download
- Depending on the service you want to run (i.e., API, Webhooks or both), use the following commad:
go run cmd/{executable_name}/main.go
In order to run the tests, run the following command at the root of the project:
go test ./...
In order to start the services composing the platform, run the following command at the root of the project:
docker-compose up --build
In order to create successful or unsucessful payments, we must use the test cards provided by Stripe's Test mode
:
-
Examples of test cards to perform succesful payments:
pm_card_visa
,pm_card_mastercard_debit
. For more examples, click here. -
Examples of test cards to perform unsuccesful payments:
pm_card_visa_chargeDeclined
,pm_card_visa_chargeDeclinedInsufficientFunds
. For more examples, click here.
- Chi - Lightweight, idiomatic and composable router for building Go HTTP services.
- Stripe-go - Go library for the Stripe API.
- Pgx - PostgreSQL driver and toolkit for Go.
- Pgxmock - Pgx mock driver for golang to test database interactions.
- Testify - A toolkit with common assertions and mocks that plays nicely with the standard library.
- Godotenv - Loads environment variables from
.env
.