Open Journal Systems  3.3.0
vendor/omnipay/paypal/tests/Message/RestResponseTest.php
1 <?php
2 
3 namespace Omnipay\PayPal\Message;
4 
5 use Omnipay\Tests\TestCase;
6 
7 class RestResponseTest extends TestCase
8 {
9  public function testPurchaseSuccess()
10  {
11  $httpResponse = $this->getMockHttpResponse('RestPurchaseSuccess.txt');
12  $data = json_decode($httpResponse->getBody()->getContents(), true);
13  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
14 
15  $this->assertTrue($response->isSuccessful());
16  $this->assertSame('44E89981F8714392Y', $response->getTransactionReference());
17  $this->assertNull($response->getMessage());
18  }
19 
20  public function testPurchaseFailure()
21  {
22  $httpResponse = $this->getMockHttpResponse('RestPurchaseFailure.txt');
23  $data = json_decode($httpResponse->getBody()->getContents(), true);
24  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
25 
26  $this->assertFalse($response->isSuccessful());
27  $this->assertNull($response->getTransactionReference());
28  $this->assertSame('Invalid request - see details', $response->getMessage());
29  }
30 
31  public function testCompletePurchaseSuccess()
32  {
33  $httpResponse = $this->getMockHttpResponse('RestCompletePurchaseSuccess.txt');
34  $data = json_decode($httpResponse->getBody()->getContents(), true);
35 
36  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
37 
38  $this->assertTrue($response->isSuccessful());
39  $this->assertSame('9EA05739TH369572R', $response->getTransactionReference());
40  $this->assertNull($response->getMessage());
41  }
42 
43  public function testCompletePurchaseFailure()
44  {
45  $httpResponse = $this->getMockHttpResponse('RestCompletePurchaseFailure.txt');
46  $data = json_decode($httpResponse->getBody()->getContents(), true);
47 
48  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
49 
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());
53  }
54 
55  public function testTokenFailure()
56  {
57  $httpResponse = $this->getMockHttpResponse('RestTokenFailure.txt');
58  $data = json_decode($httpResponse->getBody()->getContents(), true);
59 
60  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
61 
62  $this->assertFalse($response->isSuccessful());
63  $this->assertSame('Client secret does not match for this client', $response->getMessage());
64  }
65 
66  public function testAuthorizeSuccess()
67  {
68  $httpResponse = $this->getMockHttpResponse('RestAuthorizationSuccess.txt');
69  $data = json_decode($httpResponse->getBody()->getContents(), true);
70 
71  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
72 
73  $this->assertTrue($response->isSuccessful());
74  $this->assertSame('58N7596879166930B', $response->getTransactionReference());
75  $this->assertNull($response->getMessage());
76  }
77 
78  public function testCreateCardSuccess()
79  {
80  $httpResponse = $this->getMockHttpResponse('RestCreateCardSuccess.txt');
81  $data = json_decode($httpResponse->getBody()->getContents(), true);
82 
83  $response = new RestResponse($this->getMockRequest(), $data, $httpResponse->getStatusCode());
84 
85  $this->assertTrue($response->isSuccessful());
86  $this->assertSame('CARD-70E78145XN686604FKO3L6OQ', $response->getCardReference());
87  $this->assertNull($response->getMessage());
88  }
89 }
Omnipay\PayPal\Message\RestResponseTest\testCreateCardSuccess
testCreateCardSuccess()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:78
Omnipay\PayPal\Message\RestResponseTest\testAuthorizeSuccess
testAuthorizeSuccess()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:66
Omnipay\PayPal\Message\RestResponseTest\testPurchaseFailure
testPurchaseFailure()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:20
Omnipay\PayPal\Message\RestResponseTest\testPurchaseSuccess
testPurchaseSuccess()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:9
Omnipay\PayPal\Message\RestResponseTest\testCompletePurchaseSuccess
testCompletePurchaseSuccess()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:31
Omnipay\PayPal\Message\RestResponse
Definition: lib/vendor/omnipay/paypal/src/Message/RestResponse.php:14
Omnipay\PayPal\Message\RestResponseTest\testCompletePurchaseFailure
testCompletePurchaseFailure()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:43
Omnipay\PayPal\Message\RestResponseTest\testTokenFailure
testTokenFailure()
Definition: vendor/omnipay/paypal/tests/Message/RestResponseTest.php:55
Omnipay\PayPal\Message
Definition: lib/vendor/omnipay/paypal/src/Message/AbstractRequest.php:6