Skip to main content
All API requests made with test mode keys (sk_test_...) operate in a sandboxed environment. No real payments are processed, and test data is completely isolated from live data.

Test payment methods

Use these payment method IDs in test mode to simulate different outcomes:
Payment MethodBehavior
pm_card_visaSimulates a successful Visa payment
pm_card_declinedSimulates a card decline (generic_decline)
For tokenization flows, use the test card number 4242 4242 4242 4242 with any future expiration date and any 3-digit CVC.

Simulating a successful payment

# Create a PaymentIntent with a test payment method
curl -X POST https://api.leanrails.com/v1/payment_intents \
  -u "$API_KEY:" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "amount": 2000,
    "currency": "usd",
    "payment_method": "pm_card_visa"
  }'

# Confirm the payment
curl -X POST https://api.leanrails.com/v1/payment_intents/pi_xxx/confirm \
  -u "$API_KEY:" \
  -H "Idempotency-Key: $(uuidgen)"

Simulating a declined payment

curl -X POST https://api.leanrails.com/v1/payment_intents \
  -u "$API_KEY:" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "amount": 2000,
    "currency": "usd",
    "payment_method": "pm_card_declined"
  }'

Testing webhooks

Webhook events in test mode are delivered to your configured endpoints with livemode: false in the payload. You can verify your webhook handler processes test events correctly without affecting live data.
{
  "id": "evt_test_abc123",
  "object": "event",
  "type": "payment_intent.succeeded",
  "livemode": false,
  "data": {
    "object": {
      "id": "pi_test_xyz",
      "object": "payment_intent",
      "amount": 2000,
      "currency": "usd",
      "status": "succeeded",
      "livemode": false
    }
  }
}

Go-live checklist

1

Verify error handling

Test with pm_card_declined and confirm your integration handles decline codes gracefully.
2

Test the full payment flow

Create, confirm, and refund a PaymentIntent using pm_card_visa in test mode.
3

Configure live webhooks

Set up webhook endpoints for your production URL and subscribe to the events you need.
4

Switch to live keys

Replace sk_test_... with your sk_live_... key and start processing real payments.