aimandaniel/toyyibpay

Framework-agnostic PHP library for toyyibPay API (unofficial)

dev-master 2020-07-14 20:53 UTC

This package is auto-updated.

Last update: 2020-11-13 10:09:48 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-library

Getting started

Creating a client

use AimanDaniel\ToyyibPay\Client;

$client = Client::make('your-secret-key');

You can also pass a HTTP client directly:

use AimanDaniel\ToyyibPay\Client;

$http = Laravie\Codex\Discovery::client();

$client = new Client($http, 'your-secret-key');

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 $categoryCode,
  string $billName,
  string $billDescription,
  int $billPriceSetting,
  int $billPayerInfo,
  string $billAmount,
  string $billReturnUrl,
  string $billCallbackUrl,
  string $billExternalReferenceNo,
  string $billTo,
  string $billEmail,
  string $billPhone,
  int $billSplitPayment = 0,
  string $billSplitPaymentArgs,
  string $billPaymentChannel,
  int $billDisplayMerchant = 1,
  string $billContentEmail = '',
  string $billChargeToCustomer
);

var_dump($response->toArray());

Create a multi-payment bill

$response = $bill->createMultiPayment(
  string $categoryCode,
  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