Skip to main content

Prerequisites

Before you begin, make sure you have:
  • An account on the dashboard
  • Your test mode API keys (found in Settings > API Keys)
Your test secret key looks like sk_test_... and your publishable key looks like pk_test_.... You will use the secret key for all server-side API calls.

Step 1: Get your API keys

Log in to your dashboard and navigate to Settings > API Keys. Copy your test secret key. All examples below use this key for authentication via HTTP Basic Auth.
# Your secret key is the username; the password is empty.
export API_KEY="sk_test_your_key_here"

Step 2: Create a PaymentIntent

A PaymentIntent represents a single payment attempt. Create one by specifying the amount (in cents) and currency.
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",
    "customer_id": "cus_abc123"
  }'
Response:
{
  "id": "pi_1abc123def456",
  "object": "payment_intent",
  "amount": 2000,
  "currency": "usd",
  "status": "requires_confirmation",
  "payment_method": "pm_card_visa",
  "customer_id": "cus_abc123",
  "metadata": {},
  "livemode": false,
  "created_at": "2026-03-09T10:00:00Z",
  "updated_at": "2026-03-09T10:00:00Z"
}

Step 3: Confirm the PaymentIntent

Once created, the PaymentIntent is in requires_confirmation status. Confirm it to initiate the charge.
curl -X POST https://api.leanrails.com/v1/payment_intents/pi_1abc123def456/confirm \
  -u "$API_KEY:" \
  -H "Idempotency-Key: $(uuidgen)"
Response:
{
  "id": "pi_1abc123def456",
  "object": "payment_intent",
  "amount": 2000,
  "currency": "usd",
  "status": "succeeded",
  "payment_method": "pm_card_visa",
  "customer_id": "cus_abc123",
  "metadata": {},
  "livemode": false,
  "created_at": "2026-03-09T10:00:00Z",
  "updated_at": "2026-03-09T10:00:05Z"
}

Step 4: Check the status

You can retrieve any PaymentIntent at any time to check its current status.
curl https://api.leanrails.com/v1/payment_intents/pi_1abc123def456 \
  -u "$API_KEY:"

PaymentIntent statuses

StatusMeaning
requires_confirmationCreated but not yet confirmed
processingConfirmation received, payment is being processed
succeededPayment completed successfully
failedPayment failed
canceledPayment was canceled

Next steps