aimandaniel / toyyibpay
Framework-agnostic PHP library for toyyibPay API (unofficial)
Requires
- php: ^7.3|^8.0
- laravie/codex: ^5.3
- php-http/guzzle7-adapter: ^1.0
- php-http/multipart-stream-builder: ^1.0
This package is auto-updated.
Last update: 2025-02-20 01:32:33 UTC
README
Unofficial PHP library for toyyibPay payment gateway. This package is heavily inspired by jomweb/billplz. Please consult the official API reference for a detailed explanation.
Installation
$ composer require aimandaniel/toyyibpay
Getting started
Creating a client
use AimanDaniel\ToyyibPay\Client; $client = Client::make('your-secret-key', 'your-category-code');
You can also pass a HTTP client directly:
use AimanDaniel\ToyyibPay\Client; $http = Laravie\Codex\Discovery::client(); $client = new Client($http, 'your-secret-key', 'your-category-code');
Using sandbox mode
You can enable sandbox environment by adding the following line:
$client->useSandbox();
Usage
Bank
You can create a Bank
instance as follows:
$bank = $client->bank(); // or $bank = $client->uses('Bank');
You can pass the API version manually by doing
$client->bank('v1')
or$client->uses('Bank', 'v1')
but currently the API only has one version and it is set as the default one
Get bank list
$response = $bank->all(); var_dump($response->toArray());
Get bank FPX codes
$response = $bank->fpx(); var_dump($response->toArray());
Package
Create a Package
instance:
$package = $client->package(); // or $package = $client->uses('Package');
Get package list
$response = $package->all(); var_dump($response->toArray());
User
Create a User
instance:
$user = $client->user(); // or $user = $client->uses('User');
Create User
$response = $user->create( string $fullname, string $username, string $email, string $password, string $phone, int $bank, // same id as in $bank->all() string $accountNo, // bank acc number string $accountHolderName, // bank acc holder ?string $registrationNo, ?int $package, ?int $userStatus ); var_dump($response->toArray());
Get user status
$response = $user->status($username); var_dump($response->toArray());
Get all user
$partnerType = 'OEM'; // or 'ENTERPRISE', defaults to OEM if null $response = $user->all($partnerType); var_dump($response->toArray());
Category
Create a Category
instance as follows:
$category = $client->category(); // or $category = $client->uses('Category');
Create category
$response = $category->create( string $categoryName, string $categoryDescription ); var_dump($response->toArray());
Get category
$response = $category->get('category code'); var_dump($response->toArray());
Bill
Create a Bill
instance:
$bill = $client->bill(); // or $bill = $client->uses('Bill');
Create a bill
$response = $bill->create( string $billName, string $billDescription, int $billPriceSetting, int $billPayerInfo, string $billAmount, string $billReturnUrl, string $billCallbackUrl, string $billExternalReferenceNo, ?string $billTo, string $billEmail, string $billPhone, array $optionals = [] ); var_dump($response->toArray());
$optionals
expects an associative array of any of these values:
Create a multi-payment bill
$response = $bill->createMultiPayment( string $billName, string $billDescription, string $billPriceSetting, string $billPayerInfo, string $billAmount, string $billReturnUrl, string $billCallbackUrl, string $billExternalReferenceNo, string $billTo, string $billEmail, string $billPhone, string $billSplitPayment, string $billSplitPaymentArgs, string $billMultiPayment, string $billPaymentChannel, string $billDisplayMerchant, string $billContentEmail ); var_dump($response->toArray());
Run bill
$response = $bill->run( string $billCode, string $billpaymentAmount, string $billpaymentPayerName, string $billpaymentPayerPhone, string $billpaymentPayerEmail, string $billBankID ); var_dump($response->toArray());
Get all bills
$partnerType = 'OEM'; // or 'ENTERPRISE' $yearMonth = '2020-01'; $response = $bill->all( string $partnerType, ?string $yearMonth = null ); var_dump($response->toArray());
Get bill transactions
$response = $bill->transactions( string $billCode, ?int $billpaymentStatus = 1 ); var_dump($response->toArray());
Settlement
Create a Settlement
instance:
$settlement = $client->settlement(); // or $settlement = $client->uses('settlement');
Get all settlement
$response = $settlement->all( string $partnerType, bool $groupByUsername ); var_dump($response->toArray());
Get settlement summary
$response = $settlement->summary( string $partnerType, bool $groupByUsername ); var_dump($response->toArray());
Contribution
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Developer's Note
The API version declared in this package is v1 even though the official API reference does not explicitly declare it as such