Skip to content

Commit 6620784

Browse files
committed
Update gateway response class.
1 parent 736c3bd commit 6620784

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

src/Message/PurchaseRequest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public function sendData($data)
112112
$document->saveXML()
113113
);
114114

115-
$data = (array) simplexml_load_string($httpResponse->getBody());
116-
117-
return $this->response = new Response($this, $data);
115+
return $this->response = new Response($this, $httpResponse);
118116
}
119117

120118
public function getUserName()

src/Message/Response.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Omnipay\Common\Message\AbstractResponse;
88
use Omnipay\Common\Message\RedirectResponseInterface;
99
use Omnipay\Common\Message\RequestInterface;
10+
use Psr\Http\Message\ResponseInterface;
1011
use Psr\Http\Message\StreamInterface;
1112

1213
/**
@@ -17,26 +18,26 @@
1718
*/
1819
class Response extends AbstractResponse implements RedirectResponseInterface
1920
{
21+
protected $statusCode;
22+
2023
/**
2124
* construct
2225
*
23-
* @param RequestInterface $request
24-
* @param mixed $data
26+
* @param RequestInterface $request
27+
* @param ResponseInterface $response
2528
*
2629
* @throws InvalidResponseException
2730
*/
28-
public function __construct(RequestInterface $request, $data)
31+
public function __construct(RequestInterface $request, ResponseInterface $response)
2932
{
3033
try {
31-
if (is_string($data) || $data instanceof StreamInterface) {
32-
$data = (array) simplexml_load_string((string) $data);
33-
} elseif (!is_array($data)) {
34-
throw new InvalidResponseException();
35-
}
34+
$data = (array) simplexml_load_string((string) $response->getBody());
3635
} catch (Exception $ex) {
3736
throw new InvalidResponseException();
3837
}
3938

39+
$this->statusCode = $response->getStatusCode();
40+
4041
parent::__construct($request, $data);
4142
}
4243

@@ -47,9 +48,7 @@ public function __construct(RequestInterface $request, $data)
4748
*/
4849
public function getCode()
4950
{
50-
return $this->isSuccessful()
51-
? (string) $this->data["Transaction"]->Response->ReasonCode
52-
: parent::getCode(); //$this->data["Transaction"]->AuthCode
51+
return $this->statusCode;
5352
}
5453

5554
/**
@@ -59,7 +58,7 @@ public function getCode()
5958
*/
6059
public function isSuccessful()
6160
{
62-
return (string) $this->data["Transaction"]->Response->Code === '00';
61+
return '00' === (string) $this->data["Transaction"]->Response->Code;
6362
}
6463

6564
/**

tests/Message/PurchaseRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function testGetData()
3131
/*
3232
* See https://bugs.php.net/bug.php?id=29500 for why this is cast to string
3333
*/
34-
$this->assertSame('11.00', (string) $data['Transaction']['Amount']);
3534
$this->assertSame('sales', (string) $data['Transaction']['Type']);
35+
$this->assertSame('1100', (string) $data['Transaction']['Amount']);
3636
$this->assertSame('949', (string) $data['Transaction']['CurrencyCode']);
3737
}
3838
}

tests/Message/RefundRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testGetData()
3838
* See https://bugs.php.net/bug.php?id=29500 for why this is cast to string
3939
*/
4040
$this->assertSame('refund', (string) $data['Transaction']['Type']);
41-
$this->assertSame('11.00', (string) $data['Transaction']['Amount']);
41+
$this->assertSame('1100', (string) $data['Transaction']['Amount']);
4242
$this->assertSame('949', (string) $data['Transaction']['CurrencyCode']);
4343
}
4444
}

tests/Message/ResponseTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ResponseTest extends TestCase
1313
public function testPurchaseSuccess()
1414
{
1515
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
16-
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
16+
$response = new Response($this->getMockRequest(), $httpResponse);
1717

1818
$this->assertTrue($response->isSuccessful());
1919
$this->assertEquals('xxx', $response->getTransactionReference());
@@ -24,7 +24,7 @@ public function testPurchaseSuccess()
2424
public function testPurchaseFailure()
2525
{
2626
$httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt');
27-
$response = new Response($this->getMockRequest(), $httpResponse->getBody());
27+
$response = new Response($this->getMockRequest(), $httpResponse);
2828

2929
$this->assertFalse($response->isSuccessful());
3030
$this->assertSame('', $response->getTransactionReference());
@@ -38,7 +38,7 @@ public function testPurchaseFailure()
3838
// $request = m::mock('\Omnipay\Common\Message\AbstractRequest');
3939
// $request->shouldReceive('getReturnUrl')->once()->andReturn('http://sanalmagaza.org/');
4040
//
41-
// $response = new Response($request, $httpResponse->getBody());
41+
// $response = new Response($request, $httpResponse);
4242
//
4343
// $this->assertTrue($response->isRedirect());
4444
// $this->assertSame('POST', $response->getRedirectMethod());

0 commit comments

Comments
 (0)