Skip to content

Commit

Permalink
add idempotency key options in disbursement
Browse files Browse the repository at this point in the history
  • Loading branch information
albertlieyingadrian committed Feb 27, 2017
1 parent 0979a44 commit e2a7aca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ cd src/
php examples/create_disbursement_example.php "CUSTOM_ID_1" 30000 "BCA" "Rizky" "1234567890"
```

# Create Disbursement With Idempotency Key Example : #
```
cd src/
php examples/create_disbursement_with_idempotency_key_example.php "CUSTOM_ID_1" 30000 "BCA" "Rizky" "1234567890" "idempotencykeytest123"
```

# GET Disbursement Example : #
```
cd src/
Expand Down
6 changes: 5 additions & 1 deletion src/XenditPHPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ function createInvoice ($external_id, $amount, $payer_email, $description) {
return $responseObject;
}

function createDisbursement ($external_id, $amount, $bank_code, $account_holder_name, $account_number) {
function createDisbursement ($external_id, $amount, $bank_code, $account_holder_name, $account_number, $disbursement_options = null) {
$curl = curl_init();

$headers = array();
$headers[] = 'Content-Type: application/json';

if (!empty($disbursement_options['X-IDEMPOTENCY-KEY'])) {
array_push($headers, 'X-IDEMPOTENCY-KEY: '.$disbursement_options['X-IDEMPOTENCY-KEY']);
}

$end_point = $this->server_domain.'/disbursements';

$data['external_id'] = $external_id;
Expand Down
18 changes: 18 additions & 0 deletions src/examples/create_disbursement_with_idempotency_key_example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
require('config/xendit_php_client_config.php');
require('XenditPHPClient.php');

$options['secret_api_key'] = constant('SECRET_API_KEY');

$xenditPHPClient = new XenditClient\XenditPHPClient($options);

$external_id = $argv[1];
$amount = $argv[2];
$bank_code = $argv[3];
$account_holder_name = $argv[4];
$account_number = $argv[5];
$disbursement_options['X-IDEMPOTENCY-KEY'] = $argv[6];

$response = $xenditPHPClient->createDisbursement($external_id, $amount, $bank_code, $account_holder_name, $account_number, $disbursement_options);
print_r($response);
?>

0 comments on commit e2a7aca

Please sign in to comment.