From c0ec8aa44e578207196178c6b1fd375a11400af5 Mon Sep 17 00:00:00 2001 From: ao Date: Tue, 19 May 2015 12:29:18 +0100 Subject: [PATCH] v1.5 --- changelog.md | 3 ++ examples/3ds_redirect.php | 2 +- examples/cancel_authorised_order.php | 2 +- examples/capture_authorised_order.php | 2 +- examples/create_order.php | 3 +- examples/get_stored_cards.php | 2 +- examples/index.php | 70 +++++++++++++++------------ examples/partial_refund_order.php | 2 +- examples/refund_order.php | 2 +- lib/worldpay.php | 34 +++++++------ readme.md | 2 +- 11 files changed, 70 insertions(+), 54 deletions(-) diff --git a/changelog.md b/changelog.md index da43a26..9f83bb2 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +### 1.5 2015-05-19 +* Modify PHP library timeout period and message + ### 1.4 2015-03-04 * PHP 5.2 Error Exeption Handling * Authorisations diff --git a/examples/3ds_redirect.php b/examples/3ds_redirect.php index 1440b29..1695bd3 100644 --- a/examples/3ds_redirect.php +++ b/examples/3ds_redirect.php @@ -2,7 +2,7 @@ $amount*100, // Amount in pence 'is3DSOrder' => $_3ds, // 3DS 'authoriseOnly' => $authoriseOnly, + 'orderType' => $_POST['order-type'], //Order Type: ECOM/MOTO/RECURRING 'currencyCode' => $_POST['currency'], // Currency code 'name' => ($_3ds) ? '3D' : $name, // Customer name 'billingAddress' => $billing_address, // Billing address array diff --git a/examples/get_stored_cards.php b/examples/get_stored_cards.php index 2535f6d..917f534 100644 --- a/examples/get_stored_cards.php +++ b/examples/get_stored_cards.php @@ -1,7 +1,7 @@ +
+ + +
+
@@ -146,41 +154,41 @@
+ - - + diff --git a/examples/partial_refund_order.php b/examples/partial_refund_order.php index 9ebe990..e58ca99 100644 --- a/examples/partial_refund_order.php +++ b/examples/partial_refund_order.php @@ -1,7 +1,7 @@ "Invalid parameters", @@ -45,7 +46,8 @@ final class Worldpay ), 'json' => 'JSON could not be decoded', 'key' => 'Please enter your service key', - 'sslerror' => 'Worldpay SSL certificate could not be validated' + 'sslerror' => 'Worldpay SSL certificate could not be validated', + 'timeouterror'=> 'Gateway timeout - possible order failure. Please review the order in the portal to confirm success.' ); /** @@ -80,7 +82,7 @@ public function __construct($service_key = false, $timeout = false) private function getClientIp() { $ipaddress = ''; - + if (isset($_SERVER['HTTP_CLIENT_IP'])) { $ipaddress = $_SERVER['HTTP_CLIENT_IP']; } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { @@ -174,7 +176,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m } $clientUserAgent = 'os.name=' . php_uname('s') . ';os.version=' . php_uname('r') . ';os.arch=' . - $arch . ';lang.version='. phpversion() . ';lib.version=;' . + $arch . ';lang.version='. phpversion() . ';lib.version=v1.5;' . 'api.version=v1;lang=php;owner=worldpay'; curl_setopt( @@ -194,7 +196,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } - + $result = curl_exec($ch); $info = curl_getinfo($ch); @@ -206,6 +208,8 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m if ($result === false) { if ($errno === 60) { self::onError('sslerror', false, $errno, null, $err); + } else if ($errno === 28) { + self::onError('timeouterror', false, $errno, null, $err); } else { self::onError('uanv', false, $errno, null, $err); } @@ -222,7 +226,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m if ($expectResponse && ($response === null || $response === false )) { self::onError('uanv', self::$errors['json'], 503); } - + // Check the status code exists if (isset($response["httpStatusCode"])) { @@ -241,7 +245,7 @@ private function sendRequest($action, $json = false, $expectResponse = false, $m } elseif ($expectResponse && $info['http_code'] != 200) { // If we expect a result and we have an error self::onError('uanv', self::$errors['json'], 503); - + } elseif (!$expectResponse) { if ($info['http_code'] != 200) { @@ -275,7 +279,7 @@ public function createOrder($order = array()) ); $order = array_merge($defaults, $order); - + $obj = array( "token" => $order['token'], "orderDescription" => $order['orderDescription'], @@ -283,13 +287,13 @@ public function createOrder($order = array()) "is3DSOrder" => ($order['is3DSOrder']) ? true : false, "currencyCode" => $order['currencyCode'], "name" => $order['name'], - "orderType" => $order['orderType'], + "orderType" => (in_array($order['orderType'], $this->order_types)) ? $order['orderType'] : 'ECOM', "authorizeOnly" => ($order['authoriseOnly']) ? true : false, "billingAddress" => $order['billingAddress'], "customerOrderCode" => $order['customerOrderCode'], "customerIdentifiers" => $order['customerIdentifiers'] ); - + if ($obj['is3DSOrder']) { $_SESSION['worldpay_sessionid'] = uniqid(); $obj['shopperIpAddress'] = $this->getClientIp(); @@ -299,7 +303,7 @@ public function createOrder($order = array()) } $json = json_encode($obj); - + $response = $this->sendRequest('orders', $json, true); if (isset($response["orderCode"])) { @@ -309,7 +313,7 @@ public function createOrder($order = array()) self::onError("apierror"); } } - + /** * Authorise Worldpay 3DS Order * @param string $orderCode @@ -381,7 +385,7 @@ public function refundOrder($orderCode = false, $amount = null) } /** - * Get card details from Worldpay token + * Get card details from Worldpay token * @param string $token * @return array card details * */ @@ -395,7 +399,7 @@ public function getStoredCardDetails($token = false) if (!isset($response['paymentMethod'])) { self::onError("apierror"); } - + return $response['paymentMethod']; } diff --git a/readme.md b/readme.md index 65023e1..eece2db 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Worldpay PHP Library +# Worldpay PHP Library v1.5 #### Documentation https://online.worldpay.com/docs