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.
$ composer require aimandaniel/toyyibpay
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');
You can enable sandbox environment by adding the following line:
$client->useSandbox();
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
$response = $bank->all();
var_dump($response->toArray());
$response = $bank->fpx();
var_dump($response->toArray());
Create a Package
instance:
$package = $client->package();
// or
$package = $client->uses('Package');
$response = $package->all();
var_dump($response->toArray());
Create a User
instance:
$user = $client->user();
// or
$user = $client->uses('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());
$response = $user->status($username);
var_dump($response->toArray());
$partnerType = 'OEM'; // or 'ENTERPRISE', defaults to OEM if null
$response = $user->all($partnerType);
var_dump($response->toArray());
Create a Category
instance as follows:
$category = $client->category();
// or
$category = $client->uses('Category');
$response = $category->create(
string $categoryName,
string $categoryDescription
);
var_dump($response->toArray());
$response = $category->get('category code');
var_dump($response->toArray());
Create a Bill
instance:
$bill = $client->bill();
// or
$bill = $client->uses('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) |
$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());
$response = $bill->run(
string $billCode,
string $billpaymentAmount,
string $billpaymentPayerName,
string $billpaymentPayerPhone,
string $billpaymentPayerEmail,
string $billBankID
);
var_dump($response->toArray());
$partnerType = 'OEM'; // or 'ENTERPRISE'
$yearMonth = '2020-01';
$response = $bill->all(
string $partnerType,
?string $yearMonth = null
);
var_dump($response->toArray());
$response = $bill->transactions(
string $billCode,
?int $billpaymentStatus = 1
);
var_dump($response->toArray());
Create a Settlement
instance:
$settlement = $client->settlement();
// or
$settlement = $client->uses('settlement');
$response = $settlement->all(
string $partnerType,
bool $groupByUsername
);
var_dump($response->toArray());
$response = $settlement->summary(
string $partnerType,
bool $groupByUsername
);
var_dump($response->toArray());
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.
The API version declared in this package is v1 even though the official API reference does not explicitly declare it as such