Skip to content

Commit d757804

Browse files
committed
Added RedirectResponseInterface and isPaymentRefused test method
1 parent 50b103b commit d757804

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/Message/Response.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Omnipay\YM\Message;
44

55
use Omnipay\Common\Message\AbstractResponse as OmnipayAbstractResponse;
6+
use Omnipay\Common\Message\RedirectResponseInterface;
67
use Omnipay\Common\Message\RequestInterface;
78

8-
class Response extends OmnipayAbstractResponse {
9+
class Response extends OmnipayAbstractResponse implements RedirectResponseInterface {
910

1011
/**
1112
* Operation is not performed, another request is needed.
@@ -56,6 +57,16 @@ public function inProgress()
5657
return $this->data['status'] == self::IN_PROGRESS;
5758
}
5859

60+
/**
61+
* Get whether the payment was refused.
62+
*
63+
* @return bool
64+
*/
65+
public function isPaymentRefused()
66+
{
67+
return in_array($this->getCode(), array( 'payment_refused', 'authorization_reject' ));
68+
}
69+
5970
/**
6071
* @return string
6172
*/

tests/ExternalGatewayTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ public function testProcessSuccess()
6969

7070
$this->assertTrue($response->isSuccessful());
7171
$this->assertNotEmpty($response->getTransactionReference());
72+
$this->assertFalse($response->isPaymentRefused());
73+
}
74+
75+
public function testProcessRefused()
76+
{
77+
$this->setMockHttpResponse('ProcessPaymentRefused.txt');
78+
79+
$response = $this->gateway->processPayment($this->processOptions)->send();
80+
81+
$this->assertFalse($response->isSuccessful());
82+
$this->assertTrue($response->isPaymentRefused());
7283
}
7384

7485
public function testProcessRedirect()

tests/Message/ResponseTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function testRedirect()
4545
$this->assertEquals('GET', $response->getRedirectMethod());
4646
$this->assertEquals('https://example.com?foo=bar&baz=bax', $response->getRedirectUrl());
4747
$this->assertEquals(null, $response->getRedirectData());
48+
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response->getRedirectResponse());
4849
}
4950

5051
public function testMoneySource()

tests/Mock/ProcessPaymentRefused.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
HTTP/1.1 200 OK
2+
3+
{"status": "refused", "error": "payment_refused"}

0 commit comments

Comments
 (0)