Razorpay PHP
Official PHP client for the Razorpay payments, orders, and subscriptions API
Repository Health
Technical Analysis
Razorpay PHP is the official client library for Razorpay’s payment gateway API, giving PHP applications typed access to orders, payments, refunds, subscriptions, invoices, and payment links. Rather than exposing errors as return values, the library follows an exception-based error model and accepts request options as associative arrays, keeping call sites consistent across the dozens of Razorpay resources it wraps (payments, customers, cards, tokens, transfers, settlements, disputes, and more).
Beyond basic charge creation, the library covers Razorpay’s broader payments platform: recurring billing via subscriptions and e-mandate/NACH registration, virtual accounts, QR codes, OAuth-based Partner integrations, and webhook signature verification for securely validating incoming payment notifications. It is the standard integration path for PHP applications (including Laravel/WordPress e-commerce stacks) accepting payments through Razorpay in India and supported markets.
What You Get
- Typed resource classes covering payments, orders, refunds, customers, cards, tokens, transfers, and settlements
- Subscription and recurring-payment support, including e-mandate and NACH (paper/register) registration flows
- Webhook signature verification helpers for validating incoming Razorpay event payloads
- OAuth client support for Razorpay Partner integrations authenticating on behalf of merchant accounts
- Consistent exception-based error handling instead of error-code return values across every resource
Common Use Cases
- Accepting one-time and recurring payments in a PHP e-commerce or SaaS application via Razorpay Orders and Payments
- Setting up subscription billing with e-mandate/NACH-based recurring debit registration for Indian bank accounts
- Verifying Razorpay webhook signatures server-side before processing payment status updates
- Building Razorpay Partner integrations that manage payments on behalf of connected merchant accounts via OAuth
Under The Hood
Architecture Razorpay.php is the package’s autoload entry point pulling in the Razorpay\Api namespace under src/, where Api.php acts as the central client that instantiates resource classes (Order.php, Payment.php, Subscription.php, Invoice.php, Transfer.php, and more, each extending a shared Entity.php/Resource.php base) and delegates HTTP calls to Request.php. OAuth.php/OAuthClient.php/OAuthValidator.php implement the separate OAuth-based Partner authentication flow, and Utility.php provides webhook signature verification. Every resource follows the same create/fetch/all/update pattern against Resource.php, keeping the dozens of endpoint wrappers structurally consistent. Tech Stack Supports PHP 7.3 through 8.1+ with no heavyweight framework dependency, making it usable directly in plain PHP, Laravel, or WordPress integrations; it ships its own lightweight HTTP request handling rather than depending on Guzzle or a PSR HTTP client. Code Quality The tests/ directory contains one dedicated PHPUnit test file per resource (PaymentTest, SubscriptionTest, RefundTest, SignatureVerificationTest, TokenTest, TransferTest, and around 25 more), plus a CoverageTest.php and separate non_composer_tests/ for validating the manual-download integration path — indicating deliberate parity testing across the library’s broad resource surface. API Design The library documents an explicit convention (namespaced under Razorpay\Api, exceptions instead of error returns, array-based options) that keeps every resource’s call shape predictable once learned, though the sheer number of resource classes and Razorpay-specific concepts (e-mandate, NACH, virtual accounts) means new integrators need to consult Razorpay’s own API docs alongside the library’s README.
Used by 2 apps in this directory
Bagisto
Analytics · Ecommerce
Open-source Laravel eCommerce platform for building multi-vendor marketplaces, B2B stores, headless commerce, and AI-powered storefronts.
Invoice Ninja
Invoicing Finance · Project Management
Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.