Skip to content

Commit

Permalink
Merge pull request #31 from xendit/optional-fields-capture
Browse files Browse the repository at this point in the history
add optional field for capture
  • Loading branch information
albertlieyingadrian authored Oct 10, 2017
2 parents db0b265 + 6693cbf commit 58f4b62
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ cd src/
php examples/capture_credit_card_payment_example.php [external_id] [token_id] [amount]
```

# Capture credit card payment with authentication id
```
cd src/
php examples/capture_credit_card_payment_with_authentication_id_example.php [external_id] [token_id] [amount] [authentication_id]
```

# Name validator
```
cd src/
Expand Down
19 changes: 15 additions & 4 deletions src/XenditPHPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getVirtualAccountBanks () {
curl_close($curl);

$responseObject = json_decode($response, true);
return $responseObject;
return $responseObject;
}

function createCallbackVirtualAccount ($external_id, $bank_code, $name, $virtual_account_number = null) {
Expand Down Expand Up @@ -168,7 +168,7 @@ function getAvailableDisbursementBanks () {
curl_close($curl);

$responseObject = json_decode($response, true);
return $responseObject;
return $responseObject;
}

function getInvoice ($invoice_id) {
Expand Down Expand Up @@ -211,7 +211,7 @@ function getBalance () {
return $responseObject;
}

function captureCreditCardPayment ($external_id, $token_id, $amount, $authenticationId = null) {
function captureCreditCardPayment ($external_id, $token_id, $amount, $capture_options = null) {
$curl = curl_init();

$headers = array();
Expand All @@ -222,7 +222,18 @@ function captureCreditCardPayment ($external_id, $token_id, $amount, $authentica
$data['external_id'] = $external_id;
$data['token_id'] = $token_id;
$data['amount'] = $amount;
$data['authentication_id'] = $authenticationId;

if (!empty($capture_options['authentication_id'])) {
$data['authentication_id'] = $capture_options['authentication_id'];
}

if (!empty($capture_options['card_cvn'])) {
$data['card_cvn'] = $capture_options['card_cvn'];
}

if (!empty($capture_options['capture'])) {
$data['capture'] = $capture_options['capture'];
}

$payload = json_encode($data);

Expand Down
17 changes: 17 additions & 0 deletions src/examples/capture_credit_card_payment_with_options_example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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];
$token_id = $argv[2];
$amount = $argv[3];
$capture_options['authentication_id'] = $argv[4];

$response = $xenditPHPClient->captureCreditCardPayment($external_id, $token_id, $amount, $capture_options);

print_r($response);
?>

0 comments on commit 58f4b62

Please sign in to comment.