PHPackages                             webimpian/bayarcash-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. [Payment Processing](/categories/payments)
4. /
5. webimpian/bayarcash-php-sdk

Abandoned → [bayarcash/php-sdk](/?search=bayarcash%2Fphp-sdk)Sdk[Payment Processing](/categories/payments)

webimpian/bayarcash-php-sdk
===========================

Bayarcash payment gateway PHP Sdk.

v3.0.0(3w ago)310.2k↑24.6%4MITPHPPHP ^7.4|^8.0CI passing

Since Aug 30Pushed 3w ago2 watchersCompare

[ Source](https://github.com/bayarcash/php-sdk)[ Packagist](https://packagist.org/packages/webimpian/bayarcash-php-sdk)[ RSS](/packages/webimpian-bayarcash-php-sdk/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (6)Versions (22)Used By (0)

Bayarcash Payment Gateway PHP SDK
=================================

[](#bayarcash-payment-gateway-php-sdk)

[![Latest Stable Version](https://camo.githubusercontent.com/32f2573262f6f26dc16f58af121f42fe6158745ac57333d5c4d94f6d100cba8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6261796172636173682f7068702d73646b2e737667)](https://packagist.org/packages/bayarcash/php-sdk)[![Total Downloads](https://camo.githubusercontent.com/6d5448edd55d6be6c97e60ddd43f22bef7ccf4f4555d9c33de607a4c2e00c2d7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6261796172636173682f7068702d73646b2e737667)](https://packagist.org/packages/bayarcash/php-sdk)[![Downloads (legacy)](https://camo.githubusercontent.com/af657f494fd9982a6a87931c40ef5a29d7c9618b1b133886a6ec1c47c4e2504e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776562696d7069616e2f6261796172636173682d7068702d73646b2e7376673f6c6162656c3d646f776e6c6f6164732532302532386c6567616379253239)](https://packagist.org/packages/webimpian/bayarcash-php-sdk)[![PHP Version Require](https://camo.githubusercontent.com/e73141e4c70b6ca1319bf9cc736e55b4bb3314b715a11e4d14e08f77ec6226f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6261796172636173682f7068702d73646b2e737667)](https://packagist.org/packages/bayarcash/php-sdk)[![License](https://camo.githubusercontent.com/189570254a8ee8fe9cc6493e836973d04b65b810b858dcdda8495e4f5e709f22/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6261796172636173682f7068702d73646b2e737667)](https://packagist.org/packages/bayarcash/php-sdk)

The [Bayarcash](https://bayarcash.com/) SDK provides an expressive interface for interacting with Bayarcash's Payment Gateway API. It supports both API **v2** (default) and **v3**, with additional query features available in v3.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Getting Started](#getting-started)
    - [Plain PHP](#plain-php)
    - [Laravel](#laravel)
    - [Configuration](#configuration)
- [Quick Start: Accept a Payment](#quick-start-accept-a-payment)
- [Payment Channels](#payment-channels)
- [Creating a Payment Intent](#creating-a-payment-intent)
- [Handling Callbacks](#handling-callbacks)
- [Payment &amp; Transaction Status](#payment--transaction-status)
- [Transactions](#transactions)
- [FPX Direct Debit](#fpx-direct-debit)
- [Manual Bank Transfer](#manual-bank-transfer)
- [Portals &amp; FPX Banks](#portals--fpx-banks)
- [Error Handling](#error-handling)
- [Response Objects](#response-objects)
- [Security Recommendations](#security-recommendations)
- [Support](#support)

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

[](#requirements)

- PHP 7.4 – 8.5
- `ext-json`
- Guzzle 7 (installed automatically)

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

[](#installation)

Install via Composer:

```
composer require bayarcash/php-sdk
```

> **Note:** This package was previously published as `webimpian/bayarcash-php-sdk`. Existing installations using the old name continue to work, but new integrations should use `bayarcash/php-sdk`.

You will need two credentials from your Bayarcash console:

- **API token** — used to authenticate SDK requests.
- **API secret key** — used to generate request checksums and verify callbacks.

Getting Started
---------------

[](#getting-started)

### Plain PHP

[](#plain-php)

```
use Bayarcash\Bayarcash;

$bayarcash = new Bayarcash('YOUR_API_TOKEN');
$bayarcash->useSandbox(); // remove this line in production
```

### Laravel

[](#laravel)

The service provider is auto-discovered. Add your credentials to `.env`:

```
BAYARCASH_API_TOKEN=your_api_token
BAYARCASH_API_SECRET_KEY=your_api_secret_key
```

Then resolve the SDK from the container:

```
use Bayarcash\Bayarcash;

$bayarcash = app(Bayarcash::class);
$bayarcash->useSandbox(); // remove this line in production
```

To publish the config file:

```
php artisan vendor:publish --tag=bayarcash-sdk-config
```

### Configuration

[](#configuration)

```
$bayarcash
    ->useSandbox()          // switch to the sandbox environment
    ->setApiVersion('v3')   // 'v2' (default) or 'v3'
    ->setTimeout(60);       // request timeout in seconds (default 30)

$bayarcash->getApiVersion(); // read back the current version
```

> Call `useSandbox()` / `setApiVersion()` **before** making requests. Omit `useSandbox()` in production to hit the live gateway.

Quick Start: Accept a Payment
-----------------------------

[](#quick-start-accept-a-payment)

A complete FPX payment flow, from creating the payment to verifying the result:

```
use Bayarcash\Bayarcash;
use Bayarcash\Fpx;

$bayarcash = new Bayarcash('YOUR_API_TOKEN');
$bayarcash->useSandbox();

$apiSecretKey = 'YOUR_API_SECRET_KEY';

// 1. Build the payment request
$data = [
    'portal_key'             => 'your_portal_key',
    'payment_channel'        => Bayarcash::FPX,
    'order_number'           => 'INV-1001',
    'amount'                 => '10.00',
    'payer_name'             => 'Ahmad bin Abdullah',
    'payer_email'            => 'ahmad@example.com',
    'payer_telephone_number' => '0123456789',
    'return_url'             => 'https://your-site.com/payment/return',
    'callback_url'           => 'https://your-site.com/payment/callback',
];

// 2. Sign it (recommended)
$data['checksum'] = $bayarcash->createPaymentIntentChecksumValue($apiSecretKey, $data);

// 3. Create the payment intent and redirect the payer to Bayarcash
$paymentIntent = $bayarcash->createPaymentIntent($data);

header('Location: ' . $paymentIntent->url);
exit;
```

After payment, Bayarcash calls your `callback_url` (server-to-server) and redirects the payer to your `return_url`. Verify both — see [Handling Callbacks](#handling-callbacks).

Payment Channels
----------------

[](#payment-channels)

Pass one of these constants (or an array of them) as `payment_channel`:

```
Bayarcash::FPX                 // FPX Online Banking
Bayarcash::MANUAL_TRANSFER     // Manual Bank Transfer
Bayarcash::FPX_DIRECT_DEBIT    // FPX Direct Debit
Bayarcash::FPX_LINE_OF_CREDIT  // FPX Line of Credit
Bayarcash::DUITNOW_DOBW        // DuitNow Online Banking
Bayarcash::DUITNOW_QR          // DuitNow QR
Bayarcash::SPAYLATER           // ShopeePayLater
Bayarcash::BOOST_PAYFLEX       // Boost PayFlex
Bayarcash::QRISOB              // QRIS Online Banking
Bayarcash::QRISWALLET          // QRIS Wallet
Bayarcash::NETS                // NETS
Bayarcash::CREDIT_CARD         // Credit Card
Bayarcash::ALIPAY              // Alipay
Bayarcash::WECHATPAY           // WeChat Pay
Bayarcash::PROMPTPAY           // PromptPay
Bayarcash::TOUCH_N_GO          // Touch 'n Go eWallet
Bayarcash::BOOST_WALLET        // Boost Wallet
Bayarcash::GRABPAY             // GrabPay
Bayarcash::GRABPL              // Grab PayLater
Bayarcash::SHOPEE_PAY          // ShopeePay
```

Creating a Payment Intent
-------------------------

[](#creating-a-payment-intent)

```
$paymentIntent = $bayarcash->createPaymentIntent($data);
```

**Request fields:**

FieldRequiredDescription`portal_key`✅Your portal key.`order_number`✅Your reference. Max 30 chars.`amount`✅String with up to 2 decimals, e.g. `'10.00'`. Range `1.00`–`30000.00` (min differs for some channels).`payer_name`✅Max 150 chars.`payer_email`✅Valid email, max 250 chars.`payment_channel`➖A `Bayarcash::*` channel id, or an array of ids. If omitted, the payer chooses on the Bayarcash page.`payer_telephone_number`➖Required for e-wallet / DuitNow channels. Max 20 chars.`return_url`➖Where the payer's browser is redirected after payment.`callback_url`➖Server-to-server notification URL.`metadata`➖Any extra data you want echoed back.`checksum`➖Recommended. See below.### Checksum

[](#checksum)

The checksum protects the request from tampering. Generate it **after** building the request and append it as `checksum`:

```
$data['checksum'] = $bayarcash->createPaymentIntentChecksumValue($apiSecretKey, $data);
```

The checksum is computed from `payment_channel`, `order_number`, `amount`, `payer_name`, and `payer_email`.

Handling Callbacks
------------------

[](#handling-callbacks)

Bayarcash sends **two kinds** of notification. Always verify them with your API secret key before trusting the data.

NotificationHow it arrivesRead it from`callback_url` (transaction)Server-to-server **POST** (form-encoded)`$_POST` / `$request->all()``return_url` (payer redirect)Browser redirect — **POST** on v2, **GET** query on v3`$_POST` / `$_GET` / `$request->all()````
$callbackData = $_POST; // Laravel: $request->all()

// Transaction callback (sent to your callback_url)
if ($bayarcash->verifyTransactionCallbackData($callbackData, $apiSecretKey)) {
    // Data is authentic — safe to process.
}

// Payer redirect (sent to your return_url)
if ($bayarcash->verifyReturnUrlCallbackData($callbackData, $apiSecretKey)) {
    // ...
}

// Pre-transaction callback (sent before the transaction record)
if ($bayarcash->verifyPreTransactionCallbackData($callbackData, $apiSecretKey)) {
    // ...
}
```

Each verifier returns `true` only when the checksum matches. See [FPX Direct Debit](#fpx-direct-debit) for mandate-specific callback verifiers.

Payment &amp; Transaction Status
--------------------------------

[](#payment--transaction-status)

Transaction status is an integer code. Use the `Fpx` helper instead of hardcoding numbers:

```
use Bayarcash\Fpx;

Fpx::STATUS_NEW;        // 0
Fpx::STATUS_PENDING;    // 1
Fpx::STATUS_FAILED;     // 2
Fpx::STATUS_SUCCESS;    // 3
Fpx::STATUS_CANCELLED;  // 4

if ((int) $callbackData['status'] === Fpx::STATUS_SUCCESS) {
    // Payment successful
}

echo Fpx::getStatusText((int) $callbackData['status']); // e.g. "Successful"
```

Transactions
------------

[](#transactions)

```
// Get a single transaction (v2 and v3)
$transaction = $bayarcash->getTransaction('transaction_id');
```

The following query helpers require **API v3** and throw an exception on v2:

```
$bayarcash->setApiVersion('v3');

$result = $bayarcash->getAllTransactions([
    'order_number'              => 'INV-1001',
    'status'                    => '3',
    'payment_channel'           => Bayarcash::FPX,
    'exchange_reference_number' => 'REF123',
    'payer_email'               => 'ahmad@example.com',
]);
// $result['data'] => TransactionResource[], $result['meta'] => pagination meta

$byOrder   = $bayarcash->getTransactionByOrderNumber('INV-1001');
$byEmail   = $bayarcash->getTransactionsByPayerEmail('ahmad@example.com');
$byStatus  = $bayarcash->getTransactionsByStatus('3');
$byChannel = $bayarcash->getTransactionsByPaymentChannel(Bayarcash::FPX);
$byRef     = $bayarcash->getTransactionByReferenceNumber('REF123'); // single or null

// Get a payment intent by id (v3 only)
$intent = $bayarcash->getPaymentIntent('payment_intent_id');

// Cancel a payment intent (v3 only)
$bayarcash->cancelPaymentIntent('payment_intent_id');
```

FPX Direct Debit
----------------

[](#fpx-direct-debit)

FPX Direct Debit lets you set up a recurring mandate and later maintain or terminate it. Constants live on the `FpxDirectDebit` class:

```
use Bayarcash\FpxDirectDebit;

// Payer ID type
FpxDirectDebit::NRIC;                  // 1 (New IC)
FpxDirectDebit::OLD_IC;                // 2
FpxDirectDebit::PASSPORT;              // 3
FpxDirectDebit::BUSINESS_REGISTRATION; // 4
FpxDirectDebit::OTHERS;                // 5

// Frequency mode
FpxDirectDebit::MODE_DAILY;   // 'DL'
FpxDirectDebit::MODE_WEEKLY;  // 'WK'
FpxDirectDebit::MODE_MONTHLY; // 'MT'
FpxDirectDebit::MODE_YEARLY;  // 'YR'
```

### 1. Enrolment

[](#1-enrolment)

```
$data = [
    'portal_key'             => 'your_portal_key',
    'order_number'           => 'DD-1001',
    'amount'                 => '10.00', // range 5.00–30000.00
    'payer_name'             => 'Ahmad bin Abdullah',
    'payer_id_type'          => FpxDirectDebit::NRIC,
    'payer_id'               => '900101011234',
    'payer_email'            => 'ahmad@example.com', // max 27 chars
    'payer_telephone_number' => '0123456789',
    'application_reason'      => 'Monthly subscription',
    'frequency_mode'         => FpxDirectDebit::MODE_MONTHLY,
    'effective_date'         => '2026-08-01', // optional, Y-m-d
    'expiry_date'            => '2027-08-01', // optional, Y-m-d
    'return_url'             => 'https://your-site.com/mandate/return',
];

$data['checksum'] = $bayarcash->createFpxDirectDebitEnrolmentChecksumValue($apiSecretKey, $data);

$mandate = $bayarcash->createFpxDirectDebitEnrollment($data);
header('Location: ' . $mandate->url); // redirect payer to the enrolment page
```

### 2. Maintenance

[](#2-maintenance)

Update an existing mandate (identified by its mandate id):

```
$data = [
    'amount'                 => '15.00',
    'payer_email'            => 'ahmad@example.com',
    'payer_telephone_number' => '0123456789',
    'application_reason'      => 'Update amount',
    'frequency_mode'         => FpxDirectDebit::MODE_MONTHLY,
];

$data['checksum'] = $bayarcash->createFpxDirectDebitMaintenanceChecksumValue($apiSecretKey, $data);

$mandate = $bayarcash->createFpxDirectDebitMaintenance($mandateId, $data);
header('Location: ' . $mandate->url);
```

### 3. Termination

[](#3-termination)

```
$mandate = $bayarcash->createFpxDirectDebitTermination($mandateId, [
    'application_reason' => 'Customer cancelled',
]);
header('Location: ' . $mandate->url);
```

### Retrieving mandates &amp; verifying mandate callbacks

[](#retrieving-mandates--verifying-mandate-callbacks)

```
$mandate     = $bayarcash->getFpxDirectDebit($mandateId);
$transaction = $bayarcash->getFpxDirectDebitTransaction($transactionId);

// Mandate callback verifiers
$bayarcash->verifyDirectDebitBankApprovalCallbackData($callbackData, $apiSecretKey);
$bayarcash->verifyDirectDebitAuthorizationCallbackData($callbackData, $apiSecretKey);
$bayarcash->verifyDirectDebitTransactionCallbackData($callbackData, $apiSecretKey);
```

Manual Bank Transfer
--------------------

[](#manual-bank-transfer)

Submit a manual (offline) bank transfer with proof of payment:

```
$response = $bayarcash->createManualBankTransfer([
    'portal_key'                   => 'your_portal_key',
    'payment_gateway'              => Bayarcash::MANUAL_TRANSFER, // must be 2
    'order_no'                     => 'MT-1001',
    'buyer_name'                   => 'Ahmad bin Abdullah',
    'buyer_email'                  => 'ahmad@example.com',
    'buyer_tel_no'                 => '0123456789', // optional
    'order_amount'                 => '10.00',
    'merchant_bank_name'           => 'Maybank',
    'merchant_bank_account'        => '1234567890',
    'merchant_bank_account_holder' => 'Your Company Sdn Bhd',
    'bank_transfer_type'           => 'Internet Banking', // or 'Cash Deposit Machine (CDM)'
    'bank_transfer_notes'          => 'Payment for order MT-1001',
    'bank_transfer_date'           => '2026-07-22', // optional, defaults to today
    'proof_of_payment'             => '/path/to/receipt.jpg', // jpeg/png/gif/pdf, max 10 MB
]);
```

Update the status of an existing transfer:

```
use Bayarcash\Fpx;

$bayarcash->updateManualBankTransferStatus(
    'ref_no_here',
    (string) Fpx::STATUS_SUCCESS,
    '10.00'
);
```

Portals &amp; FPX Banks
-----------------------

[](#portals--fpx-banks)

```
// All portals for your account
$portals = $bayarcash->getPortals();

// Payment channels available for a portal
$channels = $bayarcash->getChannels('your_portal_key');

// FPX banks (for building a bank selector)
$banks = $bayarcash->fpxBanksList();
```

Error Handling
--------------

[](#error-handling)

Failed API calls throw typed exceptions. Catch them to handle errors gracefully:

```
use Bayarcash\Exceptions\ValidationException;
use Bayarcash\Exceptions\FailedActionException;
use Bayarcash\Exceptions\NotFoundException;
use Bayarcash\Exceptions\RateLimitExceededException;

try {
    $paymentIntent = $bayarcash->createPaymentIntent($data);
} catch (ValidationException $e) {
    // 422 — invalid request data
    $errors = $e->errors();
} catch (NotFoundException $e) {
    // 404 — resource not found
} catch (RateLimitExceededException $e) {
    // 429 — too many requests
    $resetAt = $e->rateLimitResetsAt; // unix timestamp or null
} catch (FailedActionException $e) {
    // 400 — request failed
    $message = $e->getMessage();
}
```

ExceptionHTTPMeaning`ValidationException`422Invalid data. Call `->errors()` for details.`FailedActionException`400Request failed. `->getMessage()` has the reason.`NotFoundException`404Resource not found.`RateLimitExceededException`429Rate limited. `->rateLimitResetsAt` holds the reset time.`TimeoutException`—Thrown by the optional `retry()` helper after a timeout.Response Objects
----------------

[](#response-objects)

API methods return typed resource objects. Common properties:

**`PaymentIntentResource`** (from `createPaymentIntent` / `getPaymentIntent`)

```
$paymentIntent->url;          // checkout URL to redirect the payer to
$paymentIntent->id;
$paymentIntent->status;
$paymentIntent->amount;
$paymentIntent->orderNumber;
$paymentIntent->payerName;
$paymentIntent->payerEmail;
```

**`TransactionResource`** (from `getTransaction` / transaction queries)

```
$transaction->id;
$transaction->status;                   // int status code — see Fpx constants
$transaction->statusDescription;
$transaction->amount;
$transaction->orderNumber;
$transaction->exchangeReferenceNumber;
$transaction->payerName;
$transaction->payerEmail;
```

Any missing field is `null`. Convert a resource (including nested resources) to an array:

```
$transaction->toArray();
```

Security Recommendations
------------------------

[](#security-recommendations)

1. Always send a `checksum` with payment and mandate requests.
2. Verify **every** callback with the provided verification methods before acting on it.
3. Store and check transaction ids to prevent duplicate processing.
4. Use HTTPS for your `return_url` and `callback_url`.
5. Keep your API token and secret key out of source control.

API Documentation
-----------------

[](#api-documentation)

For full API details, see the [Official Bayarcash API Documentation](https://api.webimpian.support/bayarcash).

Support
-------

[](#support)

For support questions, contact Bayarcash support or open an issue in this repository.

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for the version history.

License
-------

[](#license)

Open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance94

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.2% 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.

###  Release Activity

Cadence

Every ~34 days

Recently: every ~43 days

Total

21

Last Release

27d ago

Major Versions

1.2.5 → 2.0.02025-01-17

v2.3.0 → v3.0.02026-07-21

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0|^8.1

v3.0.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ba882a53035a44fffc01cd910b1705b8ca17b5eb605a763711632be04ad78512?d=identicon)[webimpian](/maintainers/webimpian)

---

Top Contributors

[![khairulimran-97](https://avatars.githubusercontent.com/u/105085586?v=4)](https://github.com/khairulimran-97 "khairulimran-97 (28 commits)")[![imanifaiz](https://avatars.githubusercontent.com/u/7203373?v=4)](https://github.com/imanifaiz "imanifaiz (13 commits)")[![hannyramzy](https://avatars.githubusercontent.com/u/10192653?v=4)](https://github.com/hannyramzy "hannyramzy (3 commits)")[![webimpianteam](https://avatars.githubusercontent.com/u/66111282?v=4)](https://github.com/webimpianteam "webimpianteam (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webimpian-bayarcash-php-sdk/health.svg)

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k832.6k55](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.3M49](/packages/tencentcloud-tencentcloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

353.6k](/packages/eslazarev-wildberries-sdk)[chargebee/chargebee-php

ChargeBee API client implementation for PHP

758.7M10](/packages/chargebee-chargebee-php)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)

PHPackages © 2026

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