Learn how to thoroughly test your integration using our sandbox environment and automated testing tools.
Use our sandbox for safe testing without real transactions.
// Configure SDK for testing
const gopaynow = new GoPayNow({
secretKey: 'sk_test_your_test_key',
environment: 'sandbox'
});
// Test card numbers
const testCards = {
success: '4242424242424242',
declined: '4000000000000002',
insufficient_funds: '4000000000009995'
};
Test individual API functions with mocked responses.
// Jest test example
describe('Payment Link Creation', () => {
it('should create a payment link successfully', async () => {
const mockResponse = {
id: 'pl_test_123',
url: 'https://checkout.gopay.now/pl_test_123',
amount: 5000
};
gopaynow.paymentLinks.create = jest.fn().mockResolvedValue(mockResponse);
const result = await createPaymentLink(5000, 'USD');
expect(result.url).toBeDefined();
expect(result.amount).toBe(5000);
});
});
Test the complete payment flow end-to-end.
// Integration test with real sandbox API
describe('Payment Flow Integration', () => {
it('should process payment successfully', async () => {
// Create payment link
const paymentLink = await gopaynow.paymentLinks.create({
amount: 2500,
currency: 'USD'
});
expect(paymentLink.id).toMatch(/^pl_test_/);
// Simulate payment completion
const payment = await simulatePayment(paymentLink.id);
expect(payment.status).toBe('completed');
}, 10000); // 10 second timeout
});
Test webhook endpoints with simulated events.
// Test webhook endpoint
describe('Webhook Handler', () => {
it('should handle payment.completed event', async () => {
const mockEvent = {
type: 'payment.completed',
data: {
id: 'pay_test_123',
amount: 5000,
status: 'completed'
}
};
const signature = generateTestSignature(mockEvent);
const response = await request(app)
.post('/webhook')
.set('x-gopaynow-signature', signature)
.send(mockEvent)
.expect(200);
});
});
Test individual functions in isolation
Test complete payment flows
Verify event handling works correctly
Test failure cases and edge conditions