From 663dda8eec900ea7d8ae9f4d08e1188afae96556 Mon Sep 17 00:00:00 2001 From: azizce Date: Wed, 12 Aug 2015 15:40:30 +0300 Subject: [PATCH] 3D Secure Eklendi. --- .gitignore | 3 ++- docs/pesin_satis.md | 19 ++++++++++++++ src/Payu/Configuration.php | 26 ++++++++++++++++++- src/Payu/Parser/PaymentResponseParser.php | 3 ++- src/Payu/Response/PaymentResponse.php | 26 ++++++++++++++++++- src/Payu/Response/ResponseAbstract.php | 1 + .../Serializer/PaymentRequestSerializer.php | 1 + tests/ClientTest.php | 1 + tests/ConfigurationTest.php | 9 ++++++- 9 files changed, 84 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 14f4781..568e287 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea vendor -*.lock \ No newline at end of file +*.lock +**/.DS_Store diff --git a/docs/pesin_satis.md b/docs/pesin_satis.md index 84198a3..296ffa6 100644 --- a/docs/pesin_satis.md +++ b/docs/pesin_satis.md @@ -13,6 +13,7 @@ $configuration = new Configuration(); $configuration->setMerchantId('MY_MERCHANT_01') ->setSecretKey('SECRET_KEY') ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3'); + ->setReturnUrl('http://payu/cs/payu_3dreturn.php'); $client = new Client($configuration); ``` @@ -91,6 +92,15 @@ if($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { echo $response->getTransactionId() */ } else { + /* + // Eğer Kredi Kartı 3D Secure korumalıysa + if (($response->getCode() == ResponseAbstract::SECURE3D)) { + + header("Location:" . $response->getUrl_3ds()); + exit(); + } + */ + /* // Odeme islemi hatali oldu @@ -112,6 +122,7 @@ $configuration = new Configuration(); $configuration->setMerchantId('MY_MERCHANT_01') ->setSecretKey('SECRET_KEY') ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3'); + ->setReturnUrl('http://payu/cs/payu_3dreturn.php'); $client = new Client($configuration); @@ -131,6 +142,14 @@ if($response->getStatus() == ResponseAbstract::STATUS_APPROVED) { echo $response->getTransactionId() */ } else { + /* + // Eğer Kredi Kartı 3D Secure korumalıysa + if (($response->getCode() == ResponseAbstract::SECURE3D)) { + + header("Location:" . $response->getUrl_3ds()); + exit(); + } + */ /* // Odeme islemi hatali oldu diff --git a/src/Payu/Configuration.php b/src/Payu/Configuration.php index d9062a5..e64016a 100644 --- a/src/Payu/Configuration.php +++ b/src/Payu/Configuration.php @@ -18,18 +18,24 @@ class Configuration */ private $paymentEndpointUrl; + /** + * @var string + */ + private $returnUrl; + /** * @var string */ private $loyaltyInquiryEndPointUrl; public function __construct($merchantId = null, $secretKey = null, $paymentEndpointUrl = null, - $loyaltyInquiryEndPointUrl = null) + $loyaltyInquiryEndPointUrl = null, $returnUrl = null) { $this->merchantId = $merchantId; $this->secretKey = $secretKey; $this->paymentEndpointUrl = $paymentEndpointUrl; $this->loyaltyInquiryEndPointUrl = $loyaltyInquiryEndPointUrl; + $this->returnUrl = $returnUrl; } /** @@ -103,4 +109,22 @@ public function getSecretKey() { return $this->secretKey; } + + /** + * @param string $returnUrl + * @return $this + */ + public function setReturnUrl($returnUrl) + { + $this->returnUrl = $returnUrl; + return $this; + } + + /** + * @return string + */ + public function getReturnUrl() + { + return $this->returnUrl; + } } \ No newline at end of file diff --git a/src/Payu/Parser/PaymentResponseParser.php b/src/Payu/Parser/PaymentResponseParser.php index e6a60b5..ad4f314 100644 --- a/src/Payu/Parser/PaymentResponseParser.php +++ b/src/Payu/Parser/PaymentResponseParser.php @@ -24,9 +24,10 @@ public function parse($rawData) $status = (string) $xml->STATUS; $code = (string) $xml->RETURN_CODE; $message = (string) $xml->RETURN_MESSAGE; + $url_3ds = (string) $xml->URL_3DS; $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); + return new PaymentResponse($statusCode, $code, $message, $transactionId, $url_3ds); } } \ No newline at end of file diff --git a/src/Payu/Response/PaymentResponse.php b/src/Payu/Response/PaymentResponse.php index 17d6663..80459a5 100644 --- a/src/Payu/Response/PaymentResponse.php +++ b/src/Payu/Response/PaymentResponse.php @@ -8,6 +8,28 @@ class PaymentResponse extends ResponseAbstract */ protected $transactionId; + /** + * @var string + */ + protected $url_3ds; + + /** + * @param string $url_3ds + * @return $this; + */ + public function setUrl_3ds($url_3ds) + { + $this->url_3ds = $url_3ds; + } + + /** + * @return string + */ + public function getUrl_3ds() + { + return $this->url_3ds; + } + /** * @param string $transactionId * @return $this; @@ -30,10 +52,12 @@ public function getTransactionId() * @param string $code * @param string $message * @param string $transactionId + * @param string $url_3ds */ - public function __construct($status, $code, $message, $transactionId) + public function __construct($status, $code, $message, $transactionId, $url_3ds) { parent::__construct($status, $code, $message); $this->setTransactionId($transactionId); + $this->setUrl_3ds($url_3ds); } } \ No newline at end of file diff --git a/src/Payu/Response/ResponseAbstract.php b/src/Payu/Response/ResponseAbstract.php index 93e01af..8353307 100644 --- a/src/Payu/Response/ResponseAbstract.php +++ b/src/Payu/Response/ResponseAbstract.php @@ -5,6 +5,7 @@ abstract class ResponseAbstract { const STATUS_APPROVED = 200; const STATUS_DECLINED = 500; + const SECURE3D = "3DS_ENROLLED"; /** * @var integer diff --git a/src/Payu/Serializer/PaymentRequestSerializer.php b/src/Payu/Serializer/PaymentRequestSerializer.php index 3f6a473..2a31210 100644 --- a/src/Payu/Serializer/PaymentRequestSerializer.php +++ b/src/Payu/Serializer/PaymentRequestSerializer.php @@ -113,6 +113,7 @@ public function serialize() $filteredData = array_filter($concatenatedData); $filteredData['MERCHANT'] = $this->configuration->getMerchantId(); + $filteredData['BACK_REF'] = $this->configuration->getReturnUrl(); $filteredData['ORDER_HASH'] = $this->calculateHash($filteredData); return $filteredData; diff --git a/tests/ClientTest.php b/tests/ClientTest.php index fd00475..2f43bb2 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -25,6 +25,7 @@ public function setUp() ->setSecretKey('SECRET_KEY') ->setPaymentEndpointUrl('https://secure.payu.com.tr/order/alu/v3') ->setLoyaltyInquiryEndPointUrl('https://secure.payu.com.tr/api/loyalty-points/check'); + ->setReturnUrl('http://payu/cs/payu_3dreturn.php'); $this->configuration = $configuration; $this->client = new Client($configuration); } diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php index 5bf9f7e..ed1f850 100644 --- a/tests/ConfigurationTest.php +++ b/tests/ConfigurationTest.php @@ -11,7 +11,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->configuration = new Configuration('TestMerchantId', 'TestSecretKey', 'TestPaymentEndpointUrl', - 'TestLoyaltyInquiryEndPointUrl'); + 'TestLoyaltyInquiryEndPointUrl', 'Test3DReturnUrl'); } public function testConstructor() { @@ -19,6 +19,7 @@ public function testConstructor() { $this->assertEquals('TestSecretKey', $this->configuration->getSecretKey()); $this->assertEquals('TestPaymentEndpointUrl', $this->configuration->getPaymentEndpointUrl()); $this->assertEquals('TestLoyaltyInquiryEndPointUrl', $this->configuration->getLoyaltyInquiryEndPointUrl()); + $this->assertEquals('Test3DReturnUrl', $this->configuration->getReturnUrl()); } public function testSetMerchantId() { @@ -40,4 +41,10 @@ public function testSetLoyaltyInquiryEndPointUrl() { $this->configuration->setLoyaltyInquiryEndPointUrl('TestLoyaltyInquiryEndPointUrlSetter'); $this->assertEquals('TestLoyaltyInquiryEndPointUrlSetter', $this->configuration->getLoyaltyInquiryEndPointUrl()); } + + public function testSet3DReturnUrl() { + $this->configuration->setReturnUrl('Test3DReturnUrlSetter'); + $this->assertEquals('Test3DReturnUrlSetter', $this->configuration->getReturnUrl()); + } + } \ No newline at end of file