Skip to content

Commit

Permalink
Adding getters to Response object, Adding request send/faulre tests f…
Browse files Browse the repository at this point in the history
…or authorize, purchase, adding tests for Response.
  • Loading branch information
aperdomo committed Mar 24, 2016
1 parent 6445e99 commit 3134714
Show file tree
Hide file tree
Showing 8 changed files with 295 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,34 @@ public function isSuccessful()

public function getTransactionReference()
{
return (isset($this->data['id'])) ? $this->data['id'] : null;
return isset($this->data['id']) ? $this->data['id'] : null;
}

public function getType()
{
return isset($this->data['type']) ? $this->data['type'] : null;
}

public function getOrderNumber()
{
return (isset($this->data['order_number'])) ? $this->data['order_number'] : null;
return isset($this->data['order_number']) ? $this->data['order_number'] : null;
}

public function getMessage()
public function getMessageId()
{
return isset($this->data['message_id']) ? $this->data['message_id'] : null;
}

public function getMessage()
{
return isset($this->data['message']) ? $this->data['message'] : null;
}

public function getAuthCode()
{
return isset($this->data['auth_code']) ? $this->data['auth_code'] : null;
}

public function getCode()
{
return isset($this->data['code']) ? $this->data['code'] : null;
Expand All @@ -34,4 +49,14 @@ public function getCard()
{
return isset($this->data['card']) ? $this->data['card'] : null;
}

public function getReference()
{
return isset($this->data['reference']) ? $this->data['reference'] : null;
}

public function getCategory()
{
return isset($this->data['category']) ? $this->data['category'] : null;
}
}
41 changes: 41 additions & 0 deletions tests/Message/AuthorizeRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,47 @@ public function testEndpoint()
$this->assertSame('https://www.beanstream.com/api/v1/payments', $this->request->getEndpoint());
}

public function testSendSuccess()
{
$this->request->setAmount('10.00');
$this->setMockHttpResponse('AuthorizeSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('1000001', $response->getTransactionReference());
$this->assertSame('1', $response->getOrderNumber());
$this->assertSame('Approved', $response->getMessage());
$this->assertSame('1', $response->getMessageId());
$this->assertSame('TEST', $response->getAuthCode());
$this->assertSame('PA', $response->getType());
$this->assertNull($response->getCode());
$responseCard = $response->getCard();
$this->assertNotEmpty($responseCard);
$this->assertSame('VI', $responseCard['card_type']);
$this->assertSame('1234', $responseCard['last_four']);
$this->assertSame(0, $responseCard['cvd_match']);
$this->assertSame(0, $responseCard['address_match']);
$this->assertSame(0, $responseCard['postal_result']);
}

public function testSendError()
{
$this->request->setAmount('10.00');
$this->setMockHttpResponse('AuthorizeFailure.txt');
$response = $this->request->send();
$this->assertSame(49, $response->getCode());
$this->assertSame(3, $response->getCategory());
$this->assertSame('Invalid transaction request string', $response->getMessage());
$this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getOrderNumber());
$this->assertNull($response->getType());
$this->assertNull($response->getMessageId());
$this->assertNull($response->getAuthCode());
$responseCard = $response->getCard();
$this->assertEmpty($responseCard);
}

public function testMerchantId()
{
$this->assertSame($this->request, $this->request->setMerchantId('123'));
Expand Down
41 changes: 41 additions & 0 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,47 @@ public function testEndpoint()
$this->assertSame('https://www.beanstream.com/api/v1/payments', $this->request->getEndpoint());
}

public function testSendSuccess()
{
$this->request->setAmount('10.00');
$this->setMockHttpResponse('PurchaseSuccess.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('1000001', $response->getTransactionReference());
$this->assertSame('1', $response->getOrderNumber());
$this->assertSame('Approved', $response->getMessage());
$this->assertSame('1', $response->getMessageId());
$this->assertSame('TEST', $response->getAuthCode());
$this->assertSame('P', $response->getType());
$this->assertNull($response->getCode());
$responseCard = $response->getCard();
$this->assertNotEmpty($responseCard);
$this->assertSame('VI', $responseCard['card_type']);
$this->assertSame('1234', $responseCard['last_four']);
$this->assertSame(0, $responseCard['cvd_match']);
$this->assertSame(0, $responseCard['address_match']);
$this->assertSame(0, $responseCard['postal_result']);
}

public function testSendError()
{
$this->request->setAmount('10.00');
$this->setMockHttpResponse('PurchaseFailure.txt');
$response = $this->request->send();
$this->assertSame(49, $response->getCode());
$this->assertSame(3, $response->getCategory());
$this->assertSame('Invalid transaction request string', $response->getMessage());
$this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getOrderNumber());
$this->assertNull($response->getType());
$this->assertNull($response->getMessageId());
$this->assertNull($response->getAuthCode());
$responseCard = $response->getCard();
$this->assertEmpty($responseCard);
}

public function testMerchantId()
{
$this->assertSame($this->request, $this->request->setMerchantId('123'));
Expand Down
86 changes: 86 additions & 0 deletions tests/Message/ResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Omnipay\Beanstream\Message;

use Omnipay\Tests\TestCase;

class ResponseTest extends TestCase
{
public function testPurchaseSuccess()
{
$httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt');
$response = new Response($this->getMockRequest(), $httpResponse->json());
$this->assertTrue($response->isSuccessful());
$this->assertSame('1000001', $response->getTransactionReference());
$this->assertSame('1', $response->getOrderNumber());
$this->assertSame('Approved', $response->getMessage());
$this->assertSame('1', $response->getMessageId());
$this->assertSame('TEST', $response->getAuthCode());
$this->assertSame('P', $response->getType());
$this->assertNull($response->getCode());
$responseCard = $response->getCard();
$this->assertNotEmpty($responseCard);
$this->assertSame('VI', $responseCard['card_type']);
$this->assertSame('1234', $responseCard['last_four']);
$this->assertSame(0, $responseCard['cvd_match']);
$this->assertSame(0, $responseCard['address_match']);
$this->assertSame(0, $responseCard['postal_result']);
}

public function testPurchaseFailure()
{
$httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt');
$response = new Response($this->getMockRequest(), $httpResponse->json());
$this->assertSame(49, $response->getCode());
$this->assertSame(3, $response->getCategory());
$this->assertSame('Invalid transaction request string', $response->getMessage());
$this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getOrderNumber());
$this->assertNull($response->getType());
$this->assertNull($response->getMessageId());
$this->assertNull($response->getAuthCode());
$responseCard = $response->getCard();
$this->assertEmpty($responseCard);
}

public function testAuthorizeSuccess()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeSuccess.txt');
$response = new Response($this->getMockRequest(), $httpResponse->json());
$this->assertTrue($response->isSuccessful());
$this->assertSame('1000001', $response->getTransactionReference());
$this->assertSame('1', $response->getOrderNumber());
$this->assertSame('Approved', $response->getMessage());
$this->assertSame('1', $response->getMessageId());
$this->assertSame('TEST', $response->getAuthCode());
$this->assertSame('PA', $response->getType());
$this->assertNull($response->getCode());
$responseCard = $response->getCard();
$this->assertNotEmpty($responseCard);
$this->assertSame('VI', $responseCard['card_type']);
$this->assertSame('1234', $responseCard['last_four']);
$this->assertSame(0, $responseCard['cvd_match']);
$this->assertSame(0, $responseCard['address_match']);
$this->assertSame(0, $responseCard['postal_result']);
}

public function testAuthorizeFailure()
{
$httpResponse = $this->getMockHttpResponse('AuthorizeFailure.txt');
$response = new Response($this->getMockRequest(), $httpResponse->json());
$this->assertSame(49, $response->getCode());
$this->assertSame(3, $response->getCategory());
$this->assertSame('Invalid transaction request string', $response->getMessage());
$this->assertSame('https://www.beanstream.com/docs/errors#49', $response->getReference());
$this->assertFalse($response->isSuccessful());
$this->assertNull($response->getTransactionReference());
$this->assertNull($response->getOrderNumber());
$this->assertNull($response->getType());
$this->assertNull($response->getMessageId());
$this->assertNull($response->getAuthCode());
$responseCard = $response->getCard();
$this->assertEmpty($responseCard);
}
}
9 changes: 9 additions & 0 deletions tests/Mock/AuthorizeFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"code":49,
"category":3,
"message":"Invalid transaction request string",
"reference":"https://www.beanstream.com/docs/errors#49"
}
38 changes: 38 additions & 0 deletions tests/Mock/AuthorizeSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HTTP/1.1 200 OK
Access-Control-Allow-Headers: accept, origin, content-type
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Content-Length: 477
Content-Type: application/json; charset=utf-8
Date: Thu, 24 Mar 2016 18:04:30 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

{
"id": "1000001",
"approved": "1",
"message_id": "1",
"message": "Approved",
"auth_code": "TEST",
"created": "2016-03-24T11:04:30",
"order_number": "1",
"type": "PA",
"payment_method": "CC",
"card": {
"card_type": "VI",
"last_four": "1234",
"cvd_match": 0,
"address_match": 0,
"postal_result": 0
},
"links": [
{
"rel": "complete",
"href": "https://www.beanstream.com/api/v1/payments/1000001/completions",
"method": "POST"
}
]
}
9 changes: 9 additions & 0 deletions tests/Mock/PurchaseFailure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"code":49,
"category":3,
"message":"Invalid transaction request string",
"reference":"https://www.beanstream.com/docs/errors#49"
}
43 changes: 43 additions & 0 deletions tests/Mock/PurchaseSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
HTTP/1.1 200 OK
Access-Control-Allow-Headers: accept, origin, content-type
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Content-Length: 477
Content-Type: application/json; charset=utf-8
Date: Thu, 24 Mar 2016 18:04:30 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/8.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

{
"id": "1000001",
"approved": "1",
"message_id": "1",
"message": "Approved",
"auth_code": "TEST",
"created": "2016-03-24T11:04:30",
"order_number": "1",
"type": "P",
"payment_method": "CC",
"card": {
"card_type": "VI",
"last_four": "1234",
"cvd_match": 0,
"address_match": 0,
"postal_result": 0
},
"links": [
{
"rel": "void",
"href": "https://www.beanstream.com/api/v1/payments/1000001/void",
"method": "POST"
},
{
"rel": "return",
"href": "https://www.beanstream.com/api/v1/payments/1000001/returns",
"method": "POST"
}
]
}

0 comments on commit 3134714

Please sign in to comment.