Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Jun 16, 2020
1 parent fdd0f87 commit 2748d03
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ public function getData()
public function sendData($data)
{
try {
$response = $this->httpClient->request('POST', $this->getApiEndpoint(), $this->getRequestHeaders(), json_encode($data));
$responseData = json_decode((string)$response->getBody(), true);
$response = $this->sendRequest('POST', $this->getApiEndpoint(), $data);
} catch (\Exception $e) {
throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e);
}

return $this->response = new RefundResponse($this, $responseData);
return $this->response = new RefundResponse($this, $response);
}
}
12 changes: 9 additions & 3 deletions src/Message/RefundResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ class RefundResponse extends AbstractResponse

public function isSuccessful()
{

if (isset($this->data['data']) && $transaction = $this->data['data']['transaction']) {
if (isset($transaction['status']) && $transaction['status'] == 'reversed') {
return true;
}
}

return false;
}

Expand Down Expand Up @@ -38,9 +45,8 @@ public function getCode()
public function getTransactionReference()
{
if (isset($this->data['data']) && $data = $this->data['data']) {
if(isset($data['transaction']) && $transaction = $data['transaction'])
{
return $transaction['id'];
if (isset($data['transaction']) && $transaction = $data['transaction']) {
return $transaction['reference'];
}
}

Expand Down
18 changes: 17 additions & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class GatewayTest extends GatewayTestCase
/** @var Gateway */
protected $gateway;

/** @var array */
protected $options;

/**
*
*/
public function setUp()
{
parent::setUp();
Expand All @@ -25,6 +31,9 @@ public function setUp()
];
}

/**
*
*/
public function testPurchase()
{
$this->setMockHttpResponse('PurchaseSuccess.txt');
Expand All @@ -36,10 +45,17 @@ public function testPurchase()
$response = $this->gateway->purchase($options)->send();

$this->assertTrue($response->isRedirect(), 'Purchase response is a redirect');
$this->assertEquals(static::PURCHASE_REFERENCE, $response->getTransactionReference(), 'Reference is as we gave it.');
$this->assertEquals(
static::PURCHASE_REFERENCE,
$response->getTransactionReference(),
'Reference is as we gave it.'
);
$this->assertEquals('Authorization URL created', $response->getMessage());
}

/**
*
*/
public function testRefund()
{
$this->setMockHttpResponse('RefundSuccess.txt');
Expand Down

0 comments on commit 2748d03

Please sign in to comment.