From 62667f5f323a5094871ae731ad63dcc901687702 Mon Sep 17 00:00:00 2001 From: seowyanyi Date: Fri, 31 Mar 2017 03:34:45 +0800 Subject: [PATCH] include indo cc endpoints --- examples/CardsTest.php | 52 ++++++++++++++++++++++++++++++++++++++++++ lib/ApiRequestor.php | 8 ------- lib/Card.php | 37 +++++++++++++++++++++--------- lib/Xfers.php | 2 +- 4 files changed, 79 insertions(+), 20 deletions(-) diff --git a/examples/CardsTest.php b/examples/CardsTest.php index 1505760..1a3f532 100644 --- a/examples/CardsTest.php +++ b/examples/CardsTest.php @@ -1,7 +1,59 @@ $chargeId, + 'card_name' => 'Visnu', + 'card_type' => 'V', + 'card_no' => '4137180300023783', + 'card_cvc' => '666', + 'expiry_month' => '01', + 'expiry_year' => '2021', + 'save_card' => true + ); + $resp = \Xfers\Card::chargeGuest($params); + print_r($resp); +} catch (\Xfers\Error\InvalidRequest $e) { + echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n"; +} + +try { + \Xfers\Xfers::setApiKey('LXcbEXxAZ894yVsSC1-iLpUWFx_RKTgeASsdL5TZhbc'); + echo "Listing all cards\n"; + $customer = "hello@xfers.io"; + $resp = \Xfers\Card::listAll($customer); + print_r($resp); +} catch (\Xfers\Error\InvalidRequest $e) { + echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n"; +} + +try { + echo "Charge existing card\n"; + $chargeId = '5d8c605550114d3fbfdeffbf85ba3d69'; + $token = '2D23113F-307F-41CA-8921-7A977668E3EC'; + $resp = \Xfers\Card::chargeExisting($chargeId, $token); + print_r($resp); +} catch (\Xfers\Error\InvalidRequest $e) { + echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n"; +} + +try { + echo "Deleting card\n"; + $token = '2D23113F-307F-41CA-8921-7A977668E3EC'; + $resp = \Xfers\Card::delete($token); + print_r($resp); +} catch (\Xfers\Error\InvalidRequest $e) { + echo 'Caught InvalidRequest exception: ', $e->getMessage(), "\n"; +} + + +// SINGAPORE \Xfers\Xfers::setApiKey('WuTp3zM7UEpmUkeAyGPxRHmnXAx-hXJ7jzdqmxY6S1o'); \Xfers\Xfers::setSGSandbox(); diff --git a/lib/ApiRequestor.php b/lib/ApiRequestor.php index 04cd758..b5163c9 100644 --- a/lib/ApiRequestor.php +++ b/lib/ApiRequestor.php @@ -67,14 +67,6 @@ private function _requestRaw($method, $url, $params, $headers, $connectKey = nul $myApiKey = Xfers::$apiKey; } - if (!$myApiKey) { - $msg = 'No API key provided. (HINT: set your API key using ' - . '"Xfers::setApiKey()". You can generate API keys from ' - . 'the Xfers web interface. See http://docs.xfers.io/#authentication for ' - . 'details, or email support@xfers.io if you have any questions.'; - throw new Error\Authentication($msg); - } - $absUrl = $this->_apiBase.$url; $langVersion = phpversion(); diff --git a/lib/Card.php b/lib/Card.php index f11c7f1..18d3ec4 100644 --- a/lib/Card.php +++ b/lib/Card.php @@ -6,10 +6,15 @@ class Card extends ApiResource { public static $baseUrl = '/cards'; - public static function listAll($userApiToken) + public static function listAll($param) { - $url = self::$baseUrl . "?user_api_token=" . $userApiToken; - return self::_get($url, null); + if (strpos(Xfers::$apiBase, 'id') !== false) { + $url = self::$baseUrl . "?customer=" . $param; + return self::_get($url, null); + } else { + $url = self::$baseUrl . "?user_api_token=" . $param; + return self::_get($url, null); + } } public static function add($params) @@ -17,12 +22,15 @@ public static function add($params) return self::_post($params, self::$baseUrl, null); } - public static function delete($id, $userApiToken) + public static function delete($id, $userApiToken=null) { $url = self::$baseUrl . "/" . $id; - $params = array( - 'user_api_token' => $userApiToken - ); + $params = null; + if ($userApiToken != null) { + $params = array( + 'user_api_token' => $userApiToken + ); + } return self::_delete($url, null, $params); } @@ -41,12 +49,19 @@ public static function chargeGuest($params) return self::_post($params, $url, null); } - public static function chargeExisting($chargeId) + public static function chargeExisting($chargeId, $token=null) { $url = "/credit_card_charges/charge_card"; - $params = array( - 'txn_id' => $chargeId - ); + if ($token != null) { + $params = array( + 'txn_id' => $chargeId, + 'token' => $token + ); + } else { + $params = array( + 'txn_id' => $chargeId + ); + } return self::_post($params, $url, null); } diff --git a/lib/Xfers.php b/lib/Xfers.php index fa93f6b..5331b06 100644 --- a/lib/Xfers.php +++ b/lib/Xfers.php @@ -19,7 +19,7 @@ class Xfers const IDproductionBase = 'https://id.xfers.com/api/v3'; public static $apiBase = ""; - const VERSION = '1.2.0'; + const VERSION = '1.3.0'; /** * @return string The API key used for requests.