Skip to content

Commit

Permalink
Credit card payment capture method
Browse files Browse the repository at this point in the history
  • Loading branch information
0505gonzalez committed Nov 28, 2016
1 parent 4b84da4 commit 0eaf23a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ cd src/
php examples/get_balance_example.php
```

# Capture credit card payment
```
cd src/
php examples/capture_credit_card_payment_example.php [token_id] [amount] [external_id]
```

# Post Invoice Status Callback Example : #
```
1. Run: cd src/examples
Expand Down
28 changes: 28 additions & 0 deletions src/XenditPHPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,33 @@ function getBalance () {
$responseObject = json_decode($response, true);
return $responseObject;
}

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

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

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

$data['external_id'] = $external_id;
$data['token_id'] = $token_id;
$data['amount'] = $amount;

$payload = json_encode($data);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_USERPWD, $this->secret_api_key.":");
curl_setopt($curl, CURLOPT_URL, $end_point);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);
curl_close($curl);

$responseObject = json_decode($response, true);
return $responseObject;
}
}
?>
17 changes: 17 additions & 0 deletions src/examples/capture_credit_card_payment_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');
$options['server_domain'] = constant('SERVER_DOMAIN');

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

$external_id = $argv[1];
$token_id = $argv[2];
$amount = $argv[3];

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

print_r($response);
?>

0 comments on commit 0eaf23a

Please sign in to comment.