PHPackages                             hansajith18/laravel-paycorp - 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. [Payment Processing](/categories/payments)
4. /
5. hansajith18/laravel-paycorp

ActiveLibrary[Payment Processing](/categories/payments)

hansajith18/laravel-paycorp
===========================

Laravel integration for the Paycorp (Bancstac) payment gateway. Supports Hosted Page flow, Real-Time tokenised payments, and Refund/Void.

00PHPCI failing

Since Jun 26Pushed todayCompare

[ Source](https://github.com/hansajith18/laravel-paycorp)[ Packagist](https://packagist.org/packages/hansajith18/laravel-paycorp)[ RSS](/packages/hansajith18-laravel-paycorp/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

laravel-paycorp
===============

[](#laravel-paycorp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1d93dbb4f665044d74691aae6413ed1591115b40c37c7d5f5cb40a9506922132/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616e73616a69746831382f6c61726176656c2d706179636f72702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hansajith18/laravel-paycorp)[![PHP Version](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)](https://php.net)[![Laravel](https://camo.githubusercontent.com/f9f1aee5261b3b9aa8b1f3094ea1fe03a38308a41ba790f53ec2a6a767a81137/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d31302532302537432532303131253230253743253230313225323025374325323031332d726564)](https://laravel.com)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Tests](https://camo.githubusercontent.com/d940ad7f0752e2cbe0d63c50dcebf329078807390051c41fe63258f1b5c4e182/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d70617373696e672d627269676874677265656e)](https://github.com/hansajith18/laravel-paycorp/actions)

**Laravel integration for the Paycorp (Bancstac) payment gateway.**

Supports the Sampath/Paycorp Paycenter Web 4.0 API — Hosted Page flow, Real-Time tokenised card payments, and Refund/Void operations — with full database audit logging and PCI DSS safe-handling baked in.

---

Features
--------

[](#features)

- **Hosted Page flow** — redirect payer to Paycorp-hosted card entry, receive callback
- **Real-Time flow** — charge previously tokenised (saved) cards without redirecting
- **Refund &amp; Void** — session-authenticated back-office API with AES-256 encryption
- **HMAC-SHA256 request signing** — every outgoing request is signed
- **Auto-registered log channel** — `paycorp-YYYY-MM-DD.log` with zero config required
- **Sandbox mode** — automatic amount normalisation for the Paycorp test environment
- **Full gateway audit log** — all requests/responses written to `payment_gateway_logs` table
- **PCI DSS safe** — never stores raw card numbers or CVVs; only masked card data persisted
- **Laravel 11 &amp; 12 support**

---

Requirements
------------

[](#requirements)

- PHP `^8.2`
- Laravel `^10.0`, `^11.0`, `^12.0`, or `^13.0`
- `ext-openssl`

---

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

[](#installation)

```
composer require hansajith18/laravel-paycorp
```

The service provider is auto-discovered. No manual registration required.

### Publish config and migrations

[](#publish-config-and-migrations)

```
php artisan paycorp:publish
```

Or publish individually:

```
# Config only
php artisan vendor:publish --tag=paycorp-config

# Migrations only
php artisan vendor:publish --tag=paycorp-migrations
```

Then run migrations:

```
php artisan migrate
```

---

Configuration
-------------

[](#configuration)

Add the following to your `.env` file:

```
# ── Required ──────────────────────────────────────────────────────────────────
PAYCORP_ENDPOINT=https://paycorp-smp.prod.aws.paycorp.lk/rest/service/proxy
PAYCORP_AUTH_TOKEN=your_auth_token
PAYCORP_HMAC_SECRET=your_hmac_secret

# ── Client IDs (provided by Paycorp per currency) ──────────────────────────────
PAYCORP_CLIENT_ID_LKR=your_lkr_client_id
PAYCORP_CLIENT_ID_USD=your_usd_client_id

# ── Tokenised payment client IDs (required for saved-card flow) ────────────────
PAYCORP_TOKEN_CLIENT_ID_LKR=your_tokenize_lkr_client_id
PAYCORP_TOKEN_CLIENT_ID_USD=your_tokenize_usd_client_id

# ── Return URL (Paycorp redirects here after card entry) ───────────────────────
PAYCORP_RETURN_URL="${APP_URL}/api/payments/paycorp/return"

# ── Optional ───────────────────────────────────────────────────────────────────
PAYCORP_DEFAULT_CURRENCY=LKR
PAYCORP_SANDBOX=false
PAYCORP_API_VERSION=1.04
PAYCORP_TIMEOUT=30
PAYCORP_CONNECT_TIMEOUT=10
PAYCORP_RETRY_TIMES=2
PAYCORP_RETRY_SLEEP_MS=500

# ── Refund / Void credentials (required only if using refund features) ─────────
PAYCORP_REFUND_ENDPOINT=https://paycorp-console.prod.aws.paycorp.lk
PAYCORP_REFUND_USERNAME=your_console_username
PAYCORP_REFUND_PASSWORD=your_console_password
PAYCORP_REFUND_IV_PHRASE=your_iv_phrase
PAYCORP_REFUND_AES_SECRET=your_aes_secret
PAYCORP_REFUND_DEVICE_ID=your_device_id

# ── Logging ────────────────────────────────────────────────────────────────────
PAYCORP_LOG_CHANNEL=paycorp
PAYCORP_LOG_LEVEL=debug
PAYCORP_LOG_DAYS=14
```

The package auto-registers a `paycorp` daily log channel — no changes to `config/logging.php` are needed. To redirect logs to an existing channel (e.g. `stack`), set `PAYCORP_LOG_CHANNEL=stack`.

---

Usage
-----

[](#usage)

### Hosted Page Flow

[](#hosted-page-flow)

#### 1 — Initialize a payment

[](#1--initialize-a-payment)

```
use Hansajith18\LaravelPaycorp\PaycorpClient;

$client = app(PaycorpClient::class);
// or: $client = app('paycorp');

$response = $client->initPayment(
    amountCents: 50000,          // 500.00 LKR
    clientRef:   'ORDER-' . $orderId,
    returnUrl:   route('payments.callback'),
    currency:    'LKR',
);

// Redirect the user to the Paycorp-hosted payment page
return redirect($response->paymentPageUrl);
```

#### 2 — Complete the payment (callback route)

[](#2--complete-the-payment-callback-route)

```
use Hansajith18\LaravelPaycorp\PaycorpClient;

$client = app(PaycorpClient::class);

$reqId = $request->query('reqid');

$response = $client->completePayment($reqId, 'LKR');

if ($response->isApproved()) {
    $txnRef = $response->txnReference;
    $last4  = $response->cardLast4();  // e.g. "4564"
    // fulfil the order…
} else {
    // $response->responseCode, $response->responseText
}
```

### Tokenization (Save a Card)

[](#tokenization-save-a-card)

To save a card during payment, pass `tokenize: true` to the service-level `initializePayment`:

```
use Hansajith18\LaravelPaycorp\Services\PaycenterPaymentService;
use Hansajith18\LaravelPaycorp\Enums\PaymentPurposeEnum;

$service = app(PaycenterPaymentService::class);

$payment = $service->initializePayment(
    userId:      auth()->id(),
    amountCents: 100,   // small verification charge — auto-voided after card saved
    purpose:     PaymentPurposeEnum::CARD_REGISTRATION,
    currency:    'LKR',
    tokenize:    true,
);

return redirect($payment->payment_page_url);
```

After the callback, the token is stored in `saved_payments`. The verification charge is automatically voided by the `VoidTokenizationCharge` queued job.

### Real-Time Charge (Saved Card)

[](#real-time-charge-saved-card)

```
use Hansajith18\LaravelPaycorp\Models\SavedPayment;
use Hansajith18\LaravelPaycorp\Services\PaycenterPaymentService;
use Hansajith18\LaravelPaycorp\Enums\PaymentPurposeEnum;

$savedPayment = SavedPayment::where('user_id', auth()->id())->firstOrFail();
$service      = app(PaycenterPaymentService::class);

$payment = $service->chargeWithSavedPayment(
    userId:       auth()->id(),
    amountCents:  50000,
    purpose:      PaymentPurposeEnum::RIDE_PAYMENT,
    savedPayment: $savedPayment,
    currency:     'LKR',
);

// $payment->status === GatewayPaymentStatusEnum::COMPLETED on success
```

### Refund

[](#refund)

```
$response = $client->refund(
    originalTxnReference: $txnReference,
    amountCents:          50000,
    clientRef:            'REFUND-' . $refundId,
    currency:             'LKR',
    comment:              'Customer request',
);

if ($response->isApproved()) {
    // refund successful
}
```

### Events

[](#events)

Listen to payment outcomes in your `EventServiceProvider`:

```
use Hansajith18\LaravelPaycorp\Events\PaymentSucceeded;
use Hansajith18\LaravelPaycorp\Events\PaymentFailed;

Event::listen(PaymentSucceeded::class, function ($event) {
    $payment = $event->payment;
    // fulfil order, send receipt, etc.
});

Event::listen(PaymentFailed::class, function ($event) {
    // notify user, release reservation, etc.
});
```

### Payable Status Auto-Update (Optional)

[](#payable-status-auto-update-optional)

If you want the package to automatically update a `payment_status` column on a related payable model when a payment completes or fails, list the model class base-names in `config/paycorp.php`:

```
// config/paycorp.php
'payable_status_classes' => ['Order', 'Booking'],
```

Leave the array empty (default) and handle status updates in your own event listeners instead.

---

Database Tables
---------------

[](#database-tables)

TablePurpose`payments`One row per payment attempt; tracks status, masked card info, gateway references`payment_gateway_logs`Full request/response audit trail per gateway operation`saved_payments`Tokenised cards per user (for Real-Time flow)---

Sandbox Mode
------------

[](#sandbox-mode)

Set `PAYCORP_SANDBOX=true` when using the Paycorp test environment. The package automatically:

- Strips sub-unit cents (e.g. `5389.20 LKR → 5389.00 LKR`)
- Enforces a minimum amount of `200` cents (2.00 LKR)

No code changes needed between sandbox and production.

---

Testing
-------

[](#testing)

```
composer test
```

Or directly:

```
./vendor/bin/phpunit
```

### Quality Tooling

[](#quality-tooling)

```
# Code style (Laravel Pint)
composer format

# Static analysis (PHPStan level 5)
composer analyse
```

---

Security
--------

[](#security)

- All API requests are signed with HMAC-SHA256
- TLS verification enforced (`verify: true`) — HTTP connections always use TLS
- Card numbers and CVVs are **never stored** — only masked card data persisted
- `toSafeArray()` explicitly excludes cardholder name, raw expiry, and internal comments
- Refund credentials are AES-256-CBC encrypted before transmission
- Gateway audit logs sanitise all sensitive fields before writing to the database

Please see [SECURITY.md](SECURITY.md) for how to report a security vulnerability.

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release history.

For maintainers: see [docs/releases.md](docs/releases.md) for the full release workflow guide.

---

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for details.

---

Credits
-------

[](#credits)

- [Navod Hansajith](https://github.com/hansajith18)

###  Health Score

20

—

LowBetter than 13% 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://www.gravatar.com/avatar/52e6c2f80ab453e341015f4e6dd8806347ab59f625356df14ff7ace3f590b644?d=identicon)[hansajith18](/maintainers/hansajith18)

---

Top Contributors

[![hansajith18](https://avatars.githubusercontent.com/u/59231358?v=4)](https://github.com/hansajith18 "hansajith18 (29 commits)")

### Embed Badge

![Health badge](/badges/hansajith18-laravel-paycorp/health.svg)

```
[![Health](https://phpackages.com/badges/hansajith18-laravel-paycorp/health.svg)](https://phpackages.com/packages/hansajith18-laravel-paycorp)
```

###  Alternatives

[omnipay/coinbase

Coinbase driver for the Omnipay payment processing library

18570.2k1](/packages/omnipay-coinbase)

PHPackages © 2026

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