diff --git a/src/Payu/Configuration.php b/src/Payu/Configuration.php index d9062a5..e3c16a3 100644 --- a/src/Payu/Configuration.php +++ b/src/Payu/Configuration.php @@ -23,13 +23,19 @@ class Configuration */ private $loyaltyInquiryEndPointUrl; + /** + * @var string + */ + private $paymentReturnPointUrl; + public function __construct($merchantId = null, $secretKey = null, $paymentEndpointUrl = null, - $loyaltyInquiryEndPointUrl = null) + $loyaltyInquiryEndPointUrl = null, $paymentReturnPointUrl = null) { $this->merchantId = $merchantId; $this->secretKey = $secretKey; $this->paymentEndpointUrl = $paymentEndpointUrl; $this->loyaltyInquiryEndPointUrl = $loyaltyInquiryEndPointUrl; + $this->paymentReturnPointUrl = $paymentReturnPointUrl; } /** @@ -103,4 +109,20 @@ public function getSecretKey() { return $this->secretKey; } -} \ No newline at end of file + + /** + * @return string + */ + public function getPaymentReturnPointUrl() + { + return $this->paymentReturnPointUrl; + } + + /** + * @param string $paymentReturnPointUrl + */ + public function setPaymentReturnPointUrl($paymentReturnPointUrl) + { + $this->paymentReturnPointUrl = $paymentReturnPointUrl; + } +} \ No newline at end of file diff --git a/src/Payu/Parser/PaymentResponseParser.php b/src/Payu/Parser/PaymentResponseParser.php index e6a60b5..013f855 100644 --- a/src/Payu/Parser/PaymentResponseParser.php +++ b/src/Payu/Parser/PaymentResponseParser.php @@ -1,6 +1,7 @@ STATUS; $code = (string) $xml->RETURN_CODE; $message = (string) $xml->RETURN_MESSAGE; - $statusCode = $status == 'SUCCESS' && $code == 'AUTHORIZED' ? - ResponseAbstract::STATUS_APPROVED : ResponseAbstract::STATUS_DECLINED; - $transactionId = $statusCode == ResponseAbstract::STATUS_APPROVED ? (string) $xml->REFNO : null; - return new PaymentResponse($statusCode, $code, $message, $transactionId); + $statusCode = $this->getStatusCode($status, $code); + $transactionId = $this->getTransactionId($xml->REFNO, $statusCode); + $hash = isset($xml->HASH) ? (string) $xml->HASH : null; + $url3DS = isset($xml->URL_3DS) ? (string) $xml->URL_3DS : null; + + return new PaymentResponse($statusCode, $code, $message, $transactionId, $hash, $url3DS); + } + + private function getStatusCode($status, $code) { + $statusCode = ResponseAbstract::STATUS_DECLINED; + + if ($status == 'SUCCESS') { + if ($code == 'AUTHORIZED') { + $statusCode = ResponseAbstract::STATUS_APPROVED; + } else if ($code == '3DS_ENROLLED') { + $statusCode = ResponseAbstract::STATUS_UNAUTHORIZED; + } + } + + return $statusCode; + } + + private function getTransactionId($refNo, $statusCode) { + return in_array($statusCode, array(ResponseAbstract::STATUS_APPROVED, ResponseAbstract::STATUS_UNAUTHORIZED)) ? + (string) $refNo : null; } } \ No newline at end of file diff --git a/src/Payu/Response/PaymentResponse.php b/src/Payu/Response/PaymentResponse.php index 17d6663..a701ea3 100644 --- a/src/Payu/Response/PaymentResponse.php +++ b/src/Payu/Response/PaymentResponse.php @@ -8,6 +8,32 @@ class PaymentResponse extends ResponseAbstract */ protected $transactionId; + /** + * @var string + */ + protected $hash; + + /** + * @var string + */ + protected $url3DS; + + /** + * @param integer $status + * @param string $code + * @param string $message + * @param string $transactionId + * @param string $hash + * @param string $url3DS + */ + public function __construct($status, $code, $message, $transactionId, $hash, $url3DS) + { + parent::__construct($status, $code, $message); + $this->setTransactionId($transactionId); + $this->setHash($hash); + $this->setUrl3DS($url3DS); + } + /** * @param string $transactionId * @return $this; @@ -26,14 +52,34 @@ public function getTransactionId() } /** - * @param integer $status - * @param string $code - * @param string $message - * @param string $transactionId + * @return string */ - public function __construct($status, $code, $message, $transactionId) + public function getHash() { - parent::__construct($status, $code, $message); - $this->setTransactionId($transactionId); + return $this->hash; + } + + /** + * @param string $hash + */ + public function setHash($hash) + { + $this->hash = $hash; + } + + /** + * @return string + */ + public function getUrl3DS() + { + return $this->url3DS; + } + + /** + * @param string $url3DS + */ + public function setUrl3DS($url3DS) + { + $this->url3DS = $url3DS; } } \ No newline at end of file diff --git a/src/Payu/Response/ResponseAbstract.php b/src/Payu/Response/ResponseAbstract.php index 93e01af..f1ed2c0 100644 --- a/src/Payu/Response/ResponseAbstract.php +++ b/src/Payu/Response/ResponseAbstract.php @@ -3,8 +3,9 @@ abstract class ResponseAbstract { - const STATUS_APPROVED = 200; - const STATUS_DECLINED = 500; + const STATUS_APPROVED = 200; + const STATUS_UNAUTHORIZED = 401; + const STATUS_DECLINED = 500; /** * @var integer diff --git a/src/Payu/Serializer/PaymentRequestSerializer.php b/src/Payu/Serializer/PaymentRequestSerializer.php index 3f6a473..8d764b5 100644 --- a/src/Payu/Serializer/PaymentRequestSerializer.php +++ b/src/Payu/Serializer/PaymentRequestSerializer.php @@ -18,6 +18,7 @@ private function serializeOrder() 'PRICES_CURRENCY' => $order->getCurrency(), 'SELECTED_INSTALLMENTS_NUMBER' => $order->getInstallment(), 'ORDER_TIMEOUT' => $order->getTimeout(), + 'BACK_REF' => $this->configuration->getPaymentReturnPointUrl(), 'CLIENT_IP' => $order->getClientIp() ); @@ -111,6 +112,8 @@ public function serialize() $this->serializeBasket() ); + + $filteredData = array_filter($concatenatedData); $filteredData['MERCHANT'] = $this->configuration->getMerchantId(); $filteredData['ORDER_HASH'] = $this->calculateHash($filteredData);