Skip to content

Commit

Permalink
Merge pull request #3 from vanderson139/master
Browse files Browse the repository at this point in the history
Added the "voidPreAuthorization()" message; and enable set a different date to the transaction.
  • Loading branch information
byjg authored May 5, 2017
2 parents 088a653 + ff1bd31 commit 063fdef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/Omnipay/Komerci/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ public function setNumAutor($value)
return $this->setParameter('numautor', $value);
}

public function getDate()
{
return $this->getParameter('date');
}

public function getFormattedDate()
{
return $this->getParameter('date')
? date('Ymd', strtotime(str_replace('/', '-', $this->getParameter('date'))))
: date('Ymd');
}

public function setDate($value)
{
return $this->setParameter('date', $value);
}

/**
*
* @param type $data
Expand Down
2 changes: 1 addition & 1 deletion src/Omnipay/Komerci/Message/WSConfPreAuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getData()
'Distribuidor' => '',
'Total' => sprintf("%.2F", round($this->getAmount() * 100) / 100),
'Parcelas' => $this->getFormattedInstallments(),
'Data' => date('Ymd'),
'Data' => $this->getFormattedDate(),
'NumAutor' => $this->getNumAutor(),
'NumCv' => $this->getTransactionReference(),
'Concentrador' => '',
Expand Down
32 changes: 27 additions & 5 deletions src/Omnipay/Komerci/Message/WSVoidRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ public function setPreAuth($value)
{
return $this->setParameter('preauth', $value);
}


public function getConfPreAuth()
{
return $this->getParameter('confpreauth');
}

public function setConfPreAuth($value)
{
return $this->setParameter('confpreauth', $value);
}

public function getData()
{
$this->validate('apikey', 'amount', 'transactionReference', 'numautor', 'username', 'password');

if ($this->getPreAuth()) {
return $this->getVoidPreAuthData();
} else if ($this->getConfPreAuth()) {
return $this->getVoidConfPreAuthData();
} else {
return $this->getVoidPurchaseData();
}
Expand All @@ -47,17 +59,27 @@ protected function getVoidPreAuthData()
{
$data = $this->getVoidPurchaseData();

if ($this->getTestMode()) {
$data['Distribuidor'] = '';
}
$data['Data'] = date('Ymd');
$data['Distribuidor'] = '';
$data['Data'] = $this->getFormattedDate();

return $data;
}

protected function getVoidConfPreAuthData()
{
$data = $this->getVoidPurchaseData();

$data['Parcelas'] = $this->getFormattedInstallments();
$data['Data'] = $this->getFormattedDate();

return $data;
}

public function sendData($data)
{
if ($this->getPreAuth()) {
$httpResponse = $this->prepareSendData($data, 'VoidPreAuthorization');
} else if ($this->getConfPreAuth()) {
$httpResponse = $this->prepareSendData($data, 'VoidConfPreAuthorization');
} else {
$httpResponse = $this->prepareSendData($data, 'VoidTransaction');
Expand Down

0 comments on commit 063fdef

Please sign in to comment.