From 0eaf23a1fbb7e10a5e98b5c15f62c75c23180da4 Mon Sep 17 00:00:00 2001 From: Juan Gonzalez <0505gonzalez@gmail.com> Date: Sun, 27 Nov 2016 17:54:46 -0800 Subject: [PATCH] Credit card payment capture method --- README.md | 6 ++++ src/XenditPHPClient.php | 28 +++++++++++++++++++ .../capture_credit_card_payment_example.php | 17 +++++++++++ 3 files changed, 51 insertions(+) create mode 100644 src/examples/capture_credit_card_payment_example.php diff --git a/README.md b/README.md index bf2b7d2..a0e0f90 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/XenditPHPClient.php b/src/XenditPHPClient.php index 9ff517d..ff5c505 100644 --- a/src/XenditPHPClient.php +++ b/src/XenditPHPClient.php @@ -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; + } } ?> diff --git a/src/examples/capture_credit_card_payment_example.php b/src/examples/capture_credit_card_payment_example.php new file mode 100644 index 0000000..d2c7584 --- /dev/null +++ b/src/examples/capture_credit_card_payment_example.php @@ -0,0 +1,17 @@ +captureCreditCardPayment($external_id, $token_id, $amount); + + print_r($response); +?>