diff --git a/src/Message/CreateProfileCardRequest.php b/src/Message/CreateProfileCardRequest.php index f9dfde0..e223b75 100644 --- a/src/Message/CreateProfileCardRequest.php +++ b/src/Message/CreateProfileCardRequest.php @@ -9,11 +9,14 @@ public function getEndpoint() public function getData() { - $data = array(); - $this->getCard()->validate(); + $data = array( + 'comment' => $this->getComment() + ); if ($this->getCard()) { - $data = array( + $this->getCard()->validate(); + + $data['card'] = array( 'number' => $this->getCard()->getNumber(), 'name' => $this->getCard()->getName(), 'expiry_month' => $this->getCard()->getExpiryDate('m'), @@ -22,6 +25,10 @@ public function getData() ); } + if ($this->getToken()) { + $data['token'] = $this->getToken(); + } + return $data; } diff --git a/tests/Message/CreateProfileCardRequestTest.php b/tests/Message/CreateProfileCardRequestTest.php index f59cc32..9e15284 100644 --- a/tests/Message/CreateProfileCardRequestTest.php +++ b/tests/Message/CreateProfileCardRequestTest.php @@ -45,16 +45,35 @@ public function testEndpoint() $this->assertSame('https://www.beanstream.com/api/v1/profiles/' . $this->request->getProfileId(). '/cards', $this->request->getEndpoint()); } + public function testComment() + { + $this->assertSame($this->request, $this->request->setComment('test')); + $this->assertSame('test', $this->request->getComment()); + } + public function testCard() { $card = $this->getValidCard(); $this->assertSame($this->request, $this->request->setCard($card)); $data = $this->request->getData(); - $this->assertSame($card['number'], $data['number']); - $this->assertSame($card['cvv'], $data['cvd']); - $this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['expiry_month']); - $this->assertSame(substr($card['expiryYear'], -2), $data['expiry_year']); - $this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['name']); + $this->assertSame($card['number'], $data['card']['number']); + $this->assertSame($card['cvv'], $data['card']['cvd']); + $this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['card']['expiry_month']); + $this->assertSame(substr($card['expiryYear'], -2), $data['card']['expiry_year']); + $this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['card']['name']); + } + + public function testToken() + { + $token = array( + 'name' => 'token-test-name', + 'code' => 'token-test-code' + ); + + $this->assertSame($this->request, $this->request->setToken($token)); + $this->assertSame($token, $this->request->getToken()); + $data = $this->request->getData(); + $this->assertSame($token, $data['token']); } public function testHttpMethod() diff --git a/tests/Message/UpdateProfileCardRequestTest.php b/tests/Message/UpdateProfileCardRequestTest.php index afb6d35..c6eb3e6 100644 --- a/tests/Message/UpdateProfileCardRequestTest.php +++ b/tests/Message/UpdateProfileCardRequestTest.php @@ -12,6 +12,34 @@ public function setUp() $this->request->initialize(); } + public function testSendSuccess() + { + $this->request->setProfileId('9ba60541d32648B1A3581670123dF2Ef'); + $this->request->setCardId('1'); + $card = $this->getValidCard(); + $this->assertSame($this->request, $this->request->setCard($card)); + $this->setMockHttpResponse('UpdateProfileCardSuccess.txt'); + $response = $this->request->send(); + $this->assertTrue($response->isSuccessful()); + $this->assertSame(1, $response->getCode()); + $this->assertSame('Operation Successful', $response->getMessage()); + $this->assertSame('9ba60541d32648B1A3581670123dF2Ef', $response->getCustomerCode()); + } + + public function testSendError() + { + $this->request->setProfileId('9ba60541d32648B1A3581670123dF2Ef'); + $this->request->setCardId('1'); + $card = $this->getValidCard(); + $this->assertSame($this->request, $this->request->setCard($card)); + $this->setMockHttpResponse('UpdateProfileCardFailure.txt'); + $response = $this->request->send(); + $this->assertFalse($response->isSuccessful()); + $this->assertSame(19, $response->getCode()); + $this->assertSame(3, $response->getCategory()); + $this->assertSame('Customer information failed data validation', $response->getMessage()); + } + public function testEndpoint() { $this->assertSame($this->request, $this->request->setProfileId('1')); @@ -21,10 +49,38 @@ public function testEndpoint() $this->assertSame('https://www.beanstream.com/api/v1/profiles/' . $this->request->getProfileId() . '/cards/' . $this->request->getCardId(), $this->request->getEndpoint()); } + public function testComment() + { + $this->assertSame($this->request, $this->request->setComment('test')); + $this->assertSame('test', $this->request->getComment()); + } + public function testCard() { + $this->request->setProfileId('8F10Ab54FC434b71972cF2E442c0fb4f'); + $this->request->setCardId('1'); $card = $this->getValidCard(); $this->assertSame($this->request, $this->request->setCard($card)); + $data = $this->request->getData(); + $this->assertSame($card['number'], $data['card']['number']); + $this->assertSame($card['cvv'], $data['card']['cvd']); + $this->assertSame(sprintf("%02d", $card['expiryMonth']), $data['card']['expiry_month']); + $this->assertSame(substr($card['expiryYear'], -2), $data['card']['expiry_year']); + $this->assertSame($card['firstName'] . ' ' . $card['lastName'], $data['card']['name']); + } + + public function testToken() + { + $this->request->setProfileId('8F10Ab54FC434b71972cF2E442c0fb4f'); + $this->request->setCardId('1'); + $token = array( + 'name' => 'token-test-name', + 'code' => 'token-test-code' + ); + $this->assertSame($this->request, $this->request->setToken($token)); + $this->assertSame($token, $this->request->getToken()); + $data = $this->request->getData(); + $this->assertSame($token, $data['token']); } public function testHttpMethod() diff --git a/tests/Mock/UpdateProfileCardFailure.txt b/tests/Mock/UpdateProfileCardFailure.txt index e69de29..bf00f23 100644 --- a/tests/Mock/UpdateProfileCardFailure.txt +++ b/tests/Mock/UpdateProfileCardFailure.txt @@ -0,0 +1,10 @@ +HTTP/1.1 400 Bad Request +Content-Type: application/json + +{ + "code": 19, + "category": 3, + "message": "Customer information failed data validation", + "reference": null, + "details": [] +} diff --git a/tests/Mock/UpdateProfileCardSuccess.txt b/tests/Mock/UpdateProfileCardSuccess.txt index 2e52556..dcc19ef 100644 --- a/tests/Mock/UpdateProfileCardSuccess.txt +++ b/tests/Mock/UpdateProfileCardSuccess.txt @@ -11,7 +11,6 @@ Server: Microsoft-IIS/8.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET - { "code": 1, "message": "Operation Successful",