From 9f3e0ff68ca39add5ad8e75465cf618d06785ad6 Mon Sep 17 00:00:00 2001 From: Derick Mathew Date: Wed, 8 May 2019 09:57:39 +0530 Subject: [PATCH] CS-3763 showing 'Null' When Accepting a pending order (Charleston Zip-line Adventure) (#21) * CS-3763 showing 'Null' When Accepting a pending order (Charleston Zip-line Adventure) * CS-3763 renamed test * CS-3763 using a constant to check the description length * CS-3763 using a constant to check the description length * CS-3763 using self to use constant --- src/Message/AIMAuthorizeRequest.php | 6 +++++- tests/Message/CIMAuthorizeRequestTest.php | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Message/AIMAuthorizeRequest.php b/src/Message/AIMAuthorizeRequest.php index ba370888..aaafbb10 100644 --- a/src/Message/AIMAuthorizeRequest.php +++ b/src/Message/AIMAuthorizeRequest.php @@ -9,6 +9,7 @@ */ class AIMAuthorizeRequest extends AIMAbstractRequest { + const MAX_DESCRIPTION_LENGTH = 255; protected $action = 'authOnlyTransaction'; public function getData() @@ -52,7 +53,10 @@ protected function addDescription(\SimpleXMLElement $data) /** @var mixed $req */ $req = $data->transactionRequest; - $description = $this->getDescription(); + $description = trim($this->getDescription()); + if (strlen($description) > self::MAX_DESCRIPTION_LENGTH) { + $description = substr($description, 0, self::MAX_DESCRIPTION_LENGTH); + } if (!empty($description)) { $req->order->description = $description; } diff --git a/tests/Message/CIMAuthorizeRequestTest.php b/tests/Message/CIMAuthorizeRequestTest.php index 969ad2d9..4706b32e 100644 --- a/tests/Message/CIMAuthorizeRequestTest.php +++ b/tests/Message/CIMAuthorizeRequestTest.php @@ -34,6 +34,24 @@ public function testGetData() $this->assertEquals('Test authorize transaction', $data->transactionRequest->order->description); } + public function testShouldTruncateLongDescription() + { + $description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; + $truncatedDescription = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has su"; + + $this->request = new CIMAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize( + array( + 'cardReference' => '{"customerProfileId":"28972085","customerPaymentProfileId":"26317841","customerShippingAddressId":"27057151"}', + 'amount' => '12.00', + 'description' => $description, + 'clientIp' => '10.0.0.1' + ) + ); + $data = $this->request->getData(); + $this->assertEquals($truncatedDescription, $data->transactionRequest->order->description); + } + public function testShouldUseTrackDataIfCardPresent() { $card = $this->getValidCard();