From 5595791d2f9a3cb823b22414561c20a8677485f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lenar=20L=C3=B5hmus?= Date: Fri, 29 Mar 2019 19:05:37 +0200 Subject: [PATCH] estcard payment request additionalinfo field support Figured it out :) --- src/Protocol/ECommerce.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Protocol/ECommerce.php b/src/Protocol/ECommerce.php index f086629..f1a0882 100644 --- a/src/Protocol/ECommerce.php +++ b/src/Protocol/ECommerce.php @@ -170,9 +170,14 @@ public function getPaymentRequest( } // If additionalinfo is sent it needs to be included in MAC calculation - // But how (what position, etc) is not specified by available specification, seems to be secret - // So just remove it but leave it otherwise in the code - maybe somebody figures it out - unset($data['additionalinfo']); + // So remove it if empty + // Data format (max length 128): key:value;[key:value;]* + // Key and value must not contain : and ; but no checking done here + // Example (reference number): refnr:12345678907; + // Information here: https://www.estcard.ee/doc/ecom.html (doc version 1.1.3, date 2019-03-13) + if (strlen($data['additionalinfo']) < 1) { + unset($data['additionalinfo']); + } // Generate signature $data['mac'] = $this->getSignature($data, $encoding); @@ -301,6 +306,11 @@ protected function generateSignature(array $data, string $encoding = 'UTF-8') : $data['feedBackUrl'] = ProtocolHelper::mbStrPad($data['feedBackUrl'], 128); } + if (isset($data['additionalinfo'])) { + $fields[] = 'additionalinfo'; + $data['additionalinfo'] = ProtocolHelper::mbStrPad($data['additionalinfo'], 128); + } + // Pad to correct length $data['ver'] = ProtocolHelper::mbStrPad($data['ver'], 3, "0", STR_PAD_LEFT, $encoding); $data['id'] = ProtocolHelper::mbStrPad($data['id'], 10, " ", STR_PAD_RIGHT, $encoding);