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();