Skip to main content

Stripe Mock Server

Full mock implementation of the Stripe API. Payments, customers, subscriptions, and more.

Supported endpoints

Core resources

ResourceEndpoints
ChargesCreate, retrieve, update, list, capture
CustomersCreate, retrieve, update, delete, list
Payment IntentsCreate, retrieve, update, confirm, cancel
Payment MethodsCreate, retrieve, attach, detach, list
RefundsCreate, retrieve, update, list

Billing

ResourceEndpoints
SubscriptionsCreate, retrieve, update, cancel, list
InvoicesCreate, retrieve, finalize, pay, list
ProductsCreate, retrieve, update, delete, list
PricesCreate, retrieve, update, list

Connect

ResourceEndpoints
AccountsCreate, retrieve, update, delete, list
TransfersCreate, retrieve, list
PayoutsCreate, retrieve, list

Quick example

require 'mockworld'

Mockworld.configure do |config|
  config.api_key = ENV['MOKRA_API_KEY']
end

# Create a customer
customer = Stripe::Customer.create(
  email: "ana@example.com",
  name: "Ana Smith"
)
# => { "id": "cus_mock_abc123", "email": "ana@example.com", ... }

# Create a payment intent
payment_intent = Stripe::PaymentIntent.create(
  amount: 5000,
  currency: "usd",
  customer: customer.id,
  payment_method_types: ["card"]
)
# => { "id": "pi_mock_xyz789", "amount": 5000, "status": "requires_payment_method", ... }

# Confirm the payment
Stripe::PaymentIntent.confirm(
  payment_intent.id,
  payment_method: "pm_card_visa"
)
# => { "id": "pi_mock_xyz789", "status": "succeeded", ... }

# Create a refund
refund = Stripe::Refund.create(
  payment_intent: payment_intent.id,
  amount: 2500  # Partial refund
)
# => { "id": "re_mock_def456", "amount": 2500, "status": "succeeded", ... }

Stateful behavior

The Stripe mock maintains state across requests:
# Create a customer
customer = Stripe::Customer.create(email: "test@example.com")

# Retrieve the same customer
retrieved = Stripe::Customer.retrieve(customer.id)
# => Same customer object

# Update the customer
Stripe::Customer.update(customer.id, { name: "Updated Name" })

# List all customers
customers = Stripe::Customer.list
# => Includes the created customer

Test card numbers

Use any of these test card numbers:
NumberBehavior
4242424242424242Succeeds
4000000000000002Declines
4000000000009995Insufficient funds
4000000000000069Expired card

Error simulation

# Simulate a card decline
Mokra.simulate_error("stripe", "card_declined")

charge = Stripe::Charge.create(amount: 5000, currency: "usd")
# => Raises Stripe::CardError

Webhook testing

# Trigger a test webhook
Mokra.trigger_webhook("stripe", "charge.succeeded", {
  charge_id: "ch_test_123",
  amount: 5000
})

# Your webhook endpoint receives the event

Seeding data

world.seed do |s|
  s.stripe.customers.create(
    id: "cus_existing",
    email: "existing@example.com"
  )

  s.stripe.products.create(
    id: "prod_widget",
    name: "Widget",
    default_price: "price_5000"
  )
end

SDK compatibility

Works with the official Stripe Ruby SDK:
require 'stripe'

Stripe.api_key = "sk_test_anything"  # Any value works

# All SDK methods work
Stripe::Charge.create(...)
Stripe::Customer.create(...)
Stripe::Subscription.create(...)

Next steps