Skip to content

Testing Guide

Complete guide for testing Bridge Payments integration with test cards, sandbox environments, and best practices.

Test Mode

Enable Test Mode

Use test credentials for all providers:

Stripe:

bash
STRIPE_SECRET_KEY=sk_test_...
STRIPE_PUBLISHABLE_KEY=pk_test_...

PayPal:

bash
PAYPAL_MODE=sandbox
PAYPAL_CLIENT_ID=sandbox_client_id
PAYPAL_CLIENT_SECRET=sandbox_client_secret

Authorize.net:

bash
AUTHORIZE_NET_ENVIRONMENT=sandbox
AUTHORIZE_NET_API_LOGIN_ID=sandbox_login_id
AUTHORIZE_NET_TRANSACTION_KEY=sandbox_transaction_key

Test Cards

Stripe Test Cards

Card NumberBrandResult
4242424242424242VisaSuccess
4000002500003155VisaRequires 3D Secure
4000000000009995VisaDeclined (insufficient funds)
4000000000000002VisaDeclined (generic)
4000000000000069VisaExpired card
4000000000000127VisaIncorrect CVC
5555555555554444MastercardSuccess
2223003122003222MastercardSuccess
378282246310005AmexSuccess
6011111111111117DiscoverSuccess

Expiration: Any future date (e.g., 12/25)
CVC: Any 3 digits (e.g., 123), 4 for Amex

PayPal Test Cards

Card NumberTypeResult
4111111111111111VisaSuccess
5555555555554444MastercardSuccess
378282246310005AmexSuccess
6011111111111117DiscoverSuccess

Expiration: Any future date
CVV: Any 3 digits (4 for Amex)

Authorize.net Test Cards

Card NumberTypeResult
4111111111111111VisaApproved
5424000000000015MastercardApproved
370000000000002AmexApproved
6011000000000012DiscoverApproved
4222222222222VisaDeclined

Expiration: Any future date
CVV: Any 3 digits (4 for Amex)

Testing Scenarios

1. Successful Payment

bash
curl -X POST "https://your-instance.pubflow.com/bridge-payment/payments/intents" \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: test_session_123" \
  -d '{
    "total_cents": 2000,
    "currency": "USD",
    "provider_id": "stripe",
    "card_number": "4242424242424242",
    "card_exp_month": "12",
    "card_exp_year": "2025",
    "card_cvc": "123"
  }'

2. Declined Payment

bash
curl -X POST "https://your-instance.pubflow.com/bridge-payment/payments/intents" \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: test_session_123" \
  -d '{
    "total_cents": 2000,
    "currency": "USD",
    "provider_id": "stripe",
    "card_number": "4000000000000002",
    "card_exp_month": "12",
    "card_exp_year": "2025",
    "card_cvc": "123"
  }'

3. 3D Secure Authentication

bash
curl -X POST "https://your-instance.pubflow.com/bridge-payment/payments/intents" \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: test_session_123" \
  -d '{
    "total_cents": 2000,
    "currency": "USD",
    "provider_id": "stripe",
    "card_number": "4000002500003155",
    "card_exp_month": "12",
    "card_exp_year": "2025",
    "card_cvc": "123"
  }'

4. Guest Checkout

bash
curl -X POST "https://your-instance.pubflow.com/bridge-payment/payments/intents" \
  -H "Content-Type: application/json" \
  -d '{
    "total_cents": 2000,
    "currency": "USD",
    "provider_id": "stripe",
    "card_number": "4242424242424242",
    "card_exp_month": "12",
    "card_exp_year": "2025",
    "card_cvc": "123",
    "guest_data": {
      "email": "[email protected]",
      "name": "Test User"
    }
  }'

5. Subscription

bash
curl -X POST "https://your-instance.pubflow.com/bridge-payment/subscriptions" \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: test_session_123" \
  -d '{
    "customer_id": "test_customer_123",
    "payment_method_id": "test_pm_123",
    "provider_id": "stripe",
    "total_cents": 2000,
    "currency": "USD",
    "billing_interval": "monthly",
    "trial_days": 14
  }'

Testing Webhooks

Stripe Webhook Testing

Use Stripe CLI to trigger test webhooks:

bash
# Install Stripe CLI
brew install stripe/stripe-cli/stripe

# Login
stripe login

# Forward webhooks to local server
stripe listen --forward-to localhost:3000/bridge-payment/webhooks/stripe

# Trigger test events
stripe trigger payment_intent.succeeded
stripe trigger payment_intent.failed
stripe trigger customer.subscription.created

PayPal Webhook Testing

Use PayPal Sandbox webhook simulator:

  1. Go to developer.paypal.com
  2. Navigate to WebhooksSimulator
  3. Select event type
  4. Send test webhook

Manual Webhook Testing

bash
curl -X POST "https://your-instance.pubflow.com/bridge-payment/webhooks/test" \
  -H "Content-Type: application/json" \
  -H "X-Session-ID: test_session_123" \
  -d '{
    "event": "payment_intent.succeeded",
    "test_data": {
      "payment_id": "test_pay_123",
      "amount": 2000,
      "currency": "USD"
    }
  }'

Automated Testing

Unit Tests

javascript
import { describe, it, expect } from 'vitest';
import { createPaymentIntent } from './bridge-payments';

describe('Bridge Payments', () => {
  it('should create payment intent', async () => {
    const result = await createPaymentIntent({
      total_cents: 2000,
      currency: 'USD',
      provider_id: 'stripe',
      sessionId: 'test_session_123'
    });

    expect(result).toHaveProperty('id');
    expect(result).toHaveProperty('client_secret');
    expect(result.total_cents).toBe(2000);
  });

  it('should handle declined payment', async () => {
    await expect(
      createPaymentIntent({
        total_cents: 2000,
        currency: 'USD',
        provider_id: 'stripe',
        card_number: '4000000000000002',
        sessionId: 'test_session_123'
      })
    ).rejects.toThrow();
  });
});

Integration Tests

javascript
import { describe, it, expect, beforeAll } from 'vitest';

describe('Payment Flow', () => {
  let paymentIntentId;

  beforeAll(async () => {
    // Create payment intent
    const intent = await createPaymentIntent({
      total_cents: 2000,
      currency: 'USD',
      provider_id: 'stripe',
      sessionId: 'test_session_123'
    });
    paymentIntentId = intent.id;
  });

  it('should confirm payment', async () => {
    const result = await confirmPayment(paymentIntentId, {
      card_number: '4242424242424242',
      card_exp_month: '12',
      card_exp_year: '2025',
      card_cvc: '123'
    });

    expect(result.status).toBe('succeeded');
  });

  it('should sync payment status', async () => {
    const result = await syncPaymentIntent(
      paymentIntentId,
      'test_session_123'
    );

    expect(result.status).toBe('succeeded');
  });
});

Testing Checklist

Before Going Live

  • [ ] Test successful payments
  • [ ] Test declined payments
  • [ ] Test 3D Secure authentication
  • [ ] Test guest checkout
  • [ ] Test saved payment methods
  • [ ] Test subscriptions
  • [ ] Test webhooks
  • [ ] Test error handling
  • [ ] Test edge cases (expired cards, insufficient funds)
  • [ ] Verify email receipts
  • [ ] Check payment records in database
  • [ ] Review provider dashboards
  • [ ] Test on multiple devices/browsers
  • [ ] Verify SSL/HTTPS
  • [ ] Check PCI compliance

Best Practices

  1. Use Test Mode - Always test in sandbox/test mode first
  2. Test All Scenarios - Success, failure, edge cases
  3. Automate Tests - Write unit and integration tests
  4. Monitor Webhooks - Verify webhook delivery
  5. Check Logs - Review application and provider logs
  6. Test on Real Devices - Mobile, desktop, different browsers
  7. Verify Data - Check database records match expectations

Troubleshooting

"Invalid card number"

Cause: Using production card in test mode

Solution: Use test card numbers listed above

"Webhook not received"

Cause: Webhook URL not configured or unreachable

Solution:

  1. Verify webhook URL in provider dashboard
  2. Check firewall/network settings
  3. Use webhook testing tools

"Payment stuck in processing"

Cause: Frontend didn't sync status

Solution:

  1. Call /payments/intents/:id/sync endpoint
  2. Check webhook delivery
  3. Verify payment status in provider dashboard

Next Steps