Laravel 10–13 · Payment SDK · v0.4.1 · MIT

One clean interface. Every payment gateway.

A self-contained, multi-gateway payment SDK for PHP. A factory resolves the right driver, a swappable HTTP transport does the talking, and one contract covers CyberSource Unified Checkout, Fawry, Paymob, PayLink, PayTabs, PayPal, Mastercard MPGS and Authorize.Net.

Read the docs → Quick start
01

Built like infrastructure,
not a wrapper.

Domain-driven layers keep the business rules clean and the network at arm's length.

/01

Domain-driven layering

A pure Domain of contracts, commands, results, value objects and enums; a thin Application factory; and an Infrastructure layer for drivers & Laravel adapters. Dependencies point inward — the core never touches the framework.

/02

Factory + one interface

Resolve any gateway through PaymentGatewayFactory and program against a single PaymentGatewayInterface. Unsupported operations throw UnsupportedOperationException, so the surface is identical everywhere.

/03

Ports & adapters

The HttpClient and CredentialResolver ports live in the Domain; adapters live in Infrastructure. Ship the retrying Laravel transport in production, swap the in-memory fake in tests — bind only the port you want to replace.

/04

Raw REST, no vendor SDKs

Every driver speaks the gateway's REST API directly and signs its own requests — CyberSource HMAC HTTP-Signature, Fawry SHA-256, Paymob HMAC-SHA512, PayLink HMAC-SHA256, PayTabs server-key auth with HMAC-SHA256 callbacks, PayPal OAuth 2.0 client credentials, Mastercard MPGS HTTP Basic auth, Authorize.Net name/transaction-key auth. No heavy third-party gateway dependencies.

/05

Deterministic & idempotent

Request bodies are built without hidden uniqid()/time(), so identical inputs produce byte-for-byte identical requests. Every write carries an idempotency key routed to the gateway's native dedup — retries are safe.

/06

Exact money, strict types

Amounts are carried as minor units and never rounded. PHPStan runs at level max with a zero baseline, formatted with Pint, refactor-checked with Rector, and covered by 290+ database-free Pest tests.

/07

Events & listeners

Each driver emits a typed domain event after every operation — charge, capture, refund, void, vault, checkout, webhook. One listener on the PaymentEvent interface receives them all, or target a single event. Payloads are queue-safe: ids, amount and result — never the raw request or card data.

02

Eight gateways.
One PaymentGatewayInterface.

Each driver extends AbstractPaymentGateway and implements the same fat contract.

CyberSourceHMAC HTTP-Signature

Unified Checkout

Mint a capture context for the widget, charge the transient token or run the orchestrated flow and verify the signed result JWT, run 3-DS payer-auth, and vault instruments for MIT/CIT stored credentials.

capture context · charge · orchestrated confirm · 3-DS · TMS vault
FawrySHA-256

Hosted & reference

Start a hosted checkout — card, wallet, pay-at-Fawry, MyFawry or instalment — and redirect the payer or hand back a reference code.

hosted · card · wallet · pay-at-Fawry
PaymobHMAC-SHA512

Iframe flow

Runs the auth → order → payment-key handshake in one call and returns the iframe URL. Integration & iframe ids come from credentials or per-call options.

auth → order → payment key → iframe
PayLinkHMAC-SHA256

Invoice link

Create an invoice, then redirect to the hosted checkout or embed it in an iframe, and reconcile later by invoice id. Supports settle, refund, void, reverse-authorization, and card tokenization — store a card in the TMS-backed vault, charge it as a stored credential, and revoke it.

invoice · iframe · settle · refund · reverse · vault · charge
PayTabsServer key

Every integration

Hosted page, emailable Invoice, reusable PayLink, iframe Managed Form, or an Own Form charge of a payment token. Saves card tokens for recurring / customer-initiated charges, starts repeat-billing agreements, splits settled funds across beneficiaries, and verifies the signed IPN callback.

hosted · invoice · paylink · managed · own form · tokens · recurring · split
PayPalOAuth 2.0

Orders v2 checkout

Create an order and redirect the buyer to approve it, then capture or authorize the approved order with charge. Captures, voids and refunds act on the payment resources; cards vault via the setup-token → payment-token flow for card-on-file charges, and webhooks verify through PayPal's signature API.

order · approval redirect · capture · authorize · vault · MIT/CIT
Mastercard MPGSHTTP Basic

Order & transaction

Initiate a Hosted Checkout session, then PAY or AUTHORIZE it against the merchant-assigned order and transaction ids. Captures, refunds, voids and reversals settle against the order; cards tokenize for stored-credential charges, 3-D Secure runs through the authentication operations, and webhooks verify with the notification secret.

hosted checkout · pay/authorize · capture · refund · void · 3-DS · token · MIT/CIT
Authorize.NetName / Transaction Key

Accept.js charge

Charge an Accept.js opaque-data token — the card is tokenised in the browser, so no PAN reaches your server — then capture, refund or void by transaction id. Vault the same token into a CIM profile for MIT/CIT stored-credential charges, look up a transaction for reconciliation, and verify the HMAC-SHA512 webhook signature.

Accept.js charge · capture · refund · void · CIM vault · getTransaction · webhook
03

The operation matrix.

What each driver supports. Anything unsupported throws — the surface never lies.

Operation CyberSource UC Fawry Paymob PayLink PayTabs PayPal Mastercard MPGS Authorize.Net
createCheckoutSessioncapture context / orchestratedhosted / card / walletiframe flowinvoice / iframehosted / invoice / paylink / managedorder → approvalhosted checkout
charge (transient token)Own Formapproved ordersessionAccept.js
confirmOrchestratedPayment (verify result JWT)RS256 · flx.jwk
captureAuth/Capturesettle
refund
voidcancel auth
reverseAuthorizationrelease
enroll / validatePayerAuth (3-DS)
vault / chargeStoredCredentialTMS · MIT/CITvault · charge · revoketoken · MIT/CITvault · MIT/CITtoken · MIT/CITCIM · MIT/CIT
getTransaction / searchTransactionqueryorder lookuporder lookuptransaction details
verifyWebhookAPIsecretHMAC-SHA512
1 / 8 tap a card to cycle
CyberSource UCHMAC HTTP-Signature
createCheckoutSession
capture context
charge
confirmOrchestratedPayment
verify result JWT
capture
refund
void
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
TMS · MIT/CIT
getTransaction / searchTransaction
verifyWebhook
FawrySHA-256
createCheckoutSession
hosted / card / wallet
charge
capture
Auth/Capture
refund
void
cancel auth
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
getTransaction / searchTransaction
verifyWebhook
PaymobHMAC-SHA512
createCheckoutSession
iframe flow
charge
capture
refund
void
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
getTransaction / searchTransaction
verifyWebhook
PayLinkHMAC-SHA256
createCheckoutSession
invoice / iframe
charge
capture
settle
refund
void
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
vault · charge · revoke
getTransaction / searchTransaction
verifyWebhook
PayTabsServer key
createCheckoutSession
hosted / invoice / paylink / managed
charge
Own Form
capture
refund
void
reverseAuthorization
release
enroll / validatePayerAuth
vault / chargeStoredCredential
token · MIT/CIT
getTransaction / searchTransaction
query
verifyWebhook
PayPalOAuth 2.0
createCheckoutSession
order → approval
charge
approved order
capture
refund
void
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
vault · MIT/CIT
getTransaction / searchTransaction
order lookup
verifyWebhook
Mastercard MPGSHTTP Basic
createCheckoutSession
hosted checkout
charge
session
capture
refund
void
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
token · MIT/CIT
getTransaction / searchTransaction
order lookup
verifyWebhook
secret
Authorize.NetName / Transaction Key
createCheckoutSession
charge
Accept.js
capture
refund
void
reverseAuthorization
enroll / validatePayerAuth
vault / chargeStoredCredential
CIM · MIT/CIT
getTransaction / searchTransaction
transaction details
verifyWebhook
HMAC-SHA512
04

From zero to charged.

The provider auto-registers the factory and ports. Inject the factory — no service location, no new.

  1. 1 Install

    # Composer auto-discovers the service provider
    composer require hyprpay/payments
  2. 2 Configure (optional)

    php artisan vendor:publish --tag=gateway-config
  3. 3 Bind your ports

    $this->app->bind(HttpClient::class, MyHttpClient::class);
    $this->app->bind(CredentialResolver::class, MyCredentialResolver::class);

    External services are fully decoupled. CredentialResolver seamlessly resolves single-tenant static configs and multi-tenant per-tenant credentials.

  4. 4 Charge

    $gateway = $this->gateways->make(GatewayName::Fawry);
    $gateway->charge($request);

    One charge() call works across every gateway. The factory resolves the driver, so you program against one contract.

Read the docs
app/Actions/ChargeInvoice.php
use Hyprpay\Payments\Domain\Command\ChargeRequest;
use Hyprpay\Payments\Domain\ValueObject\Money;
use Hyprpay\Payments\Domain\Enum\GatewayName;
use Hyprpay\Payments\Application\PaymentGatewayFactory;

final readonly class ChargeInvoice
{
    // Type-hint the factory; Laravel injects it.
    public function __construct(
        private PaymentGatewayFactory $gateways,
    ) {}

    public function handle(string $tokenFromWidget): void
    {
        $gateway = $this->gateways->make(
            GatewayName::CybersourceUnifiedCheckout,
        );

        $result = $gateway->charge(new ChargeRequest(
            transientToken: $tokenFromWidget,
            money: Money::minor(10000, 'EGP'), // 100.00, exact
            orderReference: 'ORDER-123',     // = idempotency key
        ));

        if ($result->success) {
            // $result->status, ->transactionId, ->raw
        }
    }
}

Retries are safe by construction: bodies are deterministic and every write carries an idempotency key — routed to v-c-idempotency-key, merchantRefNum, merchant_order_id, or an Idempotency-Key / PayPal-Request-Id header, per gateway.

Program against one contract.
Let the factory pick the driver.

Requires PHP ^8.2 · illuminate/support & illuminate/http ^10 | ^11 | ^12 | ^13 · firebase/php-jwt ^6.10 | ^7.0

What's new