Skip to content

Added specifying of Success/Fail redirect method #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand Down