Skip to content

Commit

Permalink
Merge pull request #17 from xendit/cc-refunds
Browse files Browse the repository at this point in the history
update refunds method client
  • Loading branch information
albertlieyingadrian authored Apr 25, 2017
2 parents 10f92bc + a8bfd8b commit 20600fc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ curl --include \
4. localhost:8006/paid_invoice_from_xendit (callback url) get the paid invoice data.
```

# Issue credit card refund without idempotency key
```
cd src/
php examples/issue_credit_card_refund_example.php [credit_card_charge_id] [amount] [external_id]
```

# Issue credit card refund with idempotency key
```
cd src/
php examples/issue_credit_card_refund_with_idempotency_example.php [credit_card_charge_id] [amount] [external_id] [optional-idempotency-key]
```

# Subscribe Credit Card Recurring Payment
```
cd src/
Expand Down
7 changes: 6 additions & 1 deletion src/XenditPHPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,20 @@ function captureCreditCardPayment ($external_id, $token_id, $amount) {
return $responseObject;
}

function issueCreditCardRefund ($credit_card_charge_id, $amount) {
function issueCreditCardRefund ($credit_card_charge_id, $amount, $external_id, $options = null) {
$curl = curl_init();

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

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

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

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

$payload = json_encode($data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

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

$response = $xenditPHPClient->issueCreditCardRefund($credit_card_charge_id, $amount);
$response = $xenditPHPClient->issueCreditCardRefund($credit_card_charge_id, $amount, $external_id);

print_r($response);
?>
17 changes: 17 additions & 0 deletions src/examples/issue_credit_card_refund_with_idempotency_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);

$credit_card_charge_id = $argv[1];
$amount = $argv[2];
$external_id = $argv[3];
$options['X-IDEMPOTENCY-KEY'] = $argv[4];

$response = $xenditPHPClient->issueCreditCardRefund($credit_card_charge_id, $amount, $external_id, $options);

print_r($response);
?>

0 comments on commit 20600fc

Please sign in to comment.