Testing
Ensure your payment integration works flawlessly with comprehensive testing strategies and tools.
Thorough testing is crucial for payment systems to ensure reliability, security, and excellent user experience across all scenarios.
๐งช Sandbox Testing Safe environment for comprehensive testing
โ
Test Coverage Cover all payment scenarios and edge cases
Testing Environments
๐งช Sandbox Environment
Use Payvesselโs sandbox for safe testing:
// Sandbox configuration
const testConfig = {
baseUrl: 'https://sandbox.payvessel.com' ,
apiKey: 'PVKEY-3ZO1QOSQH83C5Q3PBCVUT1' ,
apiSecret: 'Bearer PVSECRET-OZJD0SZ2F2WOTXAF'
};
// Test client setup
const payvessel = new PayvesselClient ( testConfig );
๐ณ Test Card Numbers
Use these test cards for different scenarios:
Visa: 4111111111111111
Mastercard: 5555555555554444
American Express: 378282246310005
Discover: 6011111111111117
Use any future expiry date
Use any 3-4 digit CVV
Use any valid billing address
Generic Decline: 4000000000000002
Insufficient Funds: 4000000000009995
Lost Card: 4000000000009987
Stolen Card: 4000000000009979
Expired Card: 4000000000000069
Slow Processing: 4000000000000259
Timeout: 4000000000006975
Processing Error: 4000000000000119
3D Secure Required: 4000000000003220
3D Secure Failed: 4000000000003063
Authentication Unavailable: 4000000000003055
Testing Categories
๐ฏ Functional Testing
Test all core payment functionalities:
๐ณ Payment Processing
Single payments
Recurring payments
Refunds and cancellations
Partial refunds
๐ค Customer Management
Customer creation
Payment method storage
Customer updates
Payment history
โ ๏ธ Error Handling Testing
// Test suite for error scenarios
describe ( 'Payment Error Handling' , () => {
test ( 'handles declined card gracefully' , async () => {
const declinedCard = '4000000000000002' ;
const payment = await payvessel . payments . create ({
amount: 1000 ,
currency: 'USD' ,
payment_method: {
type: 'card' ,
card: {
number: declinedCard ,
exp_month: 12 ,
exp_year: 2030 ,
cvc: '123'
}
}
});
expect ( payment . status ). toBe ( 'failed' );
expect ( payment . failure_reason ). toBe ( 'card_declined' );
});
test ( 'handles network timeouts' , async () => {
// Simulate network timeout
const timeoutCard = '4000000000006975' ;
await expect (
payvessel . payments . create ({
amount: 1000 ,
currency: 'USD' ,
payment_method: {
type: 'card' ,
card: {
number: timeoutCard ,
exp_month: 12 ,
exp_year: 2030 ,
cvc: '123'
}
}
})
). rejects . toThrow ( 'Request timeout' );
});
});
๐ Security Testing
Verify security measures:
Invalid API keys
Expired tokens
Rate limiting
IP restrictions
Automated Testing
๐ค Test Automation Framework
// Payment test helper class
class PaymentTestHelper {
constructor () {
this . client = new PayvesselClient ({
baseUrl: 'https://sandbox.payvessel.com' ,
apiKey: process . env . PAYVESSEL_TEST_API_KEY ,
apiSecret: process . env . PAYVESSEL_TEST_API_SECRET
});
}
async createTestPayment ( amount = 1000 , currency = 'USD' , cardNumber = '4111111111111111' ) {
return await this . client . payments . create ({
amount ,
currency ,
payment_method: {
type: 'card' ,
card: {
number: cardNumber ,
exp_month: 12 ,
exp_year: 2030 ,
cvc: '123'
}
},
confirm: true
});
}
async testSuccessfulPayment () {
const payment = await this . createTestPayment ();
expect ( payment . status ). toBe ( 'succeeded' );
return payment ;
}
async testDeclinedPayment () {
const payment = await this . createTestPayment ( 1000 , 'USD' , '4000000000000002' );
expect ( payment . status ). toBe ( 'failed' );
expect ( payment . failure_reason ). toBe ( 'card_declined' );
return payment ;
}
}
๐ Test Coverage
Ensure comprehensive test coverage:
// Test matrix for different scenarios
const testMatrix = [
// Payment amounts
{ amount: 100 , description: 'Minimum amount' },
{ amount: 999999 , description: 'Maximum amount' },
{ amount: 1050 , description: 'Amount with decimals' },
// Currencies
{ currency: 'USD' , description: 'US Dollars' },
{ currency: 'EUR' , description: 'Euros' },
{ currency: 'GBP' , description: 'British Pounds' },
// Card types
{ card: 'visa' , number: '4111111111111111' },
{ card: 'mastercard' , number: '5555555555554444' },
{ card: 'amex' , number: '378282246310005' },
// Error scenarios
{ scenario: 'decline' , number: '4000000000000002' },
{ scenario: 'insufficient_funds' , number: '4000000000009995' },
{ scenario: 'timeout' , number: '4000000000006975' }
];
// Run tests for each combination
testMatrix . forEach ( test => {
it ( `should handle ${ test . description } ` , async () => {
// Test implementation
});
});
Integration Testing
๐ End-to-End Testing
Test complete user journeys:
Customer Journey
Test from product selection to payment confirmation
Webhook Delivery
Verify webhook events are received and processed
Refund Process
Test complete refund workflow
Error Recovery
Test error handling and user experience
๐ Webhook Testing
// Webhook testing utility
class WebhookTester {
constructor ( webhookEndpoint ) {
this . endpoint = webhookEndpoint ;
this . receivedEvents = [];
}
async simulateWebhook ( eventType , data ) {
const event = {
id: `evt_ ${ Date . now () } ` ,
type: eventType ,
data: data ,
created: Math . floor ( Date . now () / 1000 )
};
const signature = this . generateSignature ( event );
const response = await fetch ( this . endpoint , {
method: 'POST' ,
headers: {
'Content-Type' : 'application/json' ,
'X-Payvessel-Signature' : signature
},
body: JSON . stringify ( event )
});
return response ;
}
generateSignature ( payload ) {
const secret = process . env . WEBHOOK_SECRET ;
return crypto
. createHmac ( 'sha256' , secret )
. update ( JSON . stringify ( payload ))
. digest ( 'hex' );
}
}
// Test webhook handling
describe ( 'Webhook Processing' , () => {
const webhookTester = new WebhookTester ( 'http://localhost:3000/webhooks' );
test ( 'processes payment.succeeded event' , async () => {
const response = await webhookTester . simulateWebhook ( 'payment.succeeded' , {
payment: {
id: 'pay_123' ,
amount: 1000 ,
currency: 'USD' ,
status: 'succeeded'
}
});
expect ( response . status ). toBe ( 200 );
});
});
โก Load Testing
Test system performance under load:
// Load testing with Artillery or similar tool
const loadTestConfig = {
target: 'https://sandbox.payvessel.com' ,
phases: [
{ duration: 60 , arrivalRate: 10 }, // Warm up
{ duration: 120 , arrivalRate: 50 }, // Sustained load
{ duration: 60 , arrivalRate: 100 }, // Peak load
],
scenarios: [
{
name: 'Create Payment' ,
weight: 70 ,
flow: [
{
post: {
url: '/api/v1/payments' ,
headers: {
'api-key' : 'PVKEY-3ZO1QOSQH83C5Q3PBCVUT1' ,
'api-secret' : 'Bearer PVSECRET-OZJD0SZ2F2WOTXAF' ,
'Content-Type' : 'application/json'
},
json: {
amount: 1000 ,
currency: 'USD' ,
payment_method: 'card'
}
}
}
]
}
]
};
Monitor key performance indicators:
๐ Response Times
Average response time < 500ms
95th percentile < 1000ms
99th percentile < 2000ms
No timeouts under normal load
๐ Throughput
Requests per second
Success rate > 99.9%
Error rate < 0.1%
Concurrent user capacity
Mobile Testing
๐ฑ Device Testing
Test across different mobile devices and conditions:
iOS Testing:
Safari browser compatibility
Touch interactions
Auto-fill functionality
Different screen sizes
Android Testing:
Chrome browser compatibility
Various Android versions
Different manufacturers
Keyboard interactions
Test various network scenarios:
Slow 3G connections
Intermittent connectivity
Network timeouts
Offline scenarios
Test Data Management
๐๏ธ Test Data Strategy
// Test data factory
class TestDataFactory {
static createCustomer ( overrides = {}) {
return {
email: `test ${ Date . now () } @example.com` ,
name: 'Test Customer' ,
phone: '+1234567890' ,
... overrides
};
}
static createPayment ( overrides = {}) {
return {
amount: 1000 ,
currency: 'USD' ,
payment_method: 'card' ,
customer: this . createCustomer (),
... overrides
};
}
static getTestCard ( scenario = 'success' ) {
const cards = {
success: '4111111111111111' ,
decline: '4000000000000002' ,
insufficient_funds: '4000000000009995' ,
expired: '4000000000000069'
};
return {
number: cards [ scenario ],
exp_month: 12 ,
exp_year: 2030 ,
cvc: '123'
};
}
}
Testing Checklist
Before going live:
Functional Testing
โ
All payment flows work correctly
โ
Error handling is robust
โ
Refunds process successfully
โ
Webhooks are received and processed
Security Testing
โ
Input validation prevents injection
โ
Authentication works correctly
โ
Sensitive data is not logged
โ
Rate limiting is enforced
Performance Testing
โ
Response times meet requirements
โ
System handles expected load
โ
Error rates are acceptable
โ
Mobile performance is optimized
Integration Testing
โ
End-to-end flows work
โ
External dependencies handled
โ
Monitoring and alerting work
โ
Documentation is complete
Continuous Testing: Payment systems should be tested continuously. Set up automated tests that run with every deployment and monitor production systems for any issues.
Ready to implement comprehensive testing?