Mock payments gateway with account management, order payment processing, and store callback notifications.
Flask-based mock payments gateway running on port 5000. Manages a single mock bank account and processes order payments with automatic callback notification to store_server.
Purpose: Simulate payment processing for orders from store_server. Accepts payment requests, validates funds, deducts balance, and notifies store_server of success or failure via callback.
When to Use:
Base URL: http://localhost:5000
Default Account: ACC-001, Balance: 50000.0
# Check service is running and account exists
curl -s http://localhost:5000/balance | jq '.'
# Expected output:
# {
# "status": "success",
# "account_id": "ACC-001",
# "holder": "John Doe",
# "balance": 50000.0
# }
Request:
curl http://localhost:5000/balance
Response:
{
"status": "success",
"account_id": "ACC-001",
"holder": "John Doe",
"balance": 50000.0
}
Request: After store_server checkout returns order_id and total
curl -X POST http://localhost:5000/payments/orders \
-H "Content-Type: application/json" \
-d '{
"order_id": "abc123def456",
"amount": 179.98
}'
Response (Success - Sufficient Funds):
{
"status": "success",
"message": "Payment of 179.98 for order abc123def456 completed",
"balance": 49820.02,
"transaction": {
"order_id": "abc123def456",
"amount": 179.98,
"balance_after": 49820.02
},
"shop_notified": true
}
Response (Failure - Insufficient Funds):
{
"status": "failed",
"message": "Insufficient funds",
"balance": 49820.02,
"requested": 51000
}
Behind the scenes: If successful, payments_server automatically calls:
POST http://localhost:8000/payments/confirm
{"order_id": "abc123def456", "status": "success"}
Or on failure:
POST http://localhost:8000/payments/confirm
{"order_id": "abc123def456", "status": "failed"}
Request:
curl -X POST http://localhost:5000/pay \
-H "Content-Type: application/json" \
-d '{
"amount": 100,
"recipient": "https://example-shop.com"
}'
Response:
{
"status": "success",
"message": "Payment of 100 to https://example-shop.com completed",
"balance": 49720.02,
"transaction": {
"recipient": "https://example-shop.com",
"amount": 100,
"balance_after": 49720.02
}
}
Request:
curl http://localhost:5000/transactions
Response:
{
"status": "success",
"account_id": "ACC-001",
"transactions": [
{
"order_id": "abc123def456",
"amount": 179.98,
"balance_after": 49820.02
},
{
"recipient": "https://example-shop.com",
"amount": 100,
"balance_after": 49720.02
}
]
}
Request:
curl -X POST http://localhost:5000/reset
Response:
{
"status": "success",
"message": "Account reset to default balance",
"balance": 50000.0
}
Symptom:
{"status": "failed", "message": "Insufficient funds", "balance": 100, "requested": 5000}
Cause: Account balance is less than requested payment amount.
Solution: Reset account or use smaller payment amount.
# Check current balance
curl http://localhost:5000/balance | jq '.balance'
# Reset to start fresh
curl -X POST http://localhost:5000/reset
Symptom:
{"status": "failed", "message": "Both 'order_id' and 'amount' fields are required"}
Cause: POST request missing required fields.
Solution: Verify request JSON has both order_id and amount.
# Correct format
curl -X POST http://localhost:5000/payments/orders \
-H "Content-Type: application/json" \
-d '{"order_id": "ord_123", "amount": 99.99}'
Symptom: Payment succeeds locally but shop_notified is false.
Cause: store_server is not running or not on expected port.
Solution: Verify store_server is running on port 8000.
# Check store_server health
curl http://localhost:8000/categories
# If fails, start store_server:
# cd store_server && python -m uvicorn main:app --reload --port 8000
Symptom: Payment request hangs or returns unexpected error.
Cause: Service connectivity issue or bad JSON.
Solution: Verify JSON is valid and service is responsive.
# Test connectivity
curl -v http://localhost:5000/balance
# Validate JSON syntax
echo '{"order_id": "ord_123", "amount": 99.99}' | jq .
Sequence:
Complete example script:
#!/bin/bash
# Assume store_server has created cart and checkout
order_id="abc123def456"
total=179.98
echo "Processing payment for order: $order_id, amount: $total"
# Pay via payments_server
payment=$(curl -s -X POST http://localhost:5000/payments/orders \
-H "Content-Type: application/json" \
-d "{\"order_id\": \"$order_id\", \"amount\": $total}")
echo "Payment response:"
echo $payment | jq '.'
# Check if notified store
shop_notified=$(echo $payment | jq '.shop_notified')
if [ "$shop_notified" = "true" ]; then
echo "✓ Store was notified, checking order status..."
sleep 1
curl -s http://localhost:8000/orders/$order_id | jq '.status'
else
echo "✗ Store notification failed"
fi
| Method | Endpoint | Purpose | Required Fields |
|---|---|---|---|
| GET | /balance | Check account balance | None |
| POST | /pay | Generic payment | amount, recipient |
| POST | /payments/orders | Pay for store order | order_id, amount |
| POST | /pay/order | Legacy order payment | order_id, amount |
| GET | /transactions | View all transactions | None |
| POST | /reset | Reset account to default | None |