Skip to content

PHP framework-agnostic toyyibPay library (unofficial)

Notifications You must be signed in to change notification settings

xputerax/toyyibpay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP ToyyibPay Library (unofficial)

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:

Key Expected Value Default Value
billSplitPayment Bill::PAYMENT_SPLIT (1)
(empty)
(empty)
billSplitPaymentArgs JSON String (empty)
billPaymentChannel Bill::PAYMENT_CHANNEL_FPX (0)
Bill::PAYMENT_CHANNEL_CC (1)
Bill::PAYMENT_CHANNEL_BOTH (2)
Bill::PAYMENT_CHANNEL_BOTH (2)
billDisplayMerchant Bill::MERCHANT_HIDE (0)
Bill::MERCHANT_DISPLAY (1)
Bill::MERCHANT_DISPLAY (1)
billContentEmail (string) (empty)
billChargeToCustomer Bill::CHARGE_OWNER_BOTH (null)
Bill::CHARGE_FPX_CUSTOMER_CC_OWNER (0)
Bill::CHARGE_FPX_OWNER_CC_CUSTOMER (1)
Bill::CHARGE_CUSTOMER_BOTH (2)
Bill::CHARGE_OWNER_BOTH (null)

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

License

MIT

About

PHP framework-agnostic toyyibPay library (unofficial)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages