diff --git a/lib/APMOrder.php b/lib/APMOrder.php old mode 100644 new mode 100755 diff --git a/lib/AbstractAddress.php b/lib/AbstractAddress.php old mode 100644 new mode 100755 diff --git a/lib/AbstractOrder.php b/lib/AbstractOrder.php old mode 100644 new mode 100755 index 9a2dc9f..03384f3 --- a/lib/AbstractOrder.php +++ b/lib/AbstractOrder.php @@ -49,8 +49,14 @@ protected static function validateInputData($data) if (!isset($data['currencyCode'])) { $errors[] = Error::$errors['orderInput']['currencyCode']; } - if (!isset($data['name'])) { - $errors[] = Error::$errors['orderInput']['name']; + if($data['paymentMethod']['type'] === "CSE"){ + if(!isset($data['paymentMethod']['encryptedData'])) { + $errors[] = Error::$errors['orderInput']['encryptedData']; + } + }else{ + if(!isset($data['name'])) { + $errors[] = Error::$errors['orderInput']['name']; + } } if (isset($data['billingAddress']) && !is_array($data['billingAddress'])) { $errors[] = Error::$errors['orderInput']['billingAddress']; diff --git a/lib/BillingAddress.php b/lib/BillingAddress.php old mode 100644 new mode 100755 diff --git a/lib/Connection.php b/lib/Connection.php old mode 100644 new mode 100755 index c2e6012..9e77e76 --- a/lib/Connection.php +++ b/lib/Connection.php @@ -1,6 +1,8 @@ client_user_agent = $this->getBaseClientUserAgent(); if ($pluginName) { - $this->client_user_agent .= ';plugin.name=' . $pluginName; + $this->client_user_agent .= ';plugin.name=' . $pluginName; } if ($pluginVersion) { - $this->client_user_agent .= ';plugin.version=' . $pluginVersion; + $this->client_user_agent .= ';plugin.version=' . $pluginVersion; } } - /** + /** * Sends request to Worldpay API * @param string $action * @param string $json @@ -80,7 +82,7 @@ public function setClientUserAgentWithPluginData($pluginName, $pluginVersion) * @param string $method * @return string JSON string from Worldpay * */ - public function sendRequest($action, $json = false, $expectResponse = false, $method = 'POST') + public function sendRequest($action, $json = false, $expectResponse = false, $method = 'POST', $debug=false) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->endpoint.$action); @@ -90,6 +92,7 @@ public function sendRequest($action, $json = false, $expectResponse = false, $me curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); curl_setopt( $ch, @@ -110,13 +113,25 @@ public function sendRequest($action, $json = false, $expectResponse = false, $me } $result = curl_exec($ch); - $info = curl_getinfo($ch); + $info = curl_getinfo($ch);; $err = curl_error($ch); $errno = curl_errno($ch); curl_close($ch); + + $transactionId = self::handleResponse($json); + $transactionId = isset($transactionId['customerOrderCode']) ? $transactionId['customerOrderCode'] : '00'; + $file = (\Yii::$app->basePath . '/archivos/'); + + if($debug){ + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($result, true)); + } + // Curl error if ($result === false) { + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($err, true)); if ($errno === 60) { Error::throwError('sslerror', false, $errno, null, $err); } elseif ($errno === 28) { @@ -132,16 +147,18 @@ public function sendRequest($action, $json = false, $expectResponse = false, $me // Decode JSON $response = self::handleResponse($result); - // Check JSON has decoded correctly if ($expectResponse && ($response === null || $response === false )) { + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($err, true)); Error::throwError('uanv', Error::$errors['json'], 503); } // Check the status code exists if (isset($response["httpStatusCode"])) { - if ($response["httpStatusCode"] != 200) { + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($response, true)); Error::throwError( false, $response["message"], @@ -150,21 +167,28 @@ public function sendRequest($action, $json = false, $expectResponse = false, $me $response['description'], $response['customCode'] ); - } } elseif ($expectResponse && $info['http_code'] != 200) { + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($info, true)); // If we expect a result and we have an error Error::throwError('uanv', Error::$errors['json'], 503); } elseif (!$expectResponse) { - if ($info['http_code'] != 200) { + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($result, true)); Error::throwError('apierror', $result, $info['http_code']); } else { $response = true; } } + if ($response['paymentStatus'] != 'SUCCESS' && $response['paymentStatus'] != 'AUTHORIZED') { + $file = (\Yii::$app->basePath . '/archivos/'); + file_put_contents($file . "Request-$transactionId-'worldpay.json", print_r($json, true)); + file_put_contents($file . "ResponseH-$transactionId-worlpay.json", print_r($result, true)); + } return $response; } diff --git a/lib/DeliveryAddress.php b/lib/DeliveryAddress.php old mode 100644 new mode 100755 diff --git a/lib/Error.php b/lib/Error.php old mode 100644 new mode 100755 diff --git a/lib/Order.php b/lib/Order.php old mode 100644 new mode 100755 index 82610a8..89362e0 --- a/lib/Order.php +++ b/lib/Order.php @@ -82,20 +82,27 @@ private static function extractPaymentMethodFromData($data) $paymentMethod = array(); if (isset($data['paymentMethod'])) { $_orderPM = $data['paymentMethod']; - $_name = isset($_orderPM['name']) ? $_orderPM['name'] : ""; - $_expiryMonth = isset($_orderPM['expiryMonth']) ? $_orderPM['expiryMonth'] : ""; - $_expiryYear = isset($_orderPM['expiryYear']) ? $_orderPM['expiryYear'] : ""; - $_cardNumber = isset($_orderPM['cardNumber']) ? $_orderPM['cardNumber'] : ""; - $_cvc = isset($_orderPM['cvc']) ? $_orderPM['cvc'] : ""; + if($_orderPM['type'] === "CSE"){ + $paymentMethod = array( + 'type' =>$_orderPM['type'], + 'encryptedData' =>$_orderPM['encryptedData'] + ); + }else { + $_name = isset($_orderPM['name']) ? $_orderPM['name'] : ""; + $_expiryMonth = isset($_orderPM['expiryMonth']) ? $_orderPM['expiryMonth'] : ""; + $_expiryYear = isset($_orderPM['expiryYear']) ? $_orderPM['expiryYear'] : ""; + $_cardNumber = isset($_orderPM['cardNumber']) ? $_orderPM['cardNumber'] : ""; + $_cvc = isset($_orderPM['cvc']) ? $_orderPM['cvc'] : ""; - $paymentMethod = array( - "type" => "Card", - "name" => $_name, - "expiryMonth" => $_expiryMonth, - "expiryYear" => $_expiryYear, - "cardNumber"=> $_cardNumber, - "cvc"=> $_cvc, - ); + $paymentMethod = array( + "type" => "Card", + "name" => $_name, + "expiryMonth" => $_expiryMonth, + "expiryYear" => $_expiryYear, + "cardNumber" => $_cardNumber, + "cvc" => $_cvc, + ); + } } return $paymentMethod; } diff --git a/lib/OrderService.php b/lib/OrderService.php old mode 100644 new mode 100755 index 0251f79..784626b --- a/lib/OrderService.php +++ b/lib/OrderService.php @@ -3,9 +3,9 @@ class OrderService { - public static function createOrder($order) + public static function createOrder($order, $debug=false) { - return Connection::getInstance()->sendRequest('orders', json_encode($order->toArray()), true); + return Connection::getInstance()->sendRequest('orders', json_encode($order->toArray()), true, 'POST', $debug); } public static function authorize3DSOrder($orderCode, $responseCode) diff --git a/lib/TokenService.php b/lib/TokenService.php old mode 100644 new mode 100755 diff --git a/lib/Utils.php b/lib/Utils.php old mode 100644 new mode 100755 diff --git a/lib/Worldpay.php b/lib/Worldpay.php old mode 100644 new mode 100755 index 5625099..1baa837 --- a/lib/Worldpay.php +++ b/lib/Worldpay.php @@ -102,12 +102,14 @@ public function createApmOrder($order = array()) /** * Create Worldpay order * @param array $order + * @param boolean $debug * @return array Worldpay order response * */ - public function createOrder($order = array()) + public function createOrder($order = array(), $debug=false) { + $myOrder = new Order($order); - $response = OrderService::createOrder($myOrder); + $response = OrderService::createOrder($myOrder, $debug); if (isset($response["orderCode"])) { //success diff --git a/lib/WorldpayException.php b/lib/WorldpayException.php old mode 100644 new mode 100755