PHP code example of jomweb / billplz
1. Go to this page and download the library: Download jomweb/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/ */
jomweb / billplz example snippets
nt = Billplz\Client::make('your-api-key', 'your-x-signature-key');
use Billplz\Client;
$billplz = Client::make('your-api-key');
use Billplz\Client;
$billplz = Client::make('your-api-key', 'your-x-signature-key');
use Billplz\Client;
$http = Laravie\Codex\Discovery::client();
$billplz = new Client($http, 'your-api-key', 'your-x-signature-key');
$billplz->useSandbox();
$billplz->useVersion('v3');
$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' => \Duit\MYR::given(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" => \Duit\MYR::given(100),
"variable_cut" => null,
],
];
$response = $collection->all();
var_dump($response->toArray());
return [
"collections": [{
"id" => "inbmmepb",
"title" => "My First API Collection",
"logo" => [
"thumb_url" => null,
"avatar_url" => null,
],
"split_header" => null,
"split_payments" => [
[
"email" => "[email protected] ",
"fixed_cut" => 100,
"variable_cut" => 2,
"stack_order" => 0,
],
[
"email" => "[email protected] ",
"fixed_cut" => 200,
"variable_cut" => 3,
"stack_order" => 1,
],
],
"status" => "active",
}],
"page" => 1,
];
$response = $collection->all([
'page' => 2,
'status' => 'active',
]);
var_dump($response->toArray());
return [
"collections": [{
"id" => "inbmmepb",
"title" => "My First API Collection",
"logo" => [
"thumb_url" => null,
"avatar_url" => null,
],
"split_header" => null,
"split_payments" => [
[
"email" => "[email protected] ",
"fixed_cut" => 100,
"variable_cut" => 2,
"stack_order" => 0,
],
[
"email" => "[email protected] ",
"fixed_cut" => 200,
"variable_cut" => 3,
"stack_order" => 1,
],
],
"status" => "active",
}],
"page" => 2,
];
$response = $collection->get('inbmmepb');
var_dump($response->toArray());
return [
"id" => "inbmmepb",
"title" => "My First API Collection",
"logo" => [
"thumb_url" => null,
"avatar_url" => null,
],
"split_header" => null,
"split_payments" => [
[
"email" => "[email protected] ",
"fixed_cut" => 100,
"variable_cut" => 2,
"stack_order" => 0,
],
[
"email" => "[email protected] ",
"fixed_cut" => 200,
"variable_cut" => 3,
"stack_order" => 1,
],
],
"status" => "active",
];
$response = $collection->deactivate('inbmmepb');
$response = $collection->deactivate('inbmmepb');
$collection = $billplz->openCollection();
$response = $collection->create(
'My First API Collection',
'Maecenas eu placerat ante. Fusce ut neque justo, et aliquet enim. In hac habitasse platea dictumst.',
\Duit\MYR::given(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" => \Duit\MYR::given(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",
];
$response = $collection->all();
var_dump($response->toArray());
return [
"open_collections": [{
"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" => \Duit\MYR::given(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",
}],
"page" => 1,
];
$response = $collection->all([
'page' => 2,
'status' => 'active',
]);
var_dump($response->toArray());
return [
"open_collections": [{
"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" => \Duit\MYR::given(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",
}],
"page" => 2
];
$response = $collection->get('0pp87t_6');
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" => \Duit\MYR::given(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',
\Duit\MYR::given(200),
'http://example.com/webhook/',
'Maecenas eu placerat ante.',
[], // optional.
);
var_dump($response->toArray());
return [
"id" => "8X0Iyzaw",
"collection_id" => "inbmmepb",
"paid" => false,
"state" => "overdue",
"amount" => \Duit\MYR::given(200),
"paid_amount" => \Duit\MYR::given(0),
"due_at" => new \DateTime('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."
];
$response = $bill->create(
'inbmmepb',
'[email protected] ',
null,
'Michael API V3',
\Duit\MYR::given(200),
'http://example.com/webook/',
'Maecenas eu placerat ante.',
['redirect_url' => 'http://example.com/redirect/']
);
var_dump($response->toArray());
return [
"id" => "8X0Iyzaw",
"collection_id" => "inbmmepb",
"paid" => false,
"state" => "overdue",
"amount" => \Duit\MYR::given(200),
"paid_amount" => \Duit\MYR::given(0),
"due_at" => new \DateTime('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" => "http://example.com/redirect/",
"callback_url" => "http://example.com/webhook/",
"description" => "Maecenas eu placerat ante."
];
$response = $bill->get('8X0Iyzaw');
var_dump($response->toArray());
return [
"id" => "8X0Iyzaw",
"collection_id" => "inbmmepb",
"paid" => false,
"state" => "due",
"amount" => \Duit\MYR::given(200),
"paid_amount" => \Duit\MYR::given(0),
"due_at" => new \DateTime("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());
[]
$data = $bill->redirect($_GET);
return [
'id' => 'W_79pJDk',
'paid' => true,
'paid_at' => new \DateTime('2015-03-09 16:23:59 +0800'),
];
return [
'id' => 'W_79pJDk',
'paid' => true,
'paid_at' => new \DateTime('2015-03-09 16:23:59 +0800'),
'transaction_id' => 'AC4GC031F42H',
'transaction_status' => 'completed',
];
$data = $bill->webhook($_POST);
return [
'id' => 'W_79pJDk',
'collection_id' => 'inbmmepb',
'paid' => true,
'state' => 'paid',
'amount' => \Duit\MYR::given(200),
'paid_amount' => \Duit\MYR::given(0),
'due_at' => new \DateTime('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' => new \DateTime('2015-03-09 16:23:59 +0800'),
];
return [
'id' => 'W_79pJDk',
'collection_id' => 'inbmmepb',
'paid' => true,
'state' => 'paid',
'amount' => \Duit\MYR::given(200),
'paid_amount' => \Duit\MYR::given(0),
'due_at' => new \DateTime('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' => new \DateTime('2015-03-09 16:23:59 +0800'),
'transaction_id' => 'AC4GC031F42H',
'transaction_status' => 'completed',
];
$transaction = $billplz->transaction();
$response = $transaction->get('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->get('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->createAccount('Insan Jaya', '91234567890', '999988887777', 'MBBEMYKL', true);
var_dump($response->toArray());
return [
"name" => "Insan Jaya",
"id_no" => "91234567890",
"acc_no" => "999988887777",
"code" => "MBBEMYKL",
"organization" => true,
"authorization_date" => "2017-07-03",
"status" => "pending",
"processed_at" => null,
"rejected_desc" => null
]
$response = $bank->get('1234567890');
var_dump($response->toArray());
return [
"name" => "sara",
"id_no" => "820909101001",
"acc_no" => "1234567890",
"code" => "MBBEMYKL",
"organization" => false,
"authorization_date" => "2015-12-03",
"status" => "pending",
"processed_at" => null,
"rejected_desc" => null
]
$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,
],
],
];
$paymentOrderCollection = $billplz->paymentOrderCollection();
$response = $paymentOrderCollection->create(
'My First API Payment Order Collection'
);
var_dump($response->toArray());
$response = $paymentOrderCollection->get(
'8f4e331f-ac71-435e-a870-72fe520b4563'
);
var_dump($response->toArray());
$paymentOrder = $billplz->paymentOrder();
$response = $paymentOrder->create(
'8f4e331f-ac71-435e-a870-72fe520b4563',
'MBBEMYKL',
'543478924652',
'820808062202',
'Michael Yap',
'Maecenas eu placerat ante.',
2000
);
var_dump($response->toArray());
$response = $paymentOrder->get(
'cc92738f-dfda-4969-91dc-22a44afc7e26'
);
var_dump($response->toArray());
$response = $paymentOrder->limit();
var_dump($response->toArray());
$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.