https://github.com/victorlga/payment-webhook-handler
A Clojure webhook handler for processing and validating payment events with SQLite persistence and HTTP callbacks for confirmation/cancellation.
https://github.com/victorlga/payment-webhook-handler
backend clojure functional-programming payment webhook
Last synced: about 3 hours ago
JSON representation
A Clojure webhook handler for processing and validating payment events with SQLite persistence and HTTP callbacks for confirmation/cancellation.
- Host: GitHub
- URL: https://github.com/victorlga/payment-webhook-handler
- Owner: victorlga
- License: mit
- Created: 2025-06-04T20:38:43.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-09T23:50:53.000Z (about 1 year ago)
- Last Synced: 2025-06-18T21:46:18.624Z (about 1 year ago)
- Topics: backend, clojure, functional-programming, payment, webhook
- Language: Clojure
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐งพ Payment Webhook Handler
A Clojure webhook handler for processing and validating payment events with SQLite persistence and HTTP callbacks for confirmation/cancellation.
## ๐ฆ Features
* Validates a secure token from incoming webhooks
* Checks for duplicate or malformed payloads
* Confirms or cancels transactions via internal HTTP APIs
* Persists transaction IDs in an SQLite database
* Supports both HTTP (port 5000) and HTTPS (port 5443)
---
## ๐ Getting Started
### 1. Clone the Repository
```bash
git clone https://github.com/victorlga/payment-webhook-handler.git
cd payment-webhook-handler
```
This project will run a HTTPS server locally. To make this possible, you need to generate a self-signed certificate. Run the following command **in the root of the repository** to create a `keystore.p12` file:
```bash
keytool -genkeypair -alias server-key \
-keyalg RSA -keysize 2048 -storetype PKCS12 \
-keystore keystore.p12 -validity 365 \
-storepass changeit -keypass changeit \
-dname "CN=localhost, OU=Dev, O=MyCompany, L=City, S=State, C=BR"
```
> This creates a self-signed certificate valid for 365 days, with both the store and key passwords set to `changeit`.
### 2. Build Docker Image
Make sure Docker is running:
```bash
docker build -t clojure-webhook-handler -f .devcontainer/Dockerfile .
```
### 3. Run the Server
If ports `5000` (HTTP) or `5443` (HTTPS) are in use, **change the exposed ports**.
```bash
docker run -p 5000:5000 -p 5443:5443 clojure-webhook-handler
```
For example, if port `5000` is busy and you want to use port `5050` instead:
```bash
docker run -p 5050:5000 -p 5443:5443 clojure-webhook-handler
```
You should see something like:
```
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
...
```
---
## ๐งช Testing the Webhook
### 1. Navigate to the Python Test Script
```bash
cd python
```
### 2. Set Up Python Environment
```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
### 3. Run the Test
```bash
python3 test_webhook.py
```
> โ ๏ธ If you changed the port during Docker run, make sure to update it in `test_webhook.py`.
### โ
Verifying HTTPS is Working
Once the server is running with HTTPS (on port `5443` by default), test it using `curl`:
```bash
curl -k -X POST https://localhost:5443/webhook \
-H "Content-Type: application/json" \
-H "x-webhook-token: meu-token-secreto" \
-d '{"transaction_id": "test-123", "event": "payment", "amount": "49.90", "currency": "BRL", "timestamp": "2025-06-08T12:00:00Z"}'
```
* The `-k` flag allows `curl` to skip certificate verification (necessary for self-signed certs).
* You should receive a response like `"OK"` if the request is accepted.
### โ ๏ธ Important Notes
* This `curl` request **only validates the HTTPS interface**.
* The internal HTTP requests to confirm or cancel the transaction **will fail**, because `curl` doesn't run the backend services required to handle those endpoints (`/confirmar`, `/cancelar`).
* This is expected during basic HTTPS testing.
---
## ๐ Project Structure
```
.
โโโ core.clj ; Main handler logic
โโโ project.clj ; Leiningen config
โโโ .devcontainer/
โ โโโ Dockerfile ; Docker setup
โโโ data/ ; SQLite database
โโโ python/
โโโ test_webhook.py ; Test client for webhook
โโโ requirements.txt ; Python dependencies
```