HyperSwitch PHP SDK now covers all 150 operations, and it's open source
Ask AI about this article
Home / Blog / HyperSwitch PHP SDK now covers all 150 operations, and it's open source
HyperSwitch SDK progress, part two. Part one is the first release, from May.
Our HyperSwitch PHP SDK now covers all 150 operations in HyperSwitch's v1 OpenAPI spec, up from roughly 83 endpoints when we wrote about it in May. It's open source under the MIT license, on GitHub at X2Y-DEV/Hyperswitch-PHP-SDK, and Composer installs it straight from that repository. A drift test fails the build whenever the SDK and HyperSwitch's spec disagree, so "all 150" stays true as the API moves.
What changed in the HyperSwitch PHP SDK since May?
In May the client covered 17 resource groups, about 83 endpoints, and inbound webhooks. Release 0.2.0, tagged on November 23, covers every operation in the spec: 150 of 150.
That's the payments core you'd expect (payments, refunds, customers, mandates, subscriptions, disputes, payouts, payment links) and the operational side a real integration runs into sooner or later: API keys, business profiles, merchant accounts, connectors, routing, 3-D Secure decision rules, blocklists and event delivery.
Each operation gets its own typed request and response objects, built from the spec's own schemas. Response fields the SDK doesn't know yet are kept rather than dropped, so a non-breaking addition on HyperSwitch's side doesn't crash your integration. All six of HyperSwitch's auth tiers are handled, from merchant and publishable keys to admin, ephemeral, profile-scoped keys and JWTs.
How is the SDK kept in step with HyperSwitch's spec?
A payment API keeps changing. An SDK that can't tell when it has fallen behind quietly breaks the checkout it serves, so the repository is built around one question: does the SDK still match the API?
- A pinned spec. The repo keeps a copy of HyperSwitch's own v1 OpenAPI spec, pinned to a specific HyperSwitch commit by a script.
- A drift test.
OpenApiCoverageTestcompares the SDK with that spec in both directions. It fails if the spec has an operation the SDK lacks, or the SDK has one the spec doesn't. - Static analysis. PHPStan at level 8, with strict rules.
- Every supported PHP version. CI runs on PHP 8.1, 8.2, 8.3 and 8.4.
When HyperSwitch ships an API change, catching up is a short loop: re-pin the spec, run the drift test, fill the gaps it lists, run the checks, tag a release. The steps are written down in the repository, so it doesn't depend on any one of us remembering them.
Why is the HyperSwitch PHP SDK open source?
We built it while working with a payment provider we work with, which asked us to look into HyperSwitch. We told them from the start that the client would be open source.
The reasoning is simple. HyperSwitch itself is open source (Apache 2.0), and a big part of its appeal is that you can read the code that moves your money. A closed PHP client sitting in front of it would undo that. A payment client is infrastructure, too: it's more useful to more people as a shared, readable library than as something rebuilt inside every project that needs one.
So it carries no framework at all. There are no Magento, Laravel or Symfony imports under src/, and the drift test enforces that. It drops into Adobe Commerce, Magento Open Source and Mage-OS the same way it drops into Laravel, Symfony or plain PHP.
How do you install the HyperSwitch PHP SDK?
It isn't on Packagist. Add the GitHub repository once, then require a tagged release:
composer config repositories.hyperswitch-client vcs https://github.com/X2Y-DEV/Hyperswitch-PHP-SDK
composer require x2y/hyperswitch-client:^0.2
It needs PHP 8.1 or newer. It talks to HyperSwitch through any PSR-18 HTTP client: Guzzle and Laminas Diactoros come with the package, and you can pass your own instead. Creating a payment in the sandbox looks like this:
use GuzzleHttp\Client as GuzzleClient;
use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\StreamFactory;
use X2Y\HyperSwitchClient\HyperSwitchClient;
use X2Y\HyperSwitchClient\Auth\MerchantKeyAuthResolver;
use X2Y\HyperSwitchClient\Dto\Payment\Request\CreatePaymentRequest;
use X2Y\HyperSwitchClient\Enum\Currency;
$client = HyperSwitchClient::sandbox(
httpClient: new GuzzleClient(),
requestFactory: new RequestFactory(),
streamFactory: new StreamFactory(),
auth: [new MerchantKeyAuthResolver('snd_…')],
);
$response = $client->payments()->create(new CreatePaymentRequest(
amount: 4500,
currency: Currency::USD,
));
How does it handle HyperSwitch webhooks?
HyperSwitch signs every webhook body with an HMAC, SHA-512 by default. The SDK checks the signature before it parses a byte of the body, then decodes the event into a typed object. An event type it doesn't know yet still comes through, raw, so a new event on HyperSwitch's side never gets silently lost.
What's next in the series?
This is part two of a running series on the SDK's progress. Each milestone gets its own post, linked from the one before.
For the whole picture in one place, the HyperSwitch PHP SDK page has what it covers, how it's maintained, and a 75-second film of it. The code, the changelog and the maintenance steps are on GitHub.
Building on HyperSwitch from PHP, or need a payment module on top of it for your platform? Tell us what you're building, and we'll tell you what it takes.