Biometric payment system built in Rust with face , voice , fingerprint , and gesture recognition, plus password and PIN fallback authentication. Supports wallet payments, external payment gateways, online/POS/COD checkout, merchant webhooks, and multi-source payment splitting.
crates/
├── core/ Domain models, enums, error types, compliance, encryption, audit, MFA, payment instruments
├── biometric/ Biometric trait interfaces + engines (ONNX face, MFCC voice, minutiae fingerprint, motion gesture)
├── auth/ Authentication (face, password, PIN) & authorization (voice/fingerprint/gesture/face/password/PIN) services
├── notify/ Notification channels (email, SMS, push, webhook), event bus, templates, preferences
├── db/ Repository traits + in-memory & Postgres implementations (users, accounts, payments, checkout, funding sources, payment instruments, terminals, deliveries, audit)
└── api/ Axum REST API server with checkout engine, wallet service, payment gateway, payment instrument service, merchant webhooks, metrics, Swagger UI
Layer
Default
Production
Domain data
In-memory
PostgreSQL (DATABASE_URL)
Biometric templates
In-memory (encrypted AES-256-GCM)
S3 or filesystem + encrypted at rest
Audit trail
In-memory
PostgreSQL
# Start with in-memory storage (no database required)
cargo run -p payment-api
Server listens on http://0.0.0.0:3000.
# Start the server in one terminal
cargo run -p payment-api
# In another terminal, run the full demo
bash scripts/demo_workflow.sh
The demo covers: user registration, wallet creation, deposit, biometric enrollment, online checkout (voice/fingerprint/gesture), refunds, cancellations, recurring payments, transaction ledger, and receipts.
88 tests covering: currency conversion, brute-force protection, full payment lifecycle, online/POS/COD checkout, gateway routing, wallet operations, gateway callbacks, payment instruments, password/PIN authentication, receipt PDF export, escrow, disputes, invoice verification, and ratings/reviews.
API Endpoints (105 total)
Full documentation: api.md
Method
Path
Purpose
POST
/api/v1/users
Create user
POST
/api/v1/accounts
Create account
POST
/api/v1/accounts/:id/deposit
Deposit funds
POST
/api/v1/payments
Create payment
GET
/api/v1/payments/:id
Get payment
Method
Path
Purpose
POST
/api/v1/engine/reserve/:id
Reserve funds
POST
/api/v1/engine/capture/:id
Capture funds
POST
/api/v1/engine/refund/:id
Refund payment
POST
/api/v1/engine/cancel/:id
Cancel payment
POST
/api/v1/engine/recurring
Create recurring schedule
Method
Path
Purpose
POST
/api/v1/auth/face/register/:uid
Enroll face
POST
/api/v1/auth/voice/enroll/:uid
Enroll voice
POST
/api/v1/auth/fingerprint/enroll/:uid
Enroll fingerprint
POST
/api/v1/auth/gesture/enroll/:uid
Enroll gesture
POST
/api/v1/auth/password/register/:uid
Register password
POST
/api/v1/auth/password/login/:uid
Login with password
POST
/api/v1/auth/password/reset-request/:uid
Request password reset token
POST
/api/v1/auth/password/reset
Reset password with token
POST
/api/v1/auth/pin/register/:uid
Register PIN
POST
/api/v1/auth/pin/login/:uid
Login with PIN
POST
/api/v1/auth/authorize/:uid/:pid
Authorize payment (liveness + brute-force protected)
Method
Path
Purpose
POST
/api/v1/checkout
Create checkout session (Online/Pos/Cod)
POST
/api/v1/checkout/:sid/select-source
Select funding source
POST
/api/v1/checkout/:sid/authorize
Biometric authorization
POST
/api/v1/checkout/:sid/capture
Capture payment
POST
/api/v1/checkout/pos/pdq
PDQ terminal checkout
POST
/api/v1/checkout/pos/desk
Desk terminal checkout
POST
/api/v1/checkout/:sid/cod/delivery
Create COD delivery
POST
/api/v1/checkout/delivery/:did/start
Start delivery
POST
/api/v1/checkout/delivery/:did/confirm
Confirm delivery
Method
Path
Purpose
GET
/api/v1/wallet/balance/:uid
Get wallet balance
POST
/api/v1/wallet/topup
Top up from funding source
POST
/api/v1/wallet/transfer
Transfer between users
POST
/api/v1/wallet/withdraw
Withdraw to funding source
POST
/api/v1/funding-sources
Create funding source (with optional gateway_url)
Method
Path
Purpose
POST
/api/v1/payment-instruments
Tokenize instrument (card/wallet/token/cheque)
POST
/api/v1/payment-instruments/virtual-card
Generate virtual card
GET
/api/v1/payment-instruments
List user instruments
GET
/api/v1/payment-instruments/wallet-balance/:uid
Digital wallet balance
GET
/api/v1/payment-instruments/token/:token
Resolve token to instrument
GET
/api/v1/payment-instruments/:id
Get instrument
POST
/api/v1/payment-instruments/:id/default
Set as default
POST
/api/v1/payment-instruments/:id/deactivate
Deactivate instrument
DELETE
/api/v1/payment-instruments/:id
Delete instrument
Method
Path
Purpose
POST
/api/v1/kyc/:uid/submit
Submit KYC documents
GET
/api/v1/kyc/:uid/status
Get KYC status
POST
/api/v1/kyc/:uid/review
Approve/reject KYC
Method
Path
Purpose
GET
/api/v1/receipts/:id
Get receipt
GET
/api/v1/receipts/:id/pdf
Download receipt as PDF
GET
/api/v1/receipts/payment/:pid
Get receipt for payment
GET
/api/v1/receipts/account/:aid
List account receipts
POST
/api/v1/receipts/:id/share
Share receipt
Method
Path
Purpose
POST
/api/v1/terminals
Create terminal
GET
/api/v1/terminals/:id
Get terminal
GET
/api/v1/terminals/merchant/:mid
List merchant terminals
Method
Path
Purpose
POST
/api/v1/escrow
Create escrow for payment
GET
/api/v1/escrow/:id
Get escrow
GET
/api/v1/escrow/payment/:pid
Get escrow for payment
GET
/api/v1/escrow/buyer/:uid
List buyer escrows
GET
/api/v1/escrow/seller/:uid
List seller escrows
POST
/api/v1/escrow/:id/confirm-buyer
Buyer confirms satisfaction
POST
/api/v1/escrow/:id/confirm-seller
Seller confirms fulfillment
POST
/api/v1/escrow/:id/refund
Refund escrow
Method
Path
Purpose
POST
/api/v1/disputes
Raise a dispute
GET
/api/v1/disputes/:id
Get dispute
GET
/api/v1/disputes/payment/:pid
List disputes for payment
GET
/api/v1/disputes/user/:uid
List disputes for user
POST
/api/v1/disputes/:id/review
Set dispute under review
POST
/api/v1/disputes/:id/resolve
Resolve dispute
POST
/api/v1/disputes/:id/reject
Reject dispute
Method
Path
Purpose
POST
/api/v1/invoices
Submit invoice/LPO
GET
/api/v1/invoices/:id
Get invoice
GET
/api/v1/invoices/payment/:pid
List invoices for payment
GET
/api/v1/invoices/escrow/:eid
List invoices for escrow
POST
/api/v1/invoices/:id/verify
Verify invoice
Method
Path
Purpose
POST
/api/v1/reviews
Create review
GET
/api/v1/reviews/:id
Get review
GET
/api/v1/reviews/merchant/:mid
List merchant reviews
GET
/api/v1/reviews/user/:uid
List user reviews
GET
/api/v1/reviews/payment/:pid
List payment reviews
POST
/api/v1/reviews/:id/flag
Flag review
POST
/api/v1/reviews/:id/hide
Hide review
POST
/api/v1/reviews/:id/restore
Restore review
GET
/api/v1/reviews/rating/:mid
Get merchant rating aggregation
Method
Path
Purpose
POST
/api/v1/webhooks/gateway/:sid
Inbound gateway callback
—
—
Outbound merchant webhooks (configurable per account)
Method
Path
Purpose
GET
/api/v1/health/health
Liveness check
GET
/api/v1/health/ready
Readiness check
GET
/api/metrics
Prometheus metrics
GET
/api/swagger-ui/
Interactive API docs
The system routes payments through either an internal wallet or an external gateway :
Condition
Route
Wallet has sufficient funds
Wallet — debits internal balance
Wallet insufficient + funding source has gateway_url
Gateway — external provider settles
Wallet insufficient + no gateway available
Fails — insufficient funds
User explicitly opts "gateway"
Gateway — always external
Configure the gateway via environment variables:
Variable
Effect
PAYMENT_GATEWAY_URL
Set to use HttpGateway (POSTs JSON). Omit for SimulatedGateway.
PUBLIC_URL
Base URL for callbacks sent to gateways.
gateway_url per funding source
Per-source gateway override.
merchant_webhook_url per account
Outbound merchant notifications.
Env var
Default
Description
DATABASE_URL
—
PostgreSQL connection URL (omit = in-memory)
DB_POOL_SIZE
10
Max PostgreSQL connections
ENCRYPTION_KEY
random
Hex-encoded 32-byte AES-256 key for biometric templates
BIOMETRIC_THRESHOLD
0.45
Minimum biometric match score
Env var
Default
Description
PAYMENT_GATEWAY_URL
—
External gateway URL (omit = simulated)
PUBLIC_URL
http://localhost:3000
Callback URL base for gateways
Env var
Default
Description
MFA_ENABLED
true
Enable multi-biometric for high-value payments
MFA_THRESHOLD
10000
Amount triggering MFA
MFA_REQUIRED_METHODS
2
Required biometric methods
Env var
Default
Description
FACE_MODEL_PATH
models/arcface.onnx
ONNX face model path
FACE_MIN_SIZE
32
Minimum face size in pixels
Env var
Default
Description
EXCHANGE_RATE_API_URL
—
Exchange rate API endpoint
EXCHANGE_RATE_CACHE_TTL_SECS
—
Rate cache TTL
Notifications — Email (SMTP)
Env var
Description
SMTP_HOST
SMTP server hostname
SMTP_PORT
SMTP port (default: 587)
SMTP_USERNAME
SMTP username
SMTP_PASSWORD
SMTP password
SMTP_FROM
From address (default: noreply@paymentsystem)
Notifications — SMS (Twilio)
Env var
Description
TWILIO_ACCOUNT_SID
Twilio account SID
TWILIO_AUTH_TOKEN
Twilio auth token
TWILIO_FROM
Twilio sender phone number
Notifications — Push (Firebase)
Env var
Description
FCM_SERVER_KEY
Firebase Cloud Messaging server key