Payment Flow Overview
Create Order
Create an order with products (see Creating Orders).
Blockchain Confirmation
Transaction listener monitors the blockchain and confirms after 21 confirmations.
Pay for an Order
Send TRX payment for a pending order.Endpoint
Requires authentication. The order must belong to the authenticated user and have “pending” status.
URL Parameters
- id: The MongoDB ObjectId of the order
Request
No request body required. The payment details are retrieved from the order.Response
Implementation Example
Payment Processing Logic
Fromsrc/api/orders/payOrder.js:41, the payment process:
Transaction Confirmation Process
The system automatically monitors pending transactions using a background service.Configuration
Fromsrc/services/transactionListener.js:16:
Transaction Listener
The transaction listener runs continuously and checks pending transactions every 15 seconds:What Happens on Confirmation
When a transaction is confirmed (fromsrc/services/transactionListener.js:49):
Transaction Status Updated
Transaction status changes from
pending to confirmed with 21 confirmations.Real-time Notification Sent
Socket.io event is emitted to notify the user (see Real-time Notifications).
Checking Transaction Status
Fromsrc/services/transactionListener.js:19, you can check a transaction status:
Payment Error Handling
Transaction States
- pending
- confirmed
- failed
Transaction has been broadcast to the blockchain but not yet confirmed.
- Order status:
pending - Confirmations:
0 - Stock: Not yet reduced
- User action: Wait for confirmation
Payment Security
Monitoring Payments
The transaction listener automatically starts when the server boots:Next Steps
Real-time Notifications
Set up Socket.io to receive instant payment confirmations
Admin Dashboard
Monitor all transactions and sales from the admin panel