Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified lib/APMOrder.php
100644 → 100755
Empty file.
Empty file modified lib/AbstractAddress.php
100644 → 100755
Empty file.
10 changes: 8 additions & 2 deletions lib/AbstractOrder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
Empty file modified lib/BillingAddress.php
100644 → 100755
Empty file.
46 changes: 35 additions & 11 deletions lib/Connection.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Worldpay;

use yii\helpers\VarDumper;

class Connection {

private $service_key = "";
Expand All @@ -14,7 +16,7 @@ private function __construct()

}

/**
/**
* Call this method to get singleton
*
* @return Connection
Expand Down Expand Up @@ -57,30 +59,30 @@ private function getBaseClientUserAgent()
{
$arch = (bool)((1<<32)-1) ? 'x64' : 'x86';
$clientUA = 'os.name=' . php_uname('s') . ';os.version=' . php_uname('r') . ';os.arch=' .
$arch . ';lang.version='. phpversion() . ';lib.version=2.1.0;' . 'api.version=v1;lang=php;owner=worldpay';
$arch . ';lang.version='. phpversion() . ';lib.version=2.1.0;' . 'api.version=v1;lang=php;owner=worldpay';
return $clientUA;
}

public function setClientUserAgentWithPluginData($pluginName, $pluginVersion)
{
$this->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
* @param bool $expectResponse
* @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);
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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"],
Expand All @@ -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;
}
Expand Down
Empty file modified lib/DeliveryAddress.php
100644 → 100755
Empty file.
Empty file modified lib/Error.php
100644 → 100755
Empty file.
33 changes: 20 additions & 13 deletions lib/Order.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/OrderService.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Empty file modified lib/TokenService.php
100644 → 100755
Empty file.
Empty file modified lib/Utils.php
100644 → 100755
Empty file.
6 changes: 4 additions & 2 deletions lib/Worldpay.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file modified lib/WorldpayException.php
100644 → 100755
Empty file.