Overview
POS Kasir supports multiple payment methods including cash payments and digital payments through Midtrans integration (QRIS and GoPay). The system handles payment processing, webhook notifications, and change calculation.Payment Methods
List Payment Methods
Retrieve all available payment methods. Endpoint:GET /payment-methods
Required Role: Admin, Manager, Cashier
internal/payment_methods/handler.go:23-44
Manual Payment (Cash)
Confirm Manual Payment
Process cash payment and complete the order. Endpoint:POST /orders/{id}/pay/manual
Required Role: Admin, Manager, Cashier
internal/orders/handler.go:152-207
Change Calculation
The system automatically calculates change:- Cash Received: Amount given by customer
- Net Total: Final order amount after discounts
- Change Due: Cash Received - Net Total
Digital Payment (Midtrans)
Initiate Midtrans Payment
Create a QRIS or GoPay payment session. Endpoint:POST /orders/{id}/pay/midtrans
Required Role: Admin, Manager, Cashier
internal/orders/handler.go:460-494
Payment Flow
-
Initiate Payment
- Call
/orders/{id}/pay/midtrans - Receive QR code string and transaction ID
- Display QR code to customer
- Call
-
Customer Scans QR
- Customer scans QR with mobile banking app
- Completes payment in their app
- Midtrans processes the transaction
-
Receive Webhook
- Midtrans sends notification to webhook endpoint
- System updates order status to
paid - Order is finalized
Midtrans Webhook
Midtrans sends payment notifications to this endpoint. Endpoint:POST /orders/webhook/midtrans
Required Role: Public (No authentication)
internal/orders/handler.go:496-524
Transaction Statuses
Midtrans sends different transaction statuses:- pending - Payment initiated, awaiting customer action
- settlement - Payment successful and settled
- capture - Card payment captured (needs manual approval for some cases)
- deny - Payment rejected by bank/issuer
- cancel - Transaction cancelled
- expire - Transaction expired (customer didn’t pay in time)
- refund - Payment refunded
Payment Response Structure
internal/orders/dto.go:109-122
Payment Request DTOs
internal/orders/dto.go:49-52
Integration with Orders
Payment information is included in order responses:- gross_total - Total before discounts
- discount_amount - Total discount applied
- net_total - Final amount to pay
- payment_method_id - Payment method used (1=Cash, 2=QRIS, etc.)
- payment_gateway_reference - Midtrans transaction ID (for digital payments)
- cash_received - Amount received (for cash payments)
- change_due - Change to return (for cash payments)
Workflow Examples
Cash Payment Flow
QRIS Payment Flow
Security Considerations
Webhook Signature Verification
Always verify Midtrans webhook signatures to prevent fraudulent notifications:Payment Idempotency
The system handles duplicate webhook notifications gracefully:- Check if order is already paid before processing
- Return success for duplicate notifications
- Log all webhook attempts for audit
Order State Validation
Before processing payment:- Verify order exists and is not cancelled
- Ensure order is not already paid
- Validate payment amount matches order total
Best Practices
- Cash Validation - Always validate cash_received >= net_total
- Change Calculation - Display change amount prominently to cashier
- QR Code Timeout - QRIS codes typically expire in 15 minutes
- Webhook Retry - Midtrans retries webhooks up to 5 times if endpoint fails
- Payment Status - Poll order status for real-time payment updates
- Receipt Generation - Generate receipt immediately after payment confirmation
- Refund Handling - Implement refund workflow for cancelled paid orders
- Multi-Payment - Consider splitting payments across multiple methods (future feature)
Error Handling
Common Payment Errors
- ErrOrderNotModifiable - Order already paid or cancelled
- ErrInsufficientCash - Cash received less than net total
- ErrPaymentMethodInactive - Selected payment method is disabled
- ErrMidtransTimeout - Payment gateway timeout
- ErrInvalidSignature - Webhook signature verification failed
Error Response Example
Testing
Midtrans Sandbox
Use Midtrans sandbox environment for testing:- Sandbox URL:
https://api.sandbox.midtrans.com - Test QR codes that simulate successful/failed payments
- Webhook simulator in dashboard
Test Payment Scenarios
-
Successful Cash Payment
- Exact amount
- Over payment (with change)
-
Successful QRIS Payment
- Immediate settlement
- Delayed settlement
-
Failed Scenarios
- Insufficient cash
- Expired QRIS
- Cancelled payment
- Duplicate payment attempt