diff --git a/src/Message/RefundRequest.php b/src/Message/RefundRequest.php index e48604d..5f15eca 100644 --- a/src/Message/RefundRequest.php +++ b/src/Message/RefundRequest.php @@ -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); } } diff --git a/src/Message/RefundResponse.php b/src/Message/RefundResponse.php index 5e8e1b9..7c95480 100644 --- a/src/Message/RefundResponse.php +++ b/src/Message/RefundResponse.php @@ -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; } @@ -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']; } } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 04eb6d9..4ed4dc4 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -13,6 +13,12 @@ class GatewayTest extends GatewayTestCase /** @var Gateway */ protected $gateway; + /** @var array */ + protected $options; + + /** + * + */ public function setUp() { parent::setUp(); @@ -25,6 +31,9 @@ public function setUp() ]; } + /** + * + */ public function testPurchase() { $this->setMockHttpResponse('PurchaseSuccess.txt'); @@ -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');