Test Mode
Test your integration safely with test API keys without processing real payments or affecting production data.
Overviewโ
Omise provides separate test and live environments. Use test mode during development to verify your integration without real money or customer data.
Test Mode Features:
- ๐ Separate API keys - Test keys start with
pkey_test_andskey_test_ - ๐ณ Test cards - Special card numbers for testing scenarios
- ๐ฐ No real money - All transactions are simulated
- ๐ Full API access - Test all features and payment methods
- ๐ Test dashboard - View test transactions separately
API Keysโ
Test Keys vs Live Keysโ
| Key Type | Prefix | Environment | Real Transactions |
|---|---|---|---|
| Test Public Key | pkey_test_ | Test | โ No |
| Test Secret Key | skey_test_ | Test | โ No |
| Live Public Key | pkey_live_ | Production | โ Yes |
| Live Secret Key | skey_live_ | Production | โ Yes |
Getting Test Keysโ
- Log into Omise Dashboard
- Navigate to Settings โ API Keys
- Copy your test keys (they start with
pkey_test_andskey_test_)
// Test mode configuration
const omise = require('omise')({
publicKey: 'pkey_test_5xb...', // Test public key
secretKey: 'skey_test_5xb...' // Test secret key
});
Never commit API keys to version control. Use environment variables:
OMISE_PUBLIC_KEY=pkey_test_...
OMISE_SECRET_KEY=skey_test_...
Test Cardsโ
Success Scenariosโ
| Card Number | Brand | Result |
|---|---|---|
| 4242424242424242 | Visa | Success (no 3DS) |
| 5555555555554444 | Mastercard | Success (no 3DS) |
| 3566111111111113 | JCB | Success (no 3DS) |
Expiry: Any future date (e.g., 12/25) CVV: Any 3 digits (e.g., 123)
3D Secure Test Cardsโ
| Card Number | Brand | 3DS Behavior |
|---|---|---|
| 4000000000003220 | Visa | 3DS required, authentication succeeds |
| 4000000000009235 | Visa | 3DS required, authentication fails |
| 5200000000001096 | Mastercard | 3DS required, succeeds |
Decline Scenariosโ
| Card Number | Error Type |
|---|---|
| 4000000000000002 | Card declined |
| 4000000000009995 | Insufficient funds |
| 4000000000000069 | Expired card |
| 4000000000000127 | Incorrect CVC |
| 4000000000000119 | Processing error |
Specific Amount Testingโ
Use these amounts with any test card to simulate scenarios:
| Amount | Result |
|---|---|
| 100.00 | Success |
| 100.02 | Card declined |
| 100.05 | Insufficient funds |
| 100.41 | Processing error |
Testing Payment Methodsโ
Digital Wallets (Test Mode)โ
// Create test wallet payment
const source = await omise.sources.create({
type: 'truemoney',
amount: 50000,
currency: 'THB'
});
// In test mode, you can simulate success/failure
const charge = await omise.charges.create({
amount: 50000,
currency: 'THB',
source: source.id
});
// Test charge completes immediately in test mode
Bank Transfers (Test Mode)โ
// Mobile banking test
const source = await omise.sources.create({
type: 'mobile_banking_scb',
amount: 100000,
currency: 'THB'
});
// Test mode simulates bank approval
const charge = await omise.charges.create({
amount: 100000,
currency: 'THB',
source: source.id,
return_uri: 'https://yourdomain.com/callback'
});
// In test, redirect shows test page with success/fail buttons
QR Payments (Test Mode)โ
// PromptPay test
const source = await omise.sources.create({
type: 'promptpay',
amount: 100000,
currency: 'THB'
});
// QR code generated in test mode
const qrCode = source.scannable_code.image.download_uri;
// Charge status can be updated manually in test dashboard
Test Dashboardโ
Access test data at: https://dashboard.omise.co/test/
Test Dashboard Features:
- View all test transactions
- Filter by payment method
- Test webhook delivery
- Update charge status manually
- Generate test reports
Manual Charge Updatesโ
In test mode, you can manually update charge status:
- Go to test dashboard
- Find the test charge
- Click "Change Status"
- Select: Success, Failed, or Expired
Testing Webhooksโ
Webhook Test Eventsโ
// Test webhook locally with ngrok
// 1. Start ngrok: ngrok http 3000
// 2. Add webhook URL in dashboard: https://xxx.ngrok.io/webhooks
app.post('/webhooks/omise', (req, res) => {
const event = req.body;
console.log('Test webhook received:', event.key);
console.log('Charge status:', event.data.status);
res.sendStatus(200);
});
Trigger Test Webhooksโ
From test dashboard:
- Select a test charge
- Click "Send Webhook"
- Choose event type
- Webhook fires to your endpoint
Environment Variablesโ
# .env file
NODE_ENV=development
# Test keys for development
OMISE_PUBLIC_KEY=pkey_test_5xb...
OMISE_SECRET_KEY=skey_test_5xb...
# Live keys for production (different file)
# OMISE_PUBLIC_KEY=pkey_live_5xb...
# OMISE_SECRET_KEY=skey_live_5xb...
// Load based on environment
const omise = require('omise')({
publicKey: process.env.OMISE_PUBLIC_KEY,
secretKey: process.env.OMISE_SECRET_KEY
});
// Check which mode you're in
const isTestMode = process.env.OMISE_SECRET_KEY.startsWith('skey_test_');
console.log('Running in:', isTestMode ? 'TEST' : 'LIVE');
Testing Checklistโ
Before Going Liveโ
- All payment flows tested with test cards
- 3D Secure flow tested and working
- Webhook handling tested and verified
- Error scenarios handled properly
- Refund process tested
- Mobile responsive design tested
- All payment methods tested on actual devices
- Security review completed
- Test keys replaced with live keys
- Production environment configured
Common Test Scenariosโ
1. Successful Paymentโ
// Use success test card
const token = await createToken('4242424242424242', '12/25', '123');
const charge = await omise.charges.create({
amount: 10000,
currency: 'THB',
card: token
});
assert(charge.status === 'successful');
2. Declined Cardโ
// Use decline test card
const token = await createToken('4000000000000002', '12/25', '123');
try {
const charge = await omise.charges.create({
amount: 10000,
currency: 'THB',
card: token
});
} catch (error) {
assert(error.message.includes('declined'));
}
3. 3D Secure Flowโ
// Use 3DS test card
const token = await createToken('4000000000003220', '12/25', '123');
const charge = await omise.charges.create({
amount: 10000,
currency: 'THB',
card: token,
return_uri: 'https://yourdomain.com/callback'
});
// Should have authorize_uri for 3DS
assert(charge.authorize_uri !== null);
// Test 3DS page allows success/fail selection
Best Practicesโ
1. Use Test Mode for All Developmentโ
if (process.env.NODE_ENV === 'production' && process.env.OMISE_SECRET_KEY.startsWith('skey_test_')) {
throw new Error('DANGER: Using test keys in production!');
}
2. Test Error Handlingโ
// Test various failure scenarios
const testCases = [
{ card: '4000000000000002', expected: 'card_declined' },
{ card: '4000000000009995', expected: 'insufficient_funds' },
{ card: '4000000000000069', expected: 'expired_card' }
];
for (const test of testCases) {
const token = await createToken(test.card);
// Verify error handling
}
3. Separate Test and Live Dataโ
// Different databases for test and live
const dbName = process.env.NODE_ENV === 'production'
? 'myapp_production'
: 'myapp_test';
const db = mongoose.connect(`mongodb://localhost/${dbName}`);
4. Clear Test Data Regularlyโ
Test data doesn't affect billing, but keep it tidy:
- Archive old test transactions
- Clear test customer data
- Reset test webhooks
FAQโ
Do test transactions cost money?
No. Test mode is completely free. No charges apply to test transactions.
Can I use real cards in test mode?
No. Only use test card numbers in test mode. Real card numbers will be rejected.
How do I switch from test to live mode?
Replace test API keys with live API keys. That's it! Your code stays the same.
// Change from:
OMISE_SECRET_KEY=skey_test_...
// To:
OMISE_SECRET_KEY=skey_live_...
Can I test webhooks without deploying?
Yes, use ngrok or similar tools to expose localhost:
ngrok http 3000
# Use ngrok URL in webhook settings
What happens to test data?
Test data is kept separate from production data. It won't affect reports, billing, or settlements. You can delete test data anytime.
Related Resourcesโ
- Test Cards - Full test card list
- Testing Webhooks - Webhook testing guide
- Going Live - Production checklist
Next Stepsโ
- Get your test API keys
- Implement payment flow
- Test with test cards
- Test all payment methods
- Test webhooks
- Review going live checklist
- Switch to live keys
- Go live!