This document explains the complete refund and transfer logic implemented in the orders management system. The system handles payment processing for service orders with automatic and manual refund calculations, as well as transfer payments to service providers.
- Orders Page: Main interface for managing orders
- RefundDialog: Handles refund calculations and processing
- TransferDialog: Manages payment transfers to service providers
- Stripe Integration: Payment processing backend
GET /admin/all-orders- Fetch all ordersGET /admin/order-details/{orderId}- Get specific order detailsPOST /payments/refund- Process refundPOST /payments/create-transfer- Create transfer to service provider
Refunds are only available for orders with status IN_PROGRESS. The system shows a "Refund" button in the actions column for these orders.
Every order has the following payment structure:
Total Paid = Bid Amount + Service Fee
Service Fee = Bid Amount × Application Fee Percentage
Example:
- Bid Amount: $100
- Application Fee: 15%
- Service Fee: $15
- Total Paid: $115
The system calculates refunds automatically based on time until service start:
- More than 24 hours before start: 100% refund of bid amount
- 6-24 hours before start: 75% refund of bid amount
- Less than 6 hours before start: 50% refund of bid amount
- After task started: 0% refund (manual approval only)
const startTime = new Date(order.bid.service.startTime);
const now = new Date();
const hoursUntilStart = (startTime.getTime() - now.getTime()) / (1000 * 60 * 60);
let refundPercentage = 0;
if (hoursUntilStart > 24) {
refundPercentage = 100;
} else if (hoursUntilStart >= 6) {
refundPercentage = 75;
} else if (hoursUntilStart > 0) {
refundPercentage = 50;
} else {
refundPercentage = 0; // Manual only
}
const refundAmount = bidAmount * (refundPercentage / 100);Admins can override automatic calculations using three methods:
- Input: Percentage (0-100%)
- Calculation:
bidAmount × (percentage / 100) - Example: 80% of $100 = $80
- Input: Dollar amount
- Calculation: Direct amount
- Example: Fixed $75 refund
- Input: Deduction amount
- Calculation:
bidAmount - deductionAmount - Example: $100 - $25 = $75 refund
- Service fees are NEVER refunded (always deducted)
- Only the bid amount is eligible for refund
- Refund amount cannot exceed the original bid amount
- Minimum refund amount is $0.01
Order Details:
- Bid Amount: $100
- Service Fee (15%): $15
- Total Paid: $115
- Time until start: 30 hours
Result:
- Refund Percentage: 100%
- Bid Refund: $100
- Service Fee Deducted: $15
- Total Refund to Customer: $100
Order Details:
- Bid Amount: $200
- Service Fee (10%): $20
- Total Paid: $220
- Time until start: 12 hours
Result:
- Refund Percentage: 75%
- Bid Refund: $150
- Service Fee Deducted: $20
- Total Refund to Customer: $150
Order Details:
- Bid Amount: $150
- Service Fee (15%): $22.50
- Total Paid: $172.50
- Manual: 60% refund
Result:
- Manual Percentage: 60%
- Bid Refund: $90
- Service Fee Deducted: $22.50
- Total Refund to Customer: $90
Transfers are available for orders with status IN_PROGRESS. The system shows a "Transfer" button in the actions column.
Total Paid → Bid Amount → Platform Fee Deduction → Transfer Amount
- Extract Bid Amount: Remove application fee from total paid
- Calculate Platform Fee: Apply platform fee percentage to bid amount
- Calculate Transfer: Subtract platform fee from bid amount
const totalPaid = parseFloat(order.bid.price);
const applicationFeePercent = order.applicationFeePersen || 0;
const bidAmount = totalPaid / (1 + applicationFeePercent / 100);
const platformFeePercent = parseFloat(platformFeePercent) || 15;
const platformFee = bidAmount * (platformFeePercent / 100);
const transferAmount = bidAmount - platformFee;
const amountCents = Math.round(transferAmount * 100);- Default platform fee: 15% (configurable)
- Admin can adjust platform fee percentage before transfer
- Platform fee is deducted from bid amount, not total paid
- Transfer amount is converted to cents for Stripe API
- Order must be in
IN_PROGRESSstatus - Admin must confirm the transfer (checkbox)
- Transfer amount must be greater than $0
- Service provider must have valid Stripe account
Order Details:
- Total Paid: $115
- Application Fee: 15%
- Bid Amount: $100
- Platform Fee: 15%
Calculation:
- Bid Amount: $115 ÷ 1.15 = $100
- Platform Fee: $100 × 15% = $15
- Transfer Amount: $100 - $15 = $85
- Amount in Cents: 8500
Result:
- Service Provider Receives: $85
- Platform Keeps: $15 (platform fee) + $15 (application fee) = $30
Order Details:
- Total Paid: $220
- Application Fee: 10%
- Bid Amount: $200
- Platform Fee: 20% (custom)
Calculation:
- Bid Amount: $220 ÷ 1.10 = $200
- Platform Fee: $200 × 20% = $40
- Transfer Amount: $200 - $40 = $160
- Amount in Cents: 16000
Result:
- Service Provider Receives: $160
- Platform Keeps: $40 (platform fee) + $20 (application fee) = $60
The system shows payment status badges based on order status:
const getPaymentStatusBadge = (orderStatus) => {
if (orderStatus === "CANCELLED") {
return "Refund"; // Orange badge
}
if (orderStatus === "COMPLETED") {
return "Transfer"; // Green badge
}
return "Pending"; // Gray badge
};- PENDING: Order created, payment pending
- IN_PROGRESS: Payment captured, service in progress
- COMPLETED: Service completed, ready for transfer
- CANCELLED: Order cancelled, eligible for refund
- Invalid order ID
- Order not eligible for refund
- Refund amount exceeds bid amount
- Stripe API errors
- Network connectivity issues
- Invalid service provider Stripe account
- Insufficient platform balance
- Transfer amount too small (minimum $0.50)
- Stripe API rate limits
- Invalid amount format
- Success: Toast notification with confirmation
- Error: Toast notification with specific error message
- Loading: Button shows "Processing..." state
- Validation: Real-time form validation
- All operations require admin authentication token
- Order access validated by user permissions
- Stripe operations use secure API keys
- Amount validation (positive numbers only)
- Order status verification before operations
- Service provider account verification
- Input sanitization for all user inputs
- All refund/transfer operations logged
- Order status changes tracked
- Payment processing events recorded
- Admin action attribution
- Refunds: Uses Stripe Refund API
- Transfers: Uses Stripe Transfer API
- Account verification for service providers
- Webhook handling for payment events
- Order status changes
- Payment transaction records
- Refund/transfer history
- User balance updates
- Email notifications to customers
- SMS alerts for service providers
- Admin dashboard updates
- Real-time status updates
- Partial Refunds: Allow refunding specific line items
- Scheduled Transfers: Automatic transfers based on completion
- Dispute Management: Handle payment disputes
- Multi-currency Support: Support for different currencies
- Bulk Operations: Process multiple refunds/transfers
- Advanced Analytics: Payment processing metrics
- Caching: Cache order details for better performance
- Retry Logic: Automatic retry for failed operations
- Rate Limiting: Prevent abuse of payment operations
- Real-time Updates: WebSocket integration for live updates
- Mobile Optimization: Better mobile experience for admins
- Refund Failed: Check Stripe account balance and API keys
- Transfer Delayed: Verify service provider Stripe account status
- Amount Mismatch: Ensure proper fee calculations
- Status Not Updating: Check webhook configuration
- Permission Denied: Verify admin authentication token
- All operations log detailed information to console
- Error messages include specific failure reasons
- Order details include all relevant payment information
- Stripe transaction IDs tracked for reference
Last Updated: January 2026 Version: 1.0