PHP code example of nasrulhazim / billplz

1. Go to this page and download the library: Download nasrulhazim/billplz library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nasrulhazim / billplz example snippets




use Billplz\Client;
use Http\Client\Common\HttpMethodsClient;
use Http\Adapter\Guzzle6\Client as GuzzleHttpClient;
use Http\Message\MessageFactory\GuzzleMessageFactory;

$http = new HttpMethodsClient(
    new GuzzleHttpClient(),
    new GuzzleMessageFactory()
);


$billplz = new Client($http, 'your-api-key');



use Billplz\Client;

$billplz = Client::make('your-api-key');

$billplz->useSandbox();

$billplz->useVersion('v4');

$collection = $billplz->collection();

$response = $collection->create('My First API Collection');

var_dump($response->toArray());

return [
    "id" => "inbmmepb",
    "title" => "My First API Collection",
    "logo" => [
        "thumb_url" => null,
        "avatar_url" => null
    ],
    "split_payment" => [
        "email" => null,
        "fixed_cut" => null,
        "variable_cut" => null
    ]
];

$response = $collection->create('My First API Collection', [
    'logo' => '@/Users/Billplz/Documents/uploadPhoto.png',
    'split_payment' => [
        'email' => '[email protected]',
        'fixed_cut' => \Money\Money::MYR(100),
    ],
]);

var_dump($response->toArray());

return [
    "id" => "inbmmepb",
    "title" => "My First API Collection",
    "logo" => [
        "thumb_url" => "https://sample.net/assets/uploadPhoto.png",
        "avatar_url" => "https://sample.net/assets/uploadPhoto.png"
    ],
    "split_payment" => [
        "email" => "[email protected]",
        "fixed_cut" => \Money\Money::MYR(100),
        "variable_cut" => null
    ]
]

$response = $collection->createOpen(
    'My First API Collection',
    'Maecenas eu placerat ante. Fusce ut neque justo, et aliquet enim. In hac habitasse platea dictumst.',
    Money\Money::MYR(299)
);

var_dump($response->toArray());

return [
    "id" => "0pp87t_6",
    "title" => "MY FIRST API OPEN COLLECTION",
    "description" => "Maecenas eu placerat ante. Fusce ut neque justo, et aliquet enim. In hac habitasse platea dictumst.",
    "reference_1_label" => null,
    "reference_2_label" => null,
    "email_link" => null,
    "amount" => \Money\Money::MYR(299),
    "fixed_amount" => true,
    "tax" => null,
    "fixed_quantity" => true,
    "payment_button" => "pay",
    "photo" => [
        "retina_url" =>  null,
        "avatar_url" =>  null
    ],
        "split_payment" => [
        "email" => null,
        "fixed_cut" => null,
        "variable_cut" => null
    ],
    "url" => "https://www.billplz.com/0pp87t_6"
]

$bill = $billplz->bill();

$response = $bill->create(
    'inbmmepb',
    '[email protected]',
    null,
    'Michael API V3',
    Money\Money::MYR(200),
    'http://example.com/webhook/',
    'Maecenas eu placerat ante.'
);

var_dump($response->toArray());

return [
    "id" => "8X0Iyzaw",
    "collection_id" => "inbmmepb",
    "paid" => false,
    "state" => "overdue",
    "amount" => \Money\Money::MYR(200),
    "paid_amount" => \Money\Money::MYR(0),
    "due_at" => \DateTime::createFromFormat('Y-m-d', "2015-3-9"),
    "email" => "[email protected]",
    "mobile" => null,
    "name" => "MICHAEL API V3",
    "url" => "https://www.billplz.com/bills/8X0Iyzaw",
    "reference_1_label" => "Reference 1",
    "reference_1" => null,
    "reference_2_label" => "Reference 2",
    "reference_2" => null,
    "redirect_url" => null,
    "callback_url" => "http://example.com/webhook/",
    "description" => "Maecenas eu placerat ante."
];

$data = $billplz->webhook($_POST);

return [
    'id' => 'W_79pJDk',
    'collection_id' => 'inbmmepb',
    'paid' => true,
    'state' => 'paid',
    'amount' => \Money\Money::MYR(200),
    'paid_amount' => \Money\Money::MYR(0),
    'due_at' => \Carbon\Carbon::parse('2020-12-31'),
    'email' => '[email protected]',
    'mobile' => '+60112223333',
    'name' => 'MICHAEL API',
    'metadata' => [
        'id' => 9999,
        'description' => 'This is to test bill creation',
    ],
    'url' => 'https://billplz.dev/bills/W_79pJDk',
    'paid_at' => \Carbon\Carbon::parse('2015-03-09 16:23:59 +0800'),
];

$response = $bill->show('8X0Iyzaw');

var_dump($response->toArray());

return [
    "id" => "8X0Iyzaw",
    "collection_id" => "inbmmepb",
    "paid" => false,
    "state" => "due",
    "amount" => \Money\Money::MYR(200),
    "paid_amount" => \Money\Money::MYR(0),
    "due_at" => \Carbon\Carbon::parse("2020-12-31"),
    "email" => "[email protected]",
    "mobile" => "+60112223333",
    "name" => "MICHAEL API V3",
    "url" => "https://www.billplz.com/bills/8X0Iyzaw",
    "reference_1_label" => "First Name",
    "reference_1" => "Jordan",
    "reference_2_label" => "Last Name",
    "reference_2" => "Michael",
    "redirect_url" => "http://example.com/redirect/",
    "callback_url" => "http://example.com/webhook/",
    "description" => "Maecenas eu placerat ante."
]

$response = $bill->destroy('8X0Iyzaw');

var_dump($response->toArray());

[]

$transaction = $billplz->transaction();

$response = $transaction->show('inbmmepb');

var_dump($response->toArray());

return [
    "bill_id" => "inbmmepb"
    "transactions" => [
        [
            "id": "60793D4707CD",
            "status": "completed",
            "completed_at": "2017-02-23T12:49:23.612+08:00",
            "payment_channel": "FPX"
        ],
        [
            "id" => "28F3D3194138",
            "status" => "failed",
            "completed_at" => ,
            "payment_channel" => "FPX"
        ]
    ],
    "page" => 1
]

$response = $transaction->show('8X0Iyzaw', [
    'page' => 1,
    'status' => 'completed'
]);

var_dump($response->toArray());

return [
    "bill_id" => "8X0Iyzaw"
    "transactions" => [
        [
            "id" => "60793D4707CD",
            "status" => "completed",
            "completed_at" => "2017-02-23T12:49:23.612+08:00",
            "payment_channel" => "FPX"
        ]
    ],
    "page" => 1
]

$bank = $billplz->bank();

$response = $bank->checkAccount('1234567890');

var_dump($response->toArray());

return [
    "name" => "verified"
]

$list = $bank->supportedForFpx();

var_dump($list->toArray());

return [
    "banks" => [
        [
            "name" => "PBB0233",
            "active" => true,
        ],
        [
            "name" => "MBB0227",
            "active" => true,
        ],
        [
            "name" => "MBB0228",
            "active" => true,
        ],
    ],
];

$response->getBody();

$response->toArray();

if ($response->getStatusCode() !== 200) {
    throw new SomethingHasGoneReallyBadException();
}

$response->getHeaders(); // get all headers as array.
$response->hasHeader('Content-Type'); // check if `Content-Type` header exist.
$response->getHeader('Content-Type'); // get `Content-Type` header.