From 3f70a064709426f83e85310bbda6021c2a2d4a46 Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 11:52:25 -0500 Subject: [PATCH 01/10] fix: nest CreditCard data under _card_ key see _Add card_ and _Update card_ under Profiles section at link (https://dev.na.bambora.com/docs/references/payment_APIs/v1-0-5) --- src/Message/CreateProfileCardRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/CreateProfileCardRequest.php b/src/Message/CreateProfileCardRequest.php index f9dfde0..538caad 100644 --- a/src/Message/CreateProfileCardRequest.php +++ b/src/Message/CreateProfileCardRequest.php @@ -13,7 +13,7 @@ public function getData() $this->getCard()->validate(); if ($this->getCard()) { - $data = array( + $data['card'] = array( 'number' => $this->getCard()->getNumber(), 'name' => $this->getCard()->getName(), 'expiry_month' => $this->getCard()->getExpiryDate('m'), From 68e96ecd0a9fd36dd5b423d7b2db0ef370a26eb1 Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 11:53:56 -0500 Subject: [PATCH 02/10] fix: validate card data if there's a card --- src/Message/CreateProfileCardRequest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Message/CreateProfileCardRequest.php b/src/Message/CreateProfileCardRequest.php index 538caad..91eb818 100644 --- a/src/Message/CreateProfileCardRequest.php +++ b/src/Message/CreateProfileCardRequest.php @@ -10,9 +10,10 @@ public function getEndpoint() public function getData() { $data = array(); - $this->getCard()->validate(); if ($this->getCard()) { + $this->getCard()->validate(); + $data['card'] = array( 'number' => $this->getCard()->getNumber(), 'name' => $this->getCard()->getName(), From 5feef9a2590a1eae90edab7625e0b37975ceb89e Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 11:55:34 -0500 Subject: [PATCH 03/10] feat: send token if specified/exists --- src/Message/CreateProfileCardRequest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Message/CreateProfileCardRequest.php b/src/Message/CreateProfileCardRequest.php index 91eb818..50f1112 100644 --- a/src/Message/CreateProfileCardRequest.php +++ b/src/Message/CreateProfileCardRequest.php @@ -23,6 +23,10 @@ public function getData() ); } + if ($this->getToken()) { + $data['token'] = $this->getToken(); + } + return $data; } From 885269c18ed3ef2361d746ea588b7526f4ef4fc8 Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 11:56:09 -0500 Subject: [PATCH 04/10] feat: include comment --- src/Message/CreateProfileCardRequest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Message/CreateProfileCardRequest.php b/src/Message/CreateProfileCardRequest.php index 50f1112..e223b75 100644 --- a/src/Message/CreateProfileCardRequest.php +++ b/src/Message/CreateProfileCardRequest.php @@ -9,7 +9,9 @@ public function getEndpoint() public function getData() { - $data = array(); + $data = array( + 'comment' => $this->getComment() + ); if ($this->getCard()) { $this->getCard()->validate(); From d24c4a43eb9fb1a8986910d78ef34b26ac53900b Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 13:14:22 -0500 Subject: [PATCH 05/10] fix: update test to check for nested value --- tests/Message/CreateProfileCardRequestTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Message/CreateProfileCardRequestTest.php b/tests/Message/CreateProfileCardRequestTest.php index f59cc32..73cfe7a 100644 --- a/tests/Message/CreateProfileCardRequestTest.php +++ b/tests/Message/CreateProfileCardRequestTest.php @@ -50,11 +50,11 @@ 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 testHttpMethod() From 471137ccaca744944f3e1550f58d0928088dc887 Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 13:16:04 -0500 Subject: [PATCH 06/10] feat: add successful UpdateProfileCardRequest test --- tests/Message/UpdateProfileCardRequestTest.php | 14 ++++++++++++++ tests/Mock/UpdateProfileCardSuccess.txt | 1 - 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/Message/UpdateProfileCardRequestTest.php b/tests/Message/UpdateProfileCardRequestTest.php index afb6d35..40d0ae3 100644 --- a/tests/Message/UpdateProfileCardRequestTest.php +++ b/tests/Message/UpdateProfileCardRequestTest.php @@ -12,6 +12,20 @@ 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 testEndpoint() { $this->assertSame($this->request, $this->request->setProfileId('1')); 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", From df510ebe7bd3ca5f37d16c06a0092a4efab2ef0b Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 13:16:47 -0500 Subject: [PATCH 07/10] feat: add failed UpdateProfileCardRequest test --- tests/Message/UpdateProfileCardRequestTest.php | 14 ++++++++++++++ tests/Mock/UpdateProfileCardFailure.txt | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/tests/Message/UpdateProfileCardRequestTest.php b/tests/Message/UpdateProfileCardRequestTest.php index 40d0ae3..a35915a 100644 --- a/tests/Message/UpdateProfileCardRequestTest.php +++ b/tests/Message/UpdateProfileCardRequestTest.php @@ -26,6 +26,20 @@ public function testSendSuccess() $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')); 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": [] +} From 6fc2a0d9938cd4829b60441ab9fc2ac5e9be365e Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 13:19:57 -0500 Subject: [PATCH 08/10] fix: UpdateProfileCardRequest's card test fails on profile & cardId --- tests/Message/UpdateProfileCardRequestTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Message/UpdateProfileCardRequestTest.php b/tests/Message/UpdateProfileCardRequestTest.php index a35915a..011e6c8 100644 --- a/tests/Message/UpdateProfileCardRequestTest.php +++ b/tests/Message/UpdateProfileCardRequestTest.php @@ -51,8 +51,16 @@ public function testEndpoint() 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 testHttpMethod() From 0adae701cb97949c16f6be4ac01fa0869086edb7 Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 13:20:19 -0500 Subject: [PATCH 09/10] feat: add testing for comment --- tests/Message/CreateProfileCardRequestTest.php | 6 ++++++ tests/Message/UpdateProfileCardRequestTest.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/Message/CreateProfileCardRequestTest.php b/tests/Message/CreateProfileCardRequestTest.php index 73cfe7a..f0096c6 100644 --- a/tests/Message/CreateProfileCardRequestTest.php +++ b/tests/Message/CreateProfileCardRequestTest.php @@ -45,6 +45,12 @@ 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(); diff --git a/tests/Message/UpdateProfileCardRequestTest.php b/tests/Message/UpdateProfileCardRequestTest.php index 011e6c8..10941fd 100644 --- a/tests/Message/UpdateProfileCardRequestTest.php +++ b/tests/Message/UpdateProfileCardRequestTest.php @@ -49,6 +49,12 @@ 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'); From 30631946e624b63711357a9062f101e48840de35 Mon Sep 17 00:00:00 2001 From: Tymotheos Szulc Date: Tue, 7 Jan 2020 13:20:35 -0500 Subject: [PATCH 10/10] feat: add testing for token --- tests/Message/CreateProfileCardRequestTest.php | 13 +++++++++++++ tests/Message/UpdateProfileCardRequestTest.php | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/Message/CreateProfileCardRequestTest.php b/tests/Message/CreateProfileCardRequestTest.php index f0096c6..9e15284 100644 --- a/tests/Message/CreateProfileCardRequestTest.php +++ b/tests/Message/CreateProfileCardRequestTest.php @@ -63,6 +63,19 @@ public function testCard() $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() { $this->assertSame('POST', $this->request->getHttpMethod()); diff --git a/tests/Message/UpdateProfileCardRequestTest.php b/tests/Message/UpdateProfileCardRequestTest.php index 10941fd..c6eb3e6 100644 --- a/tests/Message/UpdateProfileCardRequestTest.php +++ b/tests/Message/UpdateProfileCardRequestTest.php @@ -69,6 +69,20 @@ public function testCard() $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() { $this->assertSame('PUT', $this->request->getHttpMethod());