Skip to content

Commit

Permalink
Estcard support improved (#1)
Browse files Browse the repository at this point in the history
Estcard support improved
  • Loading branch information
lenar authored and renekorss committed Jul 27, 2016
1 parent f07929e commit 265b008
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Estcard.php
Expand Up @@ -28,7 +28,7 @@ class Estcard extends Banklink
*
* @var string
*/
protected $requestUrl = 'https://pos.estcard.ee/test-pos/iPayServlet';
protected $requestUrl = 'https://pos.estcard.ee/ecom/iPayServlet';

/**
* Test request url.
Expand Down
20 changes: 19 additions & 1 deletion src/Protocol/ECommerce.php
Expand Up @@ -30,6 +30,13 @@ class ECommerce implements Protocol
* @var string
*/
const PAYMENT_RESPONSE_SUCCESS = '000';

/**
* Abort (user aborted payment) response code.
*
* @var string
*/
const PAYMENT_RESPONSE_ABORT = '017';

/**
* File path or file contents of public key.
Expand Down Expand Up @@ -146,6 +153,11 @@ public function getPaymentRequest(
'delivery' => 'S',
'additionalinfo' => $message
);

// 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']);

// Generate signature
$data['mac'] = $this->getSignature($data, $encoding);
Expand Down Expand Up @@ -252,8 +264,14 @@ protected function generateSignature(array $data, $encoding = 'UTF-8')
);

$data['receipt_no'] = ProtocolHelper::mbStrPad($data['receipt_no'], 6, "0", STR_PAD_LEFT, $encoding);
$data['msgdata'] = ProtocolHelper::mbStrPad(
$data['respcode'] === self::PAYMENT_RESPONSE_ABORT && strlen($data['msgdata']) == 0 ? ' ' : $data['msgdata'],
40,
" ",
STR_PAD_RIGHT,
$encoding
);
$data['respcode'] = ProtocolHelper::mbStrPad($data['respcode'], 3, "0", STR_PAD_LEFT, $encoding);
$data['msgdata'] = ProtocolHelper::mbStrPad($data['msgdata'], 40, " ", STR_PAD_RIGHT, $encoding);
$data['actiontext'] = ProtocolHelper::mbStrPad($data['actiontext'], 40, " ", STR_PAD_RIGHT, $encoding);
}

Expand Down
3 changes: 1 addition & 2 deletions tests/EstcardTest.php
Expand Up @@ -17,7 +17,7 @@ class EstcardTest extends \PHPUnit_Framework_TestCase
protected $bankClass = "RKD\Banklink\Estcard";
protected $protocolClass = "RKD\Banklink\Protocol\ECommerce";

protected $requestUrl = 'https://pos.estcard.ee/test-pos/iPayServlet';
protected $requestUrl = 'https://pos.estcard.ee/ecom/iPayServlet';
protected $testRequestUrl = 'http://localhost:8080/banklink/ec';

/**
Expand Down Expand Up @@ -53,7 +53,6 @@ public function setUp()
'ecuno' => $this->orderId,
'eamount' => $this->amount * 100,
'cur' => $this->currency,
'additionalinfo' => $this->message,
'feedBackUrl' => $this->customRequestUrl,
'lang' => 'et',
'delivery' => 'S',
Expand Down

0 comments on commit 265b008

Please sign in to comment.