RailsPaymentSandbox simulates multiple payment gateways locally with fake transactions for development and testing purposes. It saves developers from needing real API keys, sandbox accounts, or actual money movement when testing payment flows.
- 🔌 Supports multiple gateways:
StripeRazorpayPayPalPaytmGoogle Pay (GPay)Apple PayPhonePeAmazon PayCashfree
- 🎲 Random or controlled statuses:
success,failed,pending - 🧾 Generates fake
transaction_idandorder_id - 🛠 No real API calls, safe for local and CI environments
- 📊 Easy integration with RSpec or Rails apps
Add this line to your Gemfile:
gem 'payment_sandbox_rails'And then run:
bundle installOr install it yourself:
gem install payment_sandbox_railsrequire "rails_payment_sandbox"
# Create a new sandbox payment (random status)
payment = RailsPaymentSandbox::Gateway.new(
gateway: :stripe,
amount: 1000, # amount in smallest unit (e.g. paise for INR)
currency: "INR"
)
result = payment.process
puts result
# {
# gateway: :stripe,
# order_id: "ORD-1696212345-4821",
# transaction_id: "STR-1696212345-4821",
# amount: 1000,
# currency: "INR",
# status: :success,
# message: "Stripe payment completed successfully"
# }payment = RailsPaymentSandbox::Gateway.new(
gateway: :razorpay,
amount: 500,
status: :failed
)
puts payment.process
# => { gateway: :razorpay, status: :failed, message: "Razorpay payment failed", ... }payment = RailsPaymentSandbox::Gateway.new(
gateway: :paypal,
amount: 1500,
order_id: "ORD-TEST-12345"
)
puts payment.process[:order_id]
# => "ORD-TEST-12345"After checking out the repo, run:
bin/setup
rake specYou can also run bin/console for an interactive prompt.
To install this gem onto your local machine:
bundle exec rake installTo release a new version:
- Update the version number in
lib/rails_payment_sandbox/version.rb. - Run
bundle exec rake release(this will create a git tag, push commits/tags, and publish to rubygems.org).
Bug reports and pull requests are welcome on GitHub: 👉 https://github.com/[USERNAME]/rails_payment_sandbox
This project is licensed under the MIT License.