From 5e0fac27d974c8e189d70ef5d47a418514f97d08 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Fri, 11 Dec 2015 15:41:57 +0000 Subject: [PATCH 1/4] Success/Fail redirect method added --- src/Message/AbstractRequest.php | 68 +++++++++++++++++++++++++++++++++ src/Message/PurchaseRequest.php | 4 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 52772d3..ebf05c5 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -107,6 +107,74 @@ public function setSecretKey($value) return $this->setParameter('secretKey', $value); } + /** + * Get the return method. + * + * @return string return method + */ + public function getReturnMethod() + { + return $this->formatMethod($this->getParameter('returnMethod')); + } + + /** + * Set the return method. + * + * @param string $value return method + * + * @return self + */ + public function setReturnMethod($value) + { + return $this->setParameter('returnMethod', $value); + } + + /** + * Get the cancel method. + * + * @return string cancel method + */ + public function getCancelMethod() + { + return $this->formatMethod($this->getParameter('cancelMethod')); + } + + /** + * Set the cancel method. + * + * @param string $value cancel method + * + * @return self + */ + public function setCancelMethod($value) + { + return $this->setParameter('cancelMethod', $value); + } + + /** + * Redirect method conversion table. + */ + private static $_methods = [ + '1' => '1', + '2' => '2', + 'GET' => '0', + 'POST' => '1', + 'LINK' => '2', + ]; + + /** + * Converts redirect method to WebMoney code: 0, 1 or 2. + * + * @param string $method + * + * @return string + */ + public function formatMethod($method) + { + $method = strtoupper((string)$method); + return isset(self::$_methods[$method]) ? self::$_methods[$method] : '0'; + } + /** * Get the SSL file. * diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index bf5766b..809a20b 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -39,9 +39,9 @@ public function getData() 'LMI_SIM_MODE' => $this->getTestMode() ? '2' : '0', 'LMI_RESULT_URL' => $this->getNotifyUrl(), 'LMI_SUCCESS_URL' => $this->getReturnUrl(), - 'LMI_SUCCESS_METHOD' => '0', + 'LMI_SUCCESS_METHOD' => $this->getReturnMethod(), 'LMI_FAIL_URL' => $this->getCancelUrl(), - 'LMI_FAIL_METHOD' => '0', + 'LMI_FAIL_METHOD' => $this->getCancelMethod(), ); } From 2bd04f8304970e6b06fc87c944521d7865952567 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Fri, 11 Dec 2015 16:09:01 +0000 Subject: [PATCH 2/4] fixed `_methods` to `methodsTable` --- src/Message/AbstractRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index ebf05c5..f8ca9a0 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -154,7 +154,7 @@ public function setCancelMethod($value) /** * Redirect method conversion table. */ - private static $_methods = [ + private static $methodsTable = [ '1' => '1', '2' => '2', 'GET' => '0', @@ -172,7 +172,7 @@ public function setCancelMethod($value) public function formatMethod($method) { $method = strtoupper((string)$method); - return isset(self::$_methods[$method]) ? self::$_methods[$method] : '0'; + return isset(self::$methodsTable[$method]) ? self::$methodsTable[$method] : '0'; } /** From 040a016b4e3238e9774be69a8ab178ecf6c8129c Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Fri, 11 Dec 2015 16:14:09 +0000 Subject: [PATCH 3/4] fixed array declaration to old synax --- src/Message/AbstractRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index f8ca9a0..ccf4555 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -154,13 +154,13 @@ public function setCancelMethod($value) /** * Redirect method conversion table. */ - private static $methodsTable = [ + private static $methodsTable = array( '1' => '1', '2' => '2', 'GET' => '0', 'POST' => '1', 'LINK' => '2', - ]; + ); /** * Converts redirect method to WebMoney code: 0, 1 or 2. From 8247652a0698a649c81bc262387e53f3ebda2b70 Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Fri, 11 Dec 2015 16:32:24 +0000 Subject: [PATCH 4/4] Added tests for redirect method --- tests/Message/PurchaseRequestTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Message/PurchaseRequestTest.php b/tests/Message/PurchaseRequestTest.php index 4a12fa7..3fd6dac 100644 --- a/tests/Message/PurchaseRequestTest.php +++ b/tests/Message/PurchaseRequestTest.php @@ -18,6 +18,8 @@ public function setUp() 'returnUrl' => 'https://www.foodstore.com/success', 'cancelUrl' => 'https://www.foodstore.com/failure', 'notifyUrl' => 'https://www.foodstore.com/notify', + 'returnMethod' => 'POST', + 'cancelMethod' => 'link', 'description' => 'Test Transaction', 'transactionId' => '1234567890', 'amount' => '14.65', @@ -48,9 +50,9 @@ public function testGetData() $this->assertSame('2', $data['LMI_SIM_MODE']); $this->assertSame('https://www.foodstore.com/notify', $data['LMI_RESULT_URL']); $this->assertSame('https://www.foodstore.com/success', $data['LMI_SUCCESS_URL']); - $this->assertSame('0', $data['LMI_SUCCESS_METHOD']); + $this->assertSame('1', $data['LMI_SUCCESS_METHOD']); $this->assertSame('https://www.foodstore.com/failure', $data['LMI_FAIL_URL']); - $this->assertSame('0', $data['LMI_FAIL_METHOD']); + $this->assertSame('2', $data['LMI_FAIL_METHOD']); } public function testSendData()