Testing & Sandbox
DVPay provides a sandbox environment for testing your integration without processing real transactions or moving actual funds. This guide covers how to access test credentials, simulate payment scenarios, and validate your implementation.
Sandbox Environment
The sandbox environment mirrors production functionality but uses test data:
Sandbox API Base URL
https://sandbox-merchant.dv.vai247.pro/api/v1
Production API Base URL
https://merchant.dv.vai247.pro/api/v1
Getting Test Credentials
Step 1: Access Sandbox Mode
In the DVPay mobile app:
Open Merchant Dashboard
Navigate to your merchant account settings
Enable Sandbox Mode
Toggle Developer Mode → Sandbox Environment
Generate Test Credentials
Tap API Settings → Generate Sandbox Keys
Copy Credentials
Save your test X-App-Id and X-Api-Key
test_ to prevent accidental use in production.Example Test Credentials
# Sandbox credentials (example)
X-App-Id: test_app_123abc
X-Api-Key: test_key_xyz789
Testing Payment Flows
Create Test Order
Use sandbox credentials to create test payment orders:
curl -X POST https://sandbox-merchant.dv.vai247.pro/api/v1/payment-gateway/order/create \
-H "X-App-Id: test_app_123abc" \
-H "X-Api-Key: test_key_xyz789" \
-H "X-Timestamp: $(date +%s)" \
-H "Content-Type: application/json" \
-d '{
"store_id": "test_store_001",
"amount": 100.00,
"currency": "USD"
}'
// Use sandbox base URL
const sandboxBaseURL = "https://sandbox-merchant.dv.vai247.pro/api/v1"
func createTestOrder() {
url := sandboxBaseURL + "/payment-gateway/order/create"
payload := CreateOrderRequest{
StoreID: "test_store_001",
Amount: 100.00,
Currency: "USD",
}
req.Header.Set("X-App-Id", "test_app_123abc")
req.Header.Set("X-Api-Key", "test_key_xyz789")
req.Header.Set("X-Timestamp", fmt.Sprintf("%d", time.Now().Unix()))
// Make request...
}
// Use sandbox base URL
const SANDBOX_URL = 'https://sandbox-merchant.dv.vai247.pro/api/v1';
const testCredentials = {
appId: 'test_app_123abc',
apiKey: 'test_key_xyz789'
};
async function createTestOrder() {
const response = await axios.post(
`${SANDBOX_URL}/payment-gateway/order/create`,
{
store_id: 'test_store_001',
amount: 100.00,
currency: 'USD'
},
{
headers: {
'X-App-Id': testCredentials.appId,
'X-Api-Key': testCredentials.apiKey,
'X-Timestamp': Math.floor(Date.now() / 1000).toString()
}
}
);
return response.data;
}
Test Payment Methods
Simulate different payment scenarios using test QR codes:
Test QR Code: Use any generated QR code in sandbox and scan with the DVPay test app
Result: Payment completes successfully after 2-3 seconds
Webhook Event: payment.success
Trigger: Create an order with amount 666.66 in any currency
Result: Payment fails with error payment_declined
Webhook Event: payment.failed
Trigger: Create an order with amount 777.77 in any currency
Result: Payment remains in pending state for 5 minutes then succeeds
Webhook Events: payment.pending → payment.success
Trigger: Create an order with amount 888.88 in any currency
Result: Payment times out after 10 minutes
Webhook Event: payment.expired
Testing Refunds
Test refund functionality with completed test orders:
# First, create and complete a test order
ORDER_ID="test_ord_123"
# Then request a refund
curl -X POST https://sandbox-merchant.dv.vai247.pro/api/v1/payment-gateway/refund \
-H "X-App-Id: test_app_123abc" \
-H "X-Api-Key: test_key_xyz789" \
-H "X-Timestamp: $(date +%s)" \
-H "Content-Type: application/json" \
-d "{
\"order_id\": \"$ORDER_ID\",
\"amount\": 100.00,
\"reason\": \"Customer requested refund\"
}"
Testing Webhooks
Local Webhook Testing
Use ngrok or similar tools to test webhooks locally:
Start Your Local Server
node server.js
# Server running on http://localhost:8080
Expose with ngrok
ngrok http 8080
# Forwarding: https://abc123.ngrok.io → http://localhost:8080
Configure Webhook in Sandbox
In DVPay app (Sandbox mode):
- Go to API Settings → Webhooks
- Enter:
https://abc123.ngrok.io/webhooks/dvpay - Save configuration
Trigger Test Events
Create a test payment to receive webhook notifications
Manual Webhook Testing
Test your webhook endpoint manually:
curl -X POST http://localhost:8080/webhooks/dvpay \
-H "Content-Type: application/json" \
-H "X-DVPay-Signature: test_signature_123" \
-d '{
"event": "payment.success",
"order_id": "test_ord_123",
"amount": 100.00,
"currency": "USD",
"status": "completed",
"timestamp": 1696435200,
"metadata": {
"store_id": "test_store_001"
}
}'
Test Cards & Accounts
Test QR Code Behaviors
Scan test QR codes with the DVPay sandbox mobile app:
| Scenario | Action | Expected Result |
|---|---|---|
| Instant Success | Scan any test QR normally | Payment succeeds immediately |
| Instant Failure | Create order with amount 666.66 | Payment fails instantly |
| Delayed Success | Create order with amount 777.77 | Pending → Success after 5 min |
| Insufficient Funds | Set test wallet balance to $0 | Payment fails with error |
Test Merchant Balances
Sandbox merchants start with test balances:
{
"balances": {
"USD": 10000.00,
"KHR": 40000000.00
}
}
Reset your test balance anytime in sandbox settings.
Testing Error Scenarios
Authentication Errors
# Test invalid API key
curl -X POST https://sandbox-merchant.dv.vai247.pro/api/v1/payment-gateway/order/create \
-H "X-App-Id: test_app_123abc" \
-H "X-Api-Key: invalid_key_xxx" \
-H "X-Timestamp: $(date +%s)" \
-d '{"store_id":"test_store_001","amount":100,"currency":"USD"}'
# Expected: 401 Unauthorized
Validation Errors
# Test invalid amount (too low)
curl -X POST https://sandbox-merchant.dv.vai247.pro/api/v1/payment-gateway/order/create \
-H "X-App-Id: test_app_123abc" \
-H "X-Api-Key: test_key_xyz789" \
-H "X-Timestamp: $(date +%s)" \
-d '{"store_id":"test_store_001","amount":0.01,"currency":"USD"}'
# Expected: 422 Unprocessable Entity - invalid_amount
Rate Limiting
# Test rate limits (100 requests/minute)
for i in {1..150}; do
curl -X GET https://sandbox-merchant.dv.vai247.pro/api/v1/payment-gateway/order/test_$i \
-H "X-App-Id: test_app_123abc" \
-H "X-Api-Key: test_key_xyz789" \
-H "X-Timestamp: $(date +%s)"
done
# Expected: First 100 succeed, then 429 Too Many Requests
Environment Configuration
Manage environment-specific configuration:
package config
import "os"
type Config struct {
BaseURL string
AppID string
APIKey string
}
func Load() *Config {
env := os.Getenv("ENV") // "sandbox" or "production"
if env == "production" {
return &Config{
BaseURL: "https://merchant.dv.vai247.pro/api/v1",
AppID: os.Getenv("DVPAY_APP_ID"),
APIKey: os.Getenv("DVPAY_API_KEY"),
}
}
// Default to sandbox
return &Config{
BaseURL: "https://sandbox-merchant.dv.vai247.pro/api/v1",
AppID: os.Getenv("DVPAY_TEST_APP_ID"),
APIKey: os.Getenv("DVPAY_TEST_API_KEY"),
}
}
// config.js
const config = {
sandbox: {
baseURL: 'https://sandbox-merchant.dv.vai247.pro/api/v1',
appId: process.env.DVPAY_TEST_APP_ID,
apiKey: process.env.DVPAY_TEST_API_KEY
},
production: {
baseURL: 'https://merchant.dv.vai247.pro/api/v1',
appId: process.env.DVPAY_APP_ID,
apiKey: process.env.DVPAY_API_KEY
}
};
const environment = process.env.NODE_ENV || 'sandbox';
module.exports = config[environment];
# Sandbox credentials
DVPAY_TEST_APP_ID=test_app_123abc
DVPAY_TEST_API_KEY=test_key_xyz789
# Production credentials (keep secure!)
DVPAY_APP_ID=prod_app_456def
DVPAY_API_KEY=prod_key_789ghi
# Current environment
NODE_ENV=sandbox
Testing Checklist
Before going live, verify:
Payment Creation
- Successfully create orders in sandbox
- Receive correct QR codes
- Handle validation errors properly
Payment Processing
- Process successful payments
- Handle failed payments gracefully
- Manage pending states correctly
Webhooks
- Receive webhook notifications
- Validate webhook signatures
- Handle idempotent webhook processing
Refunds & Cancellations
- Process full refunds
- Process partial refunds
- Cancel unpaid orders
Error Handling
- Handle authentication errors
- Implement retry logic for transient errors
- Log errors with request IDs
Security
- Store credentials securely (environment variables)
- Use HTTPS for all requests
- Validate API responses
Going Live
When ready to switch to production:
Generate Production Credentials
- Disable sandbox mode in DVPay app
- Generate production API keys
- Store credentials securely
Update Configuration
# Update environment variables
NODE_ENV=production
DVPAY_APP_ID=prod_app_456def
DVPAY_API_KEY=prod_key_789ghi
Update Base URL
const baseURL = 'https://merchant.dv.vai247.pro/api/v1';
Test Production
- Make a small real transaction
- Verify webhooks work correctly
- Confirm funds are received
Monitor
- Set up error alerting
- Track transaction success rates
- Monitor webhook delivery
Sandbox Limitations
Be aware of sandbox environment differences:
| Feature | Sandbox | Production |
|---|---|---|
| Transaction Limits | Unlimited | Based on merchant tier |
| Processing Speed | Instant/Simulated | Real-time (2-5 seconds) |
| Refund Processing | Instant | 1-3 business days |
| Webhook Retries | Disabled | Enabled (4 retries) |
| Rate Limiting | Enforced | Enforced |
| Data Retention | 30 days | Unlimited |