Basic Information

You will interact a lot with Category and Bill.

Category is a group of bills. You can create a category based on bills type. e.g. House rental, Subscription fees.

A bill is an invoice for your customer. A bill must belong to a Category

To start using the API, you would have to create a Category. Then the payment flow will kicks in as per below:

  • Customer visits your site.
  • Customer chooses to make payment.
  • Your site creates a Bill via API call.
  • Toyyibpay API returns Bill's code.
  • Your site redirects the customer to Bill's URL.
  • The customer makes payment via payment option of choice.
  • Toyyibpay sends a server-side update (Payment Completion) to your site on Bill's status on payment failure or success.
  • Your site can check payment status via API call
  • APIs

    Get Bank API is useful for you to get bank information which are accepted to be used with Toyyibpay. Bank information is required when you create a user from API

    Our API system will return bank information in JSON format.

    Sample code

    
    <?php
      $curl = curl_init();
    
      curl_setopt($curl, CURLOPT_POST, 0);
      curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/getBank');  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    
      $result = curl_exec($curl);
      $info = curl_getinfo($curl);  
      curl_close($curl);
    
      echo $result;
    ?>
    											

    Sample result

    
    [{"id":"1","bank":"Maybank","status":"1"},{"id":"2","bank":"CIMB Bank","status":"1"},{"id":"3","bank":"Bank Islam","status":"1"},{"id":"4","bank":"Bank RBS","status":"1"},{"id":"5","bank":"Bank Mandiri","status":"1"}]
    											

    Get Package API is useful for you to get package information which are provided in Toyyibpay. Package information is required when you create a user from API

    Our API system will return bank information in JSON format.

    Sample code

    
    <?php
      $curl = curl_init();
    
      curl_setopt($curl, CURLOPT_POST, 0);
      curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/getPackage');  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    
      $result = curl_exec($curl);
      $info = curl_getinfo($curl);  
      curl_close($curl);
    
      echo $result;
    ?>
    											

    Sample result

    
    [{"id":"1","package":"Pakej Standard","fee":"0.30","status":"1"},{"id":"2","package":"Pakej Pantas","fee":"0.50","status":"1"},{"id":"4","package":"Pakej Santai","fee":"0.00","status":"1"}]
    											

    This API will show how to create Toyyibpay user from API. This API will return User Secret Key which later will be used for creating Category and Bill.

    You need to pass the following parameters to create user.

    • Fullname - User full name
    • User name - User name to access or login
    • Email - User Email OR User Id (not necessary in email format)
    • Password - User Password
    • Phone - User Phone
    • Bank - User Bank Selection
    • Account No - User Bank Account No
    • Account Holder Name - User Account Holder Name
    • Registration No - User Company / Business / Organization Registration No
    • Package - User Package
    • Following - Enterprise User Secret Key

    Our API system will return User Secret Key in JSON format. It will return error if the email already exist.

    Sample code

    
    <?php
      $some_data = array(
        'fullname' => 'John Doe Sdn Bhd',
        'username' => 'johndoe',
        'email' => '[email protected]',
        'password' => '123456',
        'phone' => '0134342400',
        'bank'=>1,
        'accountNo'=>'162263282063',
        'accountHolderName'=>'John Doe,
        'registrationNo'=>'BBYUUI',
        'package' => 1,
        'following' => ''
      );
    
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/createAccount');  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data);
    
      $result = curl_exec($curl);
      $info = curl_getinfo($curl);  
      curl_close($curl);
      $obj = json_decode($result);
      echo $result;
    											

    Sample result

    
    [{"UserSecretKey":"vrbl86xf-wj1h-q0l3-95kk-4q4erulvsc0h"}]
    											

    You may check user account status by submitting user email and enterprise user secret key. Status code description as follows:-

    • 0 - Inactive
    • 1 - New-Pending Approval
    • 2 - Active

    Sample code

    
    <?php
      $some_data = array(
        'username' => 'johndoe',
        'enterpriseUserSecretKey' => 'h9ijfq4y-hrha-jsmj-s4br-r5hll1g29ty'
      );  
    
      $curl = curl_init();
    
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_URL, 'https://Toyyibpay.com/index.php/api/getUserStatus');  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data);
    
      $result = curl_exec($curl);
    
      $info = curl_getinfo($curl);  
    
      curl_close($curl);
      echo $result;
    ?>
    											

    Sample result

    
    [{"status":"1"}]
    											

    Category is a collection of bills. As an example, you may create a 'Rental' Category for bill related to rental. User Secret Key is required in order to create a Category. Please login to Toyyibpay to get User Secret Key.

    In the example below, we will show you how to create a Category. You need to pass the following parameters to generate category code.

    • catname - Category Name
    • catdescription - Category Description
    • userSecretKey - User Secret Key

    Our API system will return Category Code in JSON format.

    Sample code

    
    <?php
      $some_data = array(
        'catname' => 'Toyyibpay General 2', //CATEGORY NAME
        'catdescription' => 'Toyyibpay General Category, For Toyyibpay Transactions 2', //PROVIDE YOUR CATEGORY DESCRIPTION
        'userSecretKey' => 'w5x7srq7-rx5r-3t89-2ou2-k7361x2jewhn' //PROVIDE USER SECRET KEY HERE
      );  
    
      $curl = curl_init();
    
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/createCategory');  //PROVIDE API LINK HERE
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data);
    
      $result = curl_exec($curl);
    
      $info = curl_getinfo($curl);  
      curl_close($curl);
    
      $obj = json_decode($result);
      echo $result;
    											

    Sample result

    
    [{"CategoryCode":"j0tzqhka"}]
    											

    Bill serves as an invoice to your customer. In the example below, we will show you how to create a Bill. You need to pass the following parameters to generate category code.

    • userSecretKey - User Secret Key
    • categoryCode - Category Code. Get your Category Code from Create Category API
    • billName - Your bill name. Bill Name will be displayed as bill title
    • billDescription- For fixed amount bill, set it to 0. For dynamic bill (user can key in the amount paid), set it to 1
    • billPriceSetting - Put 1 if the bill has fix amount, put 0 if dynamic amount.
    • billPayorInfo - If you want to create open bill without require payer information, set it to 0. If you need payer information, set it to 1
    • billAmount - Key in the bill amount. The amount is in cent. e.g. 100 = RM1. Put 0 if your billPriceSetting is set to 0.
    • billReturnUrl - Key in return Url if you need the bill to be redirected to your own page upon payment completion.
    • billCallbackUrl - Key in callback url if you need the bill to be redirected to your callback page upon sucessful of payment transaction.
    • billExternalReferenceNo - Provide your own system reference no if you think it is required. You may use this reference no to check the payment status for the bill.
    • billTo - If you intend to provide the bill to specific person, you may fill the person nam in this field. If not, please leave it blank.
    • billEmail - Provide your customer email here
    • billPhone - Provide your customer phone number here.
    • billSplitPayment - Set 1 if the you need the payment to be splitted to other Toyyibpay users.
    • billSplitPaymentArgs - Provide JSON for split payment. e.g. [{"id":"johndoe","amount":"200"}]
    • [OPTIONAL]billPaymentChannel - 0 = FPX Only, 1 = Credit/Debit Card only, 2 = FPX and Credit Card

    Our API system will return Bill Code in JSON format. In this example, the API return gcbhict9 as bill code. Hence, your payment url will be:- https://toyyibpay.com/gcbhict9

    Sample code

    
    <?php
      $some_data = array(
        'userSecretKey' => 'w5x7srq7-rx5r-3t89-2ou2-k7361x2jewhn',
        'categoryCode' => 'gcbhict9',
        'billName' => 'Car Rental WXX123',
        'billDescription' => 'Car Rental WXX123 On Sunday',
        'billPriceSetting'=>0,
        'billPayorInfo'=>1,
        'billAmount'=>100,
        'billReturnUrl'=>'http://bizapp.my',
        'billCallbackUrl'=>'http://bizapp.my/paystatus',
        'billExternalReferenceNo' => 'AFR341DFI',
        'billTo'=>'John Doe',
        'billEmail'=>'[email protected]',
        'billPhone'=>'0194342411',
        'billSplitPayment'=>0,
        'billSplitPaymentArgs'=>''
        'billPaymentChannel'=>0
    
      );  
    
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/createBill');  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data);
    
      $result = curl_exec($curl);
      $info = curl_getinfo($curl);  
      curl_close($curl);
      $obj = json_decode($result);
      echo $result;
    											

    Sample result

    
    [{"BillCode":"j0tzqhka"}]
    											

    Return URL will be supplied with the following datas in GET format:-

    status_id : Payment status. 1= success, 2=pending, 3=fail

    billcode: Your billcode / permanent link

    order_id : Your external payment reference no, if specified

    Return URL will be supplied with the following datas in POST format:-

    refno : Payment reference no

    status : Payment status. 1= success, 2=pending, 3=fail

    reason : Reason for the status received

    billcode : Your billcode / permanent link

    order_id : Your external payment reference no, if specified

    amount : Payment amount received

    You may check bill payment status by submitting Bill Code and Bill External Reference No. Bill payment status code description as follows:-

    • 1 - Successful transaction
    • 2 - Pending transaction
    • 3 - Unsuccessful transaction

    Sample code

    
    <?php
      $some_data = array(
        'billCode' => 'td8bfqv7',
        'billExternalReferenceNo' => 'ASD0942YT'
      );  
    
      $curl = curl_init();
    
      curl_setopt($curl, CURLOPT_POST, 1);
      curl_setopt($curl, CURLOPT_URL, 'https://toyyibpay.com/index.php/api/getBillTransactions');  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $some_data);
    
      $result = curl_exec($curl);
      $info = curl_getinfo($curl);  
      curl_close($curl);
    
      echo $result;
    ?>
    											

    Sample result

    
    [{"billpaymentStatus":"3","billpaymentAmount":"100.00","billpaymentInvoiceNo":"B00030-467-025110300718"}]