-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for PaymentOrderCollection and PaymentOrder (#55)
* Initial commit * Apply suggestions from code review --------- Co-authored-by: Mior Muhammad Zaki <[email protected]>
- Loading branch information
1 parent
96bf2c1
commit f8994a3
Showing
12 changed files
with
412 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$api = ''; | ||
$signatureKey = ''; | ||
$paymentOrderCollectionId = ''; | ||
|
||
$billplz = Billplz\Client::make($api, $signatureKey)->useSandbox(); | ||
|
||
$response = $billplz->paymentOrderCollection()->create( | ||
"test", | ||
[ | ||
'callback_url' => 'http://example.com/webhook', | ||
], | ||
); | ||
|
||
var_dump($response->getStatusCode(), $response->toArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$api = ''; | ||
$signatureKey = ''; | ||
$paymentOrderCollectionId = ''; | ||
|
||
$billplz = Billplz\Client::make($api, $signatureKey)->useSandbox(); | ||
|
||
$response = $billplz->paymentOrder()->create( | ||
$paymentOrderCollectionId, | ||
"MBBEMYKL", | ||
"123456789012", | ||
"123456789012", | ||
"Ameer Shah", | ||
"Payment Order", | ||
1000, | ||
); | ||
|
||
var_dump($response->getStatusCode(), $response->toArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$api = ''; | ||
$signatureKey = ''; | ||
$paymentOrderCollectionId = ''; | ||
|
||
$billplz = Billplz\Client::make($api, $signatureKey)->useSandbox(); | ||
|
||
$response = $billplz->paymentOrderCollection()->get( | ||
$paymentOrderCollectionId | ||
); | ||
|
||
var_dump($response->getStatusCode(), $response->toArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$api = ''; | ||
$signatureKey = ''; | ||
|
||
$billplz = Billplz\Client::make($api, $signatureKey)->useSandbox(); | ||
|
||
$response = $billplz->paymentOrder()->limit(); | ||
|
||
var_dump($response->getStatusCode(), $response->toArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$api = ''; | ||
$signatureKey = ''; | ||
$paymentOrderId = ''; | ||
|
||
$billplz = Billplz\Client::make($api, $signatureKey)->useSandbox(); | ||
|
||
$response = $billplz->paymentOrder()->get( | ||
$paymentOrderId | ||
); | ||
|
||
var_dump($response->getStatusCode(), $response->toArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Billplz; | ||
|
||
class Checksum | ||
{ | ||
//V5 API introduces new security measures. | ||
public static function create(string $key, array $attributes): string | ||
{ | ||
return hash_hmac('sha512', implode('', $attributes), (string) $key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Billplz\Contracts; | ||
|
||
use Laravie\Codex\Contracts\Request; | ||
use Laravie\Codex\Contracts\Response; | ||
|
||
interface PaymentOrder extends Request | ||
{ | ||
/** | ||
* Create a Payment Order | ||
* | ||
* @param int $total | ||
* @param array<string, mixed> $optional | ||
*/ | ||
public function create( | ||
string $paymentOrderCollectionId, | ||
string $bankCode, | ||
string $bankAccountNumber, | ||
string $identityNumber, | ||
string $name, | ||
string $description, | ||
$total, | ||
array $optional = [] | ||
): Response; | ||
|
||
/** | ||
* Get a Payment Order | ||
*/ | ||
public function get( | ||
string $paymentOrderId, | ||
): Response; | ||
|
||
/** | ||
* Get a Payment Order Limit | ||
*/ | ||
public function limit(): Response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Billplz\Contracts; | ||
|
||
use Laravie\Codex\Contracts\Request; | ||
use Laravie\Codex\Contracts\Response; | ||
|
||
interface PaymentOrderCollection extends Request | ||
{ | ||
/** | ||
* Create a Payment Order Collection | ||
* | ||
* @param \Money\Money|\Duit\MYR|int $amount | ||
* @param array<string, mixed> $optional | ||
*/ | ||
public function create( | ||
string $title, | ||
array $optional = [] | ||
): Response; | ||
|
||
/** | ||
* Get a Payment Order Collection | ||
*/ | ||
public function get(string $paymentOrderCollectionId): Response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Billplz\Five; | ||
|
||
use Billplz\Checksum; | ||
use Billplz\Contracts\PaymentOrder as Contract; | ||
use Billplz\Request; | ||
use Laravie\Codex\Contracts\Response; | ||
|
||
class PaymentOrder extends Request implements Contract | ||
{ | ||
/** | ||
* Version namespace. | ||
* | ||
* @var string | ||
*/ | ||
protected $version = 'v5'; | ||
|
||
/** | ||
* Create a Payment Order | ||
* | ||
* @param int $total | ||
*/ | ||
public function create( | ||
string $paymentOrderCollectionId, | ||
string $bankCode, | ||
string $bankAccountNumber, | ||
string $identityNumber, | ||
string $name, | ||
string $description, | ||
$total, | ||
array $optional = [] | ||
): Response { | ||
$epoch = time(); | ||
|
||
$body['payment_order_collection_id'] = $paymentOrderCollectionId; | ||
$body['bank_code'] = $bankCode; | ||
$body['bank_account_number'] = $bankAccountNumber; | ||
$body['identity_number'] = $identityNumber; | ||
$body['name'] = $name; | ||
$body['description'] = $description; | ||
$body['total'] = $total; | ||
$body['epoch'] = $epoch; | ||
$body['checksum'] = Checksum::create($this->client->getSignatureKey(), [ | ||
$paymentOrderCollectionId, | ||
$bankAccountNumber, | ||
$total, | ||
$epoch | ||
]); | ||
|
||
$body = array_merge($body, $optional); | ||
|
||
return $this->send('POST', 'payment_orders', [], $body); | ||
} | ||
|
||
/** | ||
* Get a Payment Order | ||
*/ | ||
public function get( | ||
string $paymentOrderId, | ||
): Response { | ||
$epoch = time(); | ||
|
||
$body['payment_order_id'] = $paymentOrderId; | ||
$body['epoch'] = $epoch; | ||
$body['checksum'] = Checksum::create($this->client->getSignatureKey(), [ | ||
$paymentOrderId, | ||
$epoch | ||
]); | ||
|
||
return $this->send('GET', "payment_orders/{$paymentOrderId}", [], $body); | ||
} | ||
|
||
/** | ||
* Get a Payment Order Limit | ||
*/ | ||
public function limit( | ||
): Response { | ||
$epoch = time(); | ||
|
||
$body['epoch'] = $epoch; | ||
$body['checksum'] = Checksum::create($this->client->getSignatureKey(), [ | ||
$epoch | ||
]); | ||
|
||
return $this->send('GET', "payment_order_limit", [], $body); | ||
} | ||
} |
Oops, something went wrong.