diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 52772d3..ccf4555 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 $methodsTable = array( + '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::$methodsTable[$method]) ? self::$methodsTable[$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(), ); } 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()