Skip to content

Commit

Permalink
paranoiaproject#5 - 3D Secure desteği eklendi.
Browse files Browse the repository at this point in the history
  • Loading branch information
fg committed Aug 20, 2015
1 parent 67f4822 commit 0809df0
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 17 deletions.
26 changes: 24 additions & 2 deletions src/Payu/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -103,4 +109,20 @@ public function getSecretKey()
{
return $this->secretKey;
}
}

/**
* @return string
*/
public function getPaymentReturnPointUrl()
{
return $this->paymentReturnPointUrl;
}

/**
* @param string $paymentReturnPointUrl
*/
public function setPaymentReturnPointUrl($paymentReturnPointUrl)
{
$this->paymentReturnPointUrl = $paymentReturnPointUrl;
}
}
36 changes: 30 additions & 6 deletions src/Payu/Parser/PaymentResponseParser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Payu\Parser;

use Guzzle\Http\EntityBody;
use Payu\Exception\BadResponseError;
use Payu\Response\PaymentResponse;
use Payu\Response\ResponseAbstract;
Expand All @@ -10,23 +11,46 @@
class PaymentResponseParser implements ParserInterface
{
/**
* @param string $rawData
* @param EntityBody|string|array $rawData
* @return PaymentResponse|ResponseAbstract
* @throws \Payu\Exception\BadResponseError
*/
public function parse($rawData)
{
try {
$xml = new SimpleXMLElement($rawData);
$xml = ($rawData instanceof EntityBody || is_string($rawData)) ?
new SimpleXMLElement($rawData) : (object) $rawData;
} catch(Exception $e) {
throw new BadResponseError('Unexpected response received from provider. Response: ' . $rawData);
}

$status = (string) $xml->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;
}
}
60 changes: 53 additions & 7 deletions src/Payu/Response/PaymentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
5 changes: 3 additions & 2 deletions src/Payu/Response/ResponseAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Payu/Serializer/PaymentRequestSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);

Expand Down Expand Up @@ -111,6 +112,8 @@ public function serialize()
$this->serializeBasket()
);



$filteredData = array_filter($concatenatedData);
$filteredData['MERCHANT'] = $this->configuration->getMerchantId();
$filteredData['ORDER_HASH'] = $this->calculateHash($filteredData);
Expand Down

0 comments on commit 0809df0

Please sign in to comment.