Overview
Razorpay is India’s leading payment gateway, offering:- Credit and debit card payments
- Net banking
- UPI (Unified Payments Interface)
- Wallets (Paytm, PhonePe, etc.)
- EMI options
- International cards
- INR currency support
Prerequisites
- A Razorpay account (Sign up here)
- KYC verification completed
- Business bank account linked
- GST number (for Indian businesses)
Setup Instructions
Create Razorpay Account
- Visit Razorpay Signup
- Enter business details
- Verify email and mobile number
- Complete KYC verification
- Link your business bank account
Get API Keys
- Log in to Razorpay Dashboard
- Go to Settings → API Keys
- Click Generate Test Keys or Generate Live Keys
Configure Environment Variables
Add Razorpay credentials to your For Live Mode:
.env file:For Test Mode:Always start with test keys during development.
Testing the Integration
Use Test Cards
Razorpay provides test cards for different scenarios:Successful Payment:Payment Failed:3D Secure Authentication:Full test card list
Payment Flow
Implementation Details
Razorpay Gateway Service
SeeRazorpayGateway.php for implementation:
RazorpayGateway.php (lines 8-51)
Payment Verification
RazorpayGateway.php (lines 58-95)
Razorpay Controller
Key routes (seeroutes/razorpay.php):
| Route | Method | Description |
|---|---|---|
/razorpay/payment | POST | Create Razorpay order |
/razorpay/callback | POST | Payment verification callback |
/razorpay/webhook | POST | Webhook endpoint |
RazorpayController.php
Supported Payment Methods
Razorpay supports multiple payment methods:Cards
- Credit cards (Visa, Mastercard, Amex, RuPay)
- Debit cards
- International cards
- EMI options
UPI
- Google Pay
- PhonePe
- Paytm
- BHIM
- All UPI apps
Net Banking
- All major Indian banks
- 58+ bank options
Wallets
- Paytm
- PhonePe
- Mobikwik
- Freecharge
- Ola Money
Buy Now Pay Later
- LazyPay
- PayLater
- Simpl
Enable specific payment methods in Razorpay Dashboard under Settings → Payment Methods.
Webhook Configuration
Set up webhooks for real-time payment notifications:Create Webhook
- In Razorpay Dashboard, go to Settings → Webhooks
- Click + Add New Webhook
- Enter webhook URL:
- Enter a webhook secret (store this securely)
Select Events
Subscribe to these events:
payment.capturedpayment.failedorder.paidrefund.createdrefund.processed
Currency Support
Razorpay primarily supports INR (Indian Rupee):- USD, EUR, GBP supported
- Requires international payments activation
- Contact Razorpay support to enable
Amount Conversion
Razorpay uses paisa (1 INR = 100 paisa):Payment Modes
Test Mode
- No real money processed
- All payment methods available
- Test cards work
- Separate dashboard section
- No settlements
Live Mode
- KYC completed
- Bank account verified
- Activation approved by Razorpay
- HTTPS enabled
- Proper error handling
Security Features
Signature Verification
Always verify Razorpay signatures:Webhook Signature Verification
Error Handling
Common Razorpay errors:| Error Code | Description | Solution |
|---|---|---|
BAD_REQUEST_ERROR | Invalid parameters | Check request data |
GATEWAY_ERROR | Payment gateway issue | Retry or contact bank |
SERVER_ERROR | Razorpay server error | Retry after some time |
AUTHENTICATION_ERROR | Invalid API keys | Verify credentials |
INVALID_AMOUNT | Amount validation failed | Check amount format |
Troubleshooting
Authentication Error
Authentication Error
Problem:
Authentication failed errorSolution:- Verify Key ID and Secret are correct
- Ensure no extra spaces in
.envfile - Check you’re using test keys in test mode
- Confirm keys are active in Razorpay Dashboard
- Clear config cache:
php artisan config:clear
Signature Verification Failed
Signature Verification Failed
Problem: Signature mismatch errorSolution:
- Ensure you’re using correct secret for signature
- Verify order ID and payment ID are correct
- Check the order of parameters in hash_hmac
- Don’t modify orderId or paymentId
- Use exact format:
orderId|paymentId
Payment Successful But Not Captured
Payment Successful But Not Captured
Problem: Payment authorized but not capturedSolution:
- Set
payment_capture => 1in order creation - Or manually capture the payment:
- Check auto-capture is enabled in dashboard
Webhook Not Received
Webhook Not Received
Problem: Webhooks not hitting endpointSolution:
- Verify webhook URL is publicly accessible
- Ensure HTTPS is enabled
- Check webhook secret matches
- Test with Razorpay webhook simulator
- Review webhook logs in Razorpay Dashboard
- Verify firewall allows Razorpay IPs
Test Card Declined
Test Card Declined
Problem: Test payment failingSolution:
- Use correct test card:
4111 1111 1111 1111 - Ensure you’re in test mode (using test keys)
- Try different test cards
- Check CVV is any 3 digits
- Use any future expiry date
Amount Mismatch
Amount Mismatch
Problem: Wrong amount chargedSolution:
- Remember to convert to paisa (multiply by 100)
- Check currency is INR
- Verify amount calculation logic
- Don’t mix rupees and paisa
Razorpay Dashboard
Key sections:- Transactions: View all payments
- Orders: Track order status
- Customers: Customer database
- Settlements: Payout information
- Reports: Download transaction reports
- Disputes: Handle customer disputes
- API Keys: Manage credentials
- Webhooks: Monitor webhook delivery
Advanced Features
Recurring Payments
Create subscription plans:Payment Links
Generate payment links:Refunds
Process refunds:Going Live Checklist
Complete KYC
- Submit business documents
- Verify bank account
- Submit GST details (if applicable)
- Wait for Razorpay approval
Enable Payment Methods
- Select payment methods in dashboard
- Configure EMI options if needed
- Set up international payments if required
Transaction Fees
Razorpay pricing (India): Standard Pricing:- Domestic cards: 2% per transaction
- UPI: 2% per transaction
- Net Banking: 2% per transaction
- Wallets: 2% per transaction
- International cards: 3% + GST
- First ₹25 lakh: 2%
- Beyond ₹25 lakh: Negotiable
Pricing may vary based on business volume. Contact Razorpay for custom pricing.
Next Steps
Stripe Integration
Add Stripe for international payments
PayPal Integration
Configure PayPal payment gateway
Payment Overview
View all payment gateways
Subscription Management
Manage subscriptions