Testing Guide

Learn how to properly test your ZenPay integration before deploying to production.

Last updated: July 25, 2023
Next: Security Best Practices

Test Mode Overview

ZenPay provides a dedicated test environment that mirrors our production system. This allows you to test your integration thoroughly without processing real payments or affecting your live data.

Test Mode Features

  • Full API access with test credentials
  • Simulated payment processing
  • Test webhooks and events
  • Separate test dashboard

Test vs Live Keys

API keys are prefixed to indicate their environment:
pk_test_xxxxx - Test publishable key
sk_test_xxxxx - Test secret key
pk_live_xxxxx - Live publishable key
sk_live_xxxxx - Live secret key

Test Cards and Payment Methods

Use these test cards to simulate various payment scenarios without processing real transactions.

Card NumberBrandCVCDateResult
4242 4242 4242 4242VisaAny 3 digitsAny future dateSuccess
4000 0025 0000 3155VisaAny 3 digitsAny future dateRequires Authentication
4000 0000 0000 9995VisaAny 3 digitsAny future dateInsufficient Funds
4000 0000 0000 0002VisaAny 3 digitsAny future dateCard Declined
5555 5555 5555 4444MastercardAny 3 digitsAny future dateSuccess
3782 8224 6310 005American ExpressAny 4 digitsAny future dateSuccess

Note: For testing international payments, use test card numbers with postal codes from different countries. Each test card can be used with any valid expiration date in the future and any random CVC number.

Testing Webhooks

To properly test your webhook integration, you need to:

1

Set up a webhook endpoint

Create an endpoint on your server to receive webhook events. For local development, you can use tools like ngrok or localtunnel to expose your local server to the internet.

# Example: Exposing a local server on port 3000 ngrok http 3000
2

Register your endpoint in the dashboard

Go to the Developers → Webhooks section in your ZenPay Dashboard and add your webhook URL. Make sure to select the events you want to receive.

3

Trigger test events

You can trigger test webhook events in several ways:

  • Create test payments from the API
  • Use the "Send test webhook" button in the dashboard
  • Manually create resources through the dashboard
4

Verify webhook signatures

Always verify that the webhooks you receive are sent by ZenPay by checking the signature:

// Node.js example const event = zenpay.webhooks.constructEvent( payload, signature, webhookSecret ); // If the signature is invalid, constructEvent will throw an error

Testing Best Practices

Test the customer experience

Use our checkout testing tools to simulate the full payment flow from the customer's perspective, including form validation, error handling, and success states.

Test error scenarios

Don't just test the happy path. Use our test cards to trigger various error scenarios and ensure your application handles them gracefully, providing appropriate feedback to users.

Test your integration end-to-end

Confirm that the entire payment flow works as expected, from collecting payment information to fulfilling orders or granting access to content after successful payments.

Use automated testing

Implement automated tests for your ZenPay integration to catch regressions early. Our API is designed to be testable, with predictable responses for test cards and scenarios.

Moving to Production

Once you've thoroughly tested your integration, follow these steps to go live:

1

Complete your ZenPay account setup

Ensure all required business information is provided and verified in your ZenPay account.

2

Switch to live API keys

Replace your test API keys with live keys. Make sure to update all instances, including your webhook endpoints.

3

Perform a live test

Make a small real payment to verify that your production setup works correctly. You can refund this payment immediately after verification.

4

Monitor your integration

Set up monitoring and alerting for payment failures, webhook delivery issues, and other critical events to quickly identify and resolve any problems.

Next Steps

Ensure your integration is secure and compliant by reviewing our security guidelines:

Security Best Practices

Learn how to keep your integration secure

PCI Compliance

Understand your compliance responsibilities

Was this helpful?