Skip to content

Commit

Permalink
Merge pull request #104 from imanghafoori1/dev
Browse files Browse the repository at this point in the history
Re-Indent and flatten code
  • Loading branch information
hpakdaman authored Feb 25, 2018
2 parents 60d8f88 + af432b7 commit c16f8c1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
97 changes: 49 additions & 48 deletions src/Pasargad/Pasargad.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public function ready()
public function redirect()
{

$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile);
$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile);

$url = $this->gateUrl;
$redirectUrl = $this->getCallback();
$invoiceNumber = $this->transactionId();
$amount = $this->amount;
$terminalCode = $this->config->get('gateway.pasargad.terminalId');
$merchantCode = $this->config->get('gateway.pasargad.merchantId');
$timeStamp = date("Y/m/d H:i:s");
$invoiceDate = date("Y/m/d H:i:s");
$action = 1003;
$data = "#". $merchantCode ."#". $terminalCode ."#". $invoiceNumber ."#". $invoiceDate ."#". $amount ."#". $redirectUrl ."#". $action ."#". $timeStamp ."#";
$data = sha1($data,true);
$data = $processor->sign($data); // امضاي ديجيتال
$sign = base64_encode($data); // base64_encode
$invoiceNumber = $this->transactionId();
$amount = $this->amount;
$terminalCode = $this->config->get('gateway.pasargad.terminalId');
$merchantCode = $this->config->get('gateway.pasargad.merchantId');
$timeStamp = date("Y/m/d H:i:s");
$invoiceDate = date("Y/m/d H:i:s");
$action = 1003;
$data = "#". $merchantCode ."#". $terminalCode ."#". $invoiceNumber ."#". $invoiceDate ."#". $amount ."#". $redirectUrl ."#". $action ."#". $timeStamp ."#";
$data = sha1($data,true);
$data = $processor->sign($data); // امضاي ديجيتال
$sign = base64_encode($data); // base64_encode

return \View::make('gateway::pasargad-redirector')->with(compact('url','redirectUrl','invoiceNumber','invoiceDate','amount','terminalCode','merchantCode','timeStamp','action','sign'));
}
Expand Down Expand Up @@ -125,41 +125,42 @@ protected function sendPayRequest()
*/
protected function verifyPayment()
{
$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile);
$fields = array('invoiceUID' => Input::get('tref'));
$result = Parser::post2https($fields,'https://pep.shaparak.ir/CheckTransactionResult.aspx');
$check_array = Parser::makeXMLTree($result);
if ($check_array['resultObj']['result'] == "True") {
$fields = array(
'MerchantCode' => $this->config->get('gateway.pasargad.merchantId'),
'TerminalCode' => $this->config->get('gateway.pasargad.terminalId'),
'InvoiceNumber' => $check_array['resultObj']['invoiceNumber'],
'InvoiceDate' => Input::get('iD'),
'amount' => $check_array['resultObj']['amount'],
'TimeStamp' => date("Y/m/d H:i:s"),
'sign' => '',
);

$data = "#" . $fields['MerchantCode'] . "#" . $fields['TerminalCode'] . "#" . $fields['InvoiceNumber'] ."#" . $fields['InvoiceDate'] . "#" . $fields['amount'] . "#" . $fields['TimeStamp'] ."#";
$data = sha1($data, true);
$data = $processor->sign($data);
$fields['sign'] = base64_encode($data);
$result = Parser::post2https($fields,"https://pep.shaparak.ir/VerifyPayment.aspx");
$array = Parser::makeXMLTree($result);
if ($array['actionResult']['result'] != "True") {
$this->newLog(-1, Enum::TRANSACTION_FAILED_TEXT);
$this->transactionFailed();
throw new PasargadErrorException(Enum::TRANSACTION_FAILED_TEXT, -1);
}
$this->refId = $check_array['resultObj']['referenceNumber'];
$this->transactionSetRefId();
$this->trackingCode = Input::get('tref');
$this->transactionSucceed();
$this->newLog(0, Enum::TRANSACTION_SUCCEED_TEXT);
} else {
$this->newLog(-1, Enum::TRANSACTION_FAILED_TEXT);
$this->transactionFailed();
throw new PasargadErrorException(Enum::TRANSACTION_FAILED_TEXT, -1);
}
$processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'),RSAKeyType::XMLFile);
$fields = array('invoiceUID' => Input::get('tref'));
$result = Parser::post2https($fields,'https://pep.shaparak.ir/CheckTransactionResult.aspx');
$check_array = Parser::makeXMLTree($result);

if ($check_array['resultObj']['result'] != "True") {
$this->newLog(-1, Enum::TRANSACTION_FAILED_TEXT);
$this->transactionFailed();
throw new PasargadErrorException(Enum::TRANSACTION_FAILED_TEXT, -1);
}

$fields = array(
'MerchantCode' => $this->config->get('gateway.pasargad.merchantId'),
'TerminalCode' => $this->config->get('gateway.pasargad.terminalId'),
'InvoiceNumber' => $check_array['resultObj']['invoiceNumber'],
'InvoiceDate' => Input::get('iD'),
'amount' => $check_array['resultObj']['amount'],
'TimeStamp' => date("Y/m/d H:i:s"),
'sign' => '',
);

$data = "#" . $fields['MerchantCode'] . "#" . $fields['TerminalCode'] . "#" . $fields['InvoiceNumber'] ."#" . $fields['InvoiceDate'] . "#" . $fields['amount'] . "#" . $fields['TimeStamp'] ."#";
$data = sha1($data, true);
$data = $processor->sign($data);
$fields['sign'] = base64_encode($data);
$result = Parser::post2https($fields,"https://pep.shaparak.ir/VerifyPayment.aspx");
$array = Parser::makeXMLTree($result);
if ($array['actionResult']['result'] != "True") {
$this->newLog(-1, Enum::TRANSACTION_FAILED_TEXT);
$this->transactionFailed();
throw new PasargadErrorException(Enum::TRANSACTION_FAILED_TEXT, -1);
}
$this->refId = $check_array['resultObj']['referenceNumber'];
$this->transactionSetRefId();
$this->trackingCode = Input::get('tref');
$this->transactionSucceed();
$this->newLog(0, Enum::TRANSACTION_SUCCEED_TEXT);
}
}
9 changes: 4 additions & 5 deletions src/Sadad/Sadad.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@ protected function verifyPayment()

$this->newLog($statusResult, $message['fa']);

if ($statusResult == 0 && $appStatus === 'commit') {
$this->trackingCode = $result->TraceNo;
$this->cardNumber = $result->CustomerCardNumber;
$this->transactionSucceed();
} else {
if ($statusResult != 0 || $appStatus !== 'commit') {
$this->transactionFailed();
throw new SadadException($message['fa'], $statusResult);
}
$this->trackingCode = $result->TraceNo;
$this->cardNumber = $result->CustomerCardNumber;
$this->transactionSucceed();
}

/**
Expand Down

0 comments on commit c16f8c1

Please sign in to comment.