5 use Omnipay\Tests\TestCase;
7 class RestResponseTest
extends TestCase
11 $httpResponse = $this->getMockHttpResponse(
'RestPurchaseSuccess.txt');
12 $data = json_decode($httpResponse->getBody()->getContents(),
true);
13 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
15 $this->assertTrue($response->isSuccessful());
16 $this->assertSame(
'44E89981F8714392Y', $response->getTransactionReference());
17 $this->assertNull($response->getMessage());
22 $httpResponse = $this->getMockHttpResponse(
'RestPurchaseFailure.txt');
23 $data = json_decode($httpResponse->getBody()->getContents(),
true);
24 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
26 $this->assertFalse($response->isSuccessful());
27 $this->assertNull($response->getTransactionReference());
28 $this->assertSame(
'Invalid request - see details', $response->getMessage());
33 $httpResponse = $this->getMockHttpResponse(
'RestCompletePurchaseSuccess.txt');
34 $data = json_decode($httpResponse->getBody()->getContents(),
true);
36 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
38 $this->assertTrue($response->isSuccessful());
39 $this->assertSame(
'9EA05739TH369572R', $response->getTransactionReference());
40 $this->assertNull($response->getMessage());
45 $httpResponse = $this->getMockHttpResponse(
'RestCompletePurchaseFailure.txt');
46 $data = json_decode($httpResponse->getBody()->getContents(),
true);
48 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
50 $this->assertFalse($response->isSuccessful());
51 $this->assertNull($response->getTransactionReference());
52 $this->assertSame(
'This request is invalid due to the current state of the payment', $response->getMessage());
57 $httpResponse = $this->getMockHttpResponse(
'RestTokenFailure.txt');
58 $data = json_decode($httpResponse->getBody()->getContents(),
true);
60 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
62 $this->assertFalse($response->isSuccessful());
63 $this->assertSame(
'Client secret does not match for this client', $response->getMessage());
68 $httpResponse = $this->getMockHttpResponse(
'RestAuthorizationSuccess.txt');
69 $data = json_decode($httpResponse->getBody()->getContents(),
true);
71 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
73 $this->assertTrue($response->isSuccessful());
74 $this->assertSame(
'58N7596879166930B', $response->getTransactionReference());
75 $this->assertNull($response->getMessage());
80 $httpResponse = $this->getMockHttpResponse(
'RestCreateCardSuccess.txt');
81 $data = json_decode($httpResponse->getBody()->getContents(),
true);
83 $response =
new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
85 $this->assertTrue($response->isSuccessful());
86 $this->assertSame(
'CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());
87 $this->assertNull($response->getMessage());