Skip to content

Commit

Permalink
estcard payment request additionalinfo field support
Browse files Browse the repository at this point in the history
Figured it out :)
  • Loading branch information
lenar authored and renekorss committed Apr 1, 2019
1 parent 35d82da commit 5595791
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Protocol/ECommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5595791

Please sign in to comment.