Skip to main content

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

Test invalid inputs:
  • Malformed card numbers
  • Invalid expiry dates
  • Missing required fields
  • SQL injection attempts
  • XSS payloads
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:
1

Customer Journey

Test from product selection to payment confirmation
2

Webhook Delivery

Verify webhook events are received and processed
3

Refund Process

Test complete refund workflow
4

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);
  });
});

Performance Testing

โšก 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'
            }
          }
        }
      ]
    }
  ]
};

๐Ÿ“Š Performance Metrics

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:
1

Functional Testing

โœ… All payment flows work correctly โœ… Error handling is robust โœ… Refunds process successfully โœ… Webhooks are received and processed
2

Security Testing

โœ… Input validation prevents injection โœ… Authentication works correctly โœ… Sensitive data is not logged โœ… Rate limiting is enforced
3

Performance Testing

โœ… Response times meet requirements โœ… System handles expected load โœ… Error rates are acceptable โœ… Mobile performance is optimized
4

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.