PHPackages                             hafizasifali/cardstream-php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. hafizasifali/cardstream-php-sdk

ActiveLibrary

hafizasifali/cardstream-php-sdk
===============================

Composer-installable PHP SDK for the Cardstream Payment Gateway (Direct &amp; Hosted integration, 3DSv2 support), with optional plug-and-play Laravel integration.

00PHPCI passing

Since Jul 28Pushed todayCompare

[ Source](https://github.com/hafizasifali/cardstream-php-sdk)[ Packagist](https://packagist.org/packages/hafizasifali/cardstream-php-sdk)[ RSS](/packages/hafizasifali-cardstream-php-sdk/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Cardstream PHP SDK (Composer Package)
=====================================

[](#cardstream-php-sdk-composer-package)

[![Latest Stable Version](https://camo.githubusercontent.com/388bd8ccccd3ac690c5ec3bd6b4ceba384ec84bd19b410e1a80925a33f5c0e6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f686166697a61736966616c692f6361726473747265616d2d7068702d73646b2e737667)](https://packagist.org/packages/hafizasifali/cardstream-php-sdk)[![License](https://camo.githubusercontent.com/6915f87c4e3489c80c0cf30dadd7656e16cb588dde99079351b07dc04557831f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686166697a61736966616c692f6361726473747265616d2d7068702d73646b2e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/aa62061de6f06397ce30f5b4b1407b932032d739261d8c7e9c65af2efe51ed2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f686166697a61736966616c692f6361726473747265616d2d7068702d73646b2e737667)](composer.json)

A Composer-installable, PSR-4 autoloaded package for the official [Cardstream Payment Gateway PHP SDK](https://github.com/cardstream/PHP-SDK), with a plug-and-play Laravel integration (auto-discovered ServiceProvider, Facade, and `config/cardstream.php`) layered on top. Works standalone in any core PHP 7.4+/8.x codebase with zero Laravel dependency.

The upstream SDK ships as a single `gateway.php` file meant to be manually `require`'d. This package repackages the same `\P3\SDK\Gateway` class so it can be installed and autoloaded via Composer, and published to [Packagist](https://packagist.org) for the community.

> The SDK logic itself is unmodified from Cardstream's official release, other than guarding a few `$_SERVER` lookups so the SDK doesn't emit PHP warnings when called outside a live HTTP request (Artisan commands, queued jobs, tests) — see [CHANGELOG.md](CHANGELOG.md). This project's primary job is Composer/PSR-4 packaging around it.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Usage (core PHP)](#usage)
    - [Direct Integration](#direct-integration)
    - [Hosted Integration](#hosted-integration)
    - [3DSv2 Browser Info](#3dsv2-browser-info)
- [Laravel Integration](#laravel-integration)
- [Configuration Reference](#configuration-reference)
- [Testing](#testing)
- [License](#license)
- [Disclaimer](#disclaimer)

Installation
------------

[](#installation)

```
composer require hafizasifali/cardstream-php-sdk
```

Nothing else to wire up: in a Laravel app the `CardstreamServiceProvider`and `Cardstream` facade are auto-discovered via Composer's `extra.laravel`metadata (no manual `config/app.php` edits needed). In a plain PHP project `P3\SDK\Gateway` is available as soon as `vendor/autoload.php` is loaded — the Laravel classes simply aren't touched.

Prerequisites
-------------

[](#prerequisites)

- PHP 7.4+ (tested on PHP 7.4 through 8.5)
- `ext-curl` (falls back to PHP stream wrappers if unavailable)
- HTTPS enabled on your server for direct integration (the gateway responds over SSL)
- Laravel integration additionally requires `illuminate/support` — already present in any Laravel 8–12 app, nothing extra to install

Usage (core PHP)
----------------

[](#usage-core-php)

Set your Merchant ID and secret before making a request:

```
require 'vendor/autoload.php';

use P3\SDK\Gateway;

Gateway::$merchantID = '100856';
Gateway::$merchantSecret = 'YourMerchantSecretHere';
```

### Direct Integration

[](#direct-integration)

```
$request = [
    'merchantID'       => 100001,
    'action'           => 'SALE',
    'type'             => 1,
    'currencyCode'     => 826,
    'countryCode'      => 826,
    'amount'           => 1001,
    'cardNumber'       => '4012001037141112',
    'cardExpiryMonth'  => 12,
    'cardExpiryYear'   => 25,
    'cardCVV'          => '083',
    'customerName'     => 'Test Customer',
    'customerEmail'    => 'test@testcustomer.com',
    'customerAddress'  => '16 Test Street',
    'customerPostCode' => 'TE15 5ST',
    'orderRef'         => 'Test purchase',
    // Required for 3DSv2 direct integration
    'remoteAddress'      => $_SERVER['REMOTE_ADDR'],
    'threeDSRedirectURL' => $pageUrl . '&acs=1',
];

try {
    $response = Gateway::directRequest($request);
    // Inspect $response['responseCode'] / $response['responseMessage']
} catch (\Exception $e) {
    // Handle communication or signature errors
    echo $e->getMessage();
}
```

### Hosted Integration

[](#hosted-integration)

```
echo Gateway::hostedRequest($request);
// Renders an auto-submitting HTML form that redirects the
// customer to the Cardstream hosted payment page.
```

On the return page, verify the response:

```
try {
    Gateway::verifyResponse($_POST);
} catch (\Exception $e) {
    die($e->getMessage());
}
```

### 3DSv2 Browser Info

[](#3dsv2-browser-info)

For 3DSv2 direct integration, collect the required browser fingerprint fields:

```
echo Gateway::collectBrowserInfo([
    'formData' => ['orderRef' => 'Test purchase'],
]);
```

Laravel Integration
-------------------

[](#laravel-integration)

The package auto-registers `P3\SDK\Laravel\CardstreamServiceProvider` and the `Cardstream` facade via Laravel's package discovery — just `composer require` it and configure via `.env`.

### Configuration

[](#configuration)

Publish the config file if you want to edit it directly (optional — env vars alone are enough for most setups):

```
php artisan vendor:publish --tag=cardstream-config
```

Then set your credentials in `.env`:

```
CARDSTREAM_MERCHANT_ID=100856
CARDSTREAM_MERCHANT_SECRET=YourMerchantSecretHere
CARDSTREAM_MERCHANT_PASSWORD=
CARDSTREAM_HOSTED_URL=https://gateway.cardstream.com/hosted/
CARDSTREAM_DIRECT_URL=https://gateway.cardstream.com/direct/
CARDSTREAM_PROXY_URL=
CARDSTREAM_TIMEOUT=30
CARDSTREAM_DEBUG=false
```

Any of these left unset falls back to `P3\SDK\Gateway`'s own defaults (Cardstream's public demo `merchantID`/`merchantSecret` — see the warning in [Configuration Reference](#configuration-reference)). The service provider applies your `.env`/config values to the underlying `Gateway`statics on boot, so both the facade and `P3\SDK\Gateway` directly stay in sync — use whichever style you prefer.

### Usage via the Facade

[](#usage-via-the-facade)

```
use Cardstream;

$response = Cardstream::directRequest([
    'action'       => 'SALE',
    'type'         => 1,
    'currencyCode' => 826,
    'countryCode'  => 826,
    'amount'       => 1001,
    'cardNumber'   => '4012001037141112',
    // ...
]);
```

### Usage via the container (for injection/mocking in tests)

[](#usage-via-the-container-for-injectionmocking-in-tests)

```
use P3\SDK\Laravel\CardstreamGateway;

class CheckoutController
{
    /** @var CardstreamGateway */
    private $gateway;

    public function __construct(CardstreamGateway $gateway)
    {
        $this->gateway = $gateway;
    }

    public function pay()
    {
        return $this->gateway->directRequest([/* ... */]);
    }
}
```

Because `CardstreamGateway` is bound as a singleton in the container, it can be swapped for a test double with `$this->mock(CardstreamGateway::class)`in your Laravel feature tests without touching the underlying static SDK.

Both the facade and `P3\SDK\Gateway::*` calls are equivalent — the facade and the injectable `CardstreamGateway` class are thin, optional conveniences around the same static SDK.

Configuration Reference
-----------------------

[](#configuration-reference)

PropertyDefaultDescription`Gateway::$hostedUrl``https://gateway.cardstream.com/hosted/`Hosted API endpoint`Gateway::$directUrl``https://gateway.cardstream.com/direct/`Direct API endpoint`Gateway::$merchantID``100001` (Cardstream's public demo account)Merchant Account ID or Alias`Gateway::$merchantPwd``null`Merchant account password`Gateway::$merchantSecret``Circle4Take40Idea` (Cardstream's public demo secret)Merchant account secret (for signing)`Gateway::$proxyUrl``null`Optional outbound proxy URL`Gateway::$timeout``30`cURL/stream connect+transfer timeout, in seconds`Gateway::$debug``false`Log debug output via `error_log`> **Do not ship to production without overriding `$merchantID` and `$merchantSecret`.** Both default to Cardstream's public sandbox/demo credentials, not blank values — if you forget to set your own, requests will be signed with the demo secret and either fail against your live account or silently succeed against the sandbox instead of your account.

Useful response code constants: `Gateway::RC_SUCCESS`, `Gateway::RC_DO_NOT_HONOR`, `Gateway::RC_NO_REASON_TO_DECLINE`, `Gateway::RC_3DS_AUTHENTICATION_REQUIRED`.

See the class docblocks in [`src/Gateway.php`](src/Gateway.php) for full method signatures, or Cardstream's integration guides for complete gateway field reference.

Testing
-------

[](#testing)

```
composer install
vendor/bin/phpunit
```

The suite covers:

- **Unit tests** (`tests/GatewaySignatureTest.php`, `tests/GatewayValidationTest.php`) — signing, signature verification (full and partial), HTML field escaping, and `prepareRequest()` validation. No network access needed.
- **HTTP integration test** (`tests/GatewayHttpIntegrationTest.php`) — spins up a local fake Gateway with PHP's built-in server and drives `Gateway::directRequest()` through a real cURL round trip (sign → POST → parse → verify), including the declined-transaction and signature-mismatch paths. This is what proves the package works plug-and-play out of the box, without needing a real Cardstream account.
- **Laravel tests** (`tests/Laravel/ServiceProviderTest.php`, via [Orchestra Testbench](https://packagist.org/packages/orchestra/testbench)) — provider auto-discovery, config merging, `.env`/config values reaching the underlying `Gateway` statics, container binding, the facade, and `vendor:publish`.

CI (`.github/workflows/tests.yml`) runs the full suite on PHP 7.4–8.3.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE). Original SDK © Cardstream ([cardstream/PHP-SDK](https://github.com/cardstream/PHP-SDK)); Composer packaging by [hafizasifali](https://github.com/hafizasifali).

Disclaimer
----------

[](#disclaimer)

This is an independent, community-maintained Composer package. It is not an official Cardstream product. Cardstream only supports the SDK logic itself (the original `gateway.php`); use of this package requires full end-to-end testing by the integrator before production use.

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/47742059?v=4)[Hafiz Asif Ali](/maintainers/hafizasifali)[@hafizasifali](https://github.com/hafizasifali)

---

Top Contributors

[![hafizasifali](https://avatars.githubusercontent.com/u/47742059?v=4)](https://github.com/hafizasifali "hafizasifali (2 commits)")

### Embed Badge

![Health badge](/badges/hafizasifali-cardstream-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/hafizasifali-cardstream-php-sdk/health.svg)](https://phpackages.com/packages/hafizasifali-cardstream-php-sdk)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
