Skip to content

Commit

Permalink
- SaleRequest with email
Browse files Browse the repository at this point in the history
- SetAdCustBorOrderId fix
  • Loading branch information
veneliniliev committed Apr 15, 2021
1 parent afd06eb commit 1abc48d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
63 changes: 32 additions & 31 deletions src/SaleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,6 @@ public function __construct()
$this->setTransactionType(TransactionType::SALE());
}

/**
* Get notification email address
*
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}

/**
* Set notification email address
*
* @param string $emailAddress E-mail адрес за уведомления.
*
* @return SaleRequest
* @throws ParameterValidationException
*/
public function setEmailAddress($emailAddress)
{
if (mb_strlen($emailAddress) > 80) {
throw new ParameterValidationException('Email address for notifications must be maximum 80 characters');
}
$this->emailAddress = $emailAddress;
return $this;
}

/**
* Send to borica. Generate form and auto submit with JS.
*
Expand Down Expand Up @@ -144,6 +117,7 @@ public function getData()
'MERCHANT' => $this->getMerchantId(),
'MERCH_NAME' => $this->getMerchantName(),
'MERCH_URL' => $this->getMerchantUrl(),
'EMAIL' => $this->getEmailAddress(),

'ORDER' => $this->getOrder(),
'AMOUNT' => $this->getAmount(),
Expand Down Expand Up @@ -332,23 +306,50 @@ public function setMerchantUrl($merchantUrl)
return $this;
}

/**
* Get notification email address
*
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}

/**
* Set notification email address
*
* @param string $emailAddress E-mail адрес за уведомления.
*
* @return SaleRequest
* @throws ParameterValidationException
*/
public function setEmailAddress($emailAddress)
{
if (mb_strlen($emailAddress) > 80) {
throw new ParameterValidationException('Email address for notifications must be maximum 80 characters');
}
$this->emailAddress = $emailAddress;
return $this;
}

/**
* Generate AD.CUST_BOR_ORDER_ID borica field
*
* @return array
*/
private function generateAdCustBorOrderId()
{
$orderString = $this->getOrder();
$orderString = $this->getAdCustBorOrderId();

if (!empty($this->getAdCustBorOrderId())) {
$orderString .= $this->getAdCustBorOrderId();
if (empty($orderString)) {
$orderString = $this->getOrder();
}

/*
* полето не трябва да съдържа символ “;”
*/
$orderString .= str_ireplace(';', '', $orderString);
$orderString = str_ireplace(';', '', $orderString);

return [
'AD.CUST_BOR_ORDER_ID' => mb_substr($orderString, 0, 16),
Expand Down
7 changes: 6 additions & 1 deletion tests/SaleRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public function testSignature()
->setDescription('Детайли плащане.')
->setMerchantGMT('+03')
->setMerchantUrl('https://test.com')
->setEmailAddress('[email protected]')
->setBackRefUrl('https://test.com/back-ref-url')
->setTerminalID(self::TERMINAL_ID)
->setMerchantId(self::MERCHANT_ID)
->setPrivateKey(__DIR__ . '/certificates/test.key')
->setPrivateKeyPassword('test')
->setSignatureTimestamp('20201013115715')
->setNonce('FC8AC36A9FDADCB6127D273CD15DAEC3')
->setAdCustBorOrderId('test')
->setSigningSchemaMacExtended();

$this->assertEquals(
Expand Down Expand Up @@ -59,6 +61,8 @@ public function testData()
->setPrivateKeyPassword('test')
->setSignatureTimestamp('20201013115715')
->setNonce('FC8AC36A9FDADCB6127D273CD15DAEC3')
->setEmailAddress('[email protected]')
->setAdCustBorOrderId('test')
->setSigningSchemaMacExtended()
->getData();

Expand All @@ -74,8 +78,9 @@ public function testData()
'TERMINAL' => self::TERMINAL_ID,
'MERCH_URL' => 'https://test.com',
'MERCH_NAME' => null,
'EMAIL' => '[email protected]',
'BACKREF' => 'https://test.com/back-ref-url',
'AD.CUST_BOR_ORDER_ID' => '145659145659',
'AD.CUST_BOR_ORDER_ID' => 'test',
'ADDENDUM' => 'AD,TD',
'NONCE' => 'FC8AC36A9FDADCB6127D273CD15DAEC3',
'MERCHANT' => self::MERCHANT_ID,
Expand Down

0 comments on commit 1abc48d

Please sign in to comment.