Skip to content

Commit

Permalink
normalized parameters name - all to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
samuraee committed Jun 7, 2019
1 parent 10e14e7 commit dc0fb24
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 35 deletions.
16 changes: 11 additions & 5 deletions src/Adapter/AdapterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function init() { }
*/
public function __set($key, $val)
{
$key = strtolower($key);
$this->parameters[$key] = trim($val);
}

Expand All @@ -90,6 +91,7 @@ public function __set($key, $val)
*/
public function __get($key)
{
$key = strtolower($key);
return isset($this->parameters[$key]) ? trim($this->parameters[$key]) : null;
}

Expand All @@ -110,6 +112,7 @@ public function getTransaction(): TransactionInterface
public function setParameters(array $parameters = []): AdapterInterface
{
foreach ($parameters as $key => $value) {
$key = strtolower($key);
$this->parameters[$key] = trim($value);
}

Expand All @@ -123,6 +126,7 @@ public function setParameters(array $parameters = []): AdapterInterface
*/
public function getParameter($key)
{
$key = strtolower($key);
return isset($this->parameters[$key]) ? trim($this->parameters[$key]) : null;
}

Expand Down Expand Up @@ -177,6 +181,8 @@ public function reverse(): bool
*/
protected function checkRequiredParameters(array $parameters)
{
$parameters = array_change_key_case($parameters,CASE_LOWER);

foreach ($parameters as $parameter) {
if (!array_key_exists($parameter, $this->parameters) || trim($this->parameters[$parameter]) == "") {
throw new Exception("Parameters array must have a not null value for key: '$parameter'");
Expand All @@ -187,7 +193,7 @@ protected function checkRequiredParameters(array $parameters)
/**
* @return string
*/
protected function getWSDL()
protected function getWSDL(): string
{
if (config('larapay.mode') == 'production') {
return $this->WSDL;
Expand All @@ -199,7 +205,7 @@ protected function getWSDL()
/**
* @return string
*/
protected function getEndPoint()
protected function getEndPoint(): string
{
if (config('larapay.mode') == 'production') {
return $this->endPoint;
Expand Down Expand Up @@ -228,7 +234,7 @@ public function setSoapOptions(array $options = [])
/**
* @return array
*/
protected function getSoapOptions()
protected function getSoapOptions(): array
{
return $this->soapOptions;
}
Expand All @@ -255,7 +261,7 @@ public function getGatewayReferenceId(): string
/**
* @return bool
*/
public function reverseSupport()
public function reverseSupport(): bool
{
return $this->reverseSupport;
}
Expand All @@ -273,7 +279,7 @@ public function canContinueWithCallbackParameters(): bool
*
* @return array
*/
protected function obj2array($obj)
protected function obj2array($obj): array
{
$out = [];
foreach ($obj as $key => $val) {
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/Mellat.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function verifyTransaction()
'SaleOrderId',
'SaleReferenceId',
'CardHolderInfo',
'CardHolderPan',
]);

$sendParams = [
Expand Down Expand Up @@ -282,7 +283,7 @@ protected function settleTransaction()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function reverseTransaction()
protected function reverseTransaction(): bool
{
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
throw new Exception('larapay::larapay.could_not_reverse_payment');
Expand Down
8 changes: 4 additions & 4 deletions src/Adapter/Parsian.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function requestToken()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function generateForm()
protected function generateForm(): string
{
$authority = $this->requestToken();

Expand All @@ -112,7 +112,7 @@ protected function generateForm()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function verifyTransaction()
protected function verifyTransaction(): bool
{
if ($this->getTransaction()->checkForVerify() == false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
Expand Down Expand Up @@ -166,7 +166,7 @@ protected function verifyTransaction()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function reverseTransaction()
protected function reverseTransaction(): bool
{
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
throw new Exception('larapay::larapay.could_not_reverse_payment');
Expand Down Expand Up @@ -218,7 +218,7 @@ public function getGatewayReferenceId(): string
}


protected function getWSDL()
protected function getWSDL(): string
{

$type = $this->requestType;
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Pasargad.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function generateForm(): string
* @return bool
* @throws Exception
*/
protected function verifyTransaction()
protected function verifyTransaction(): bool
{
$this->checkRequiredParameters([
'iN',
Expand Down Expand Up @@ -136,7 +136,7 @@ protected function verifyTransaction()
* @return bool
* @throws Exception
*/
protected function reverseTransaction()
protected function reverseTransaction(): bool
{
$this->checkRequiredParameters([
'iN',
Expand Down
10 changes: 4 additions & 6 deletions src/Adapter/Payir.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class Payir extends AdapterAbstract implements AdapterInterface
public $reverseSupport = false;

/**
* @return array
* @return string
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function requestToken()
protected function requestToken(): string
{
if ($this->getTransaction()->checkForRequestToken() == false) {
throw new Exception('larapay::larapay.could_not_request_payment');
Expand All @@ -46,8 +46,6 @@ protected function requestToken()
];

try {


Log::debug('PaymentRequest call', $sendParams);
$result = Helper::post2https($sendParams, $this->endPoint);

Expand Down Expand Up @@ -79,7 +77,7 @@ protected function requestToken()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function generateForm()
protected function generateForm(): string
{
$authority = $this->requestToken();

Expand All @@ -95,7 +93,7 @@ protected function generateForm()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function verifyTransaction()
protected function verifyTransaction(): bool
{
if ($this->getTransaction()->checkForVerify() == false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
Expand Down
46 changes: 34 additions & 12 deletions src/Adapter/Saman.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class Saman extends AdapterAbstract implements AdapterInterface
protected $reverseSupport = true;

/**
* @return array
* @throws Exception
* @return string
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function requestToken()
protected function requestToken(): string
{
Log::debug(__METHOD__);

Expand Down Expand Up @@ -74,7 +74,7 @@ protected function requestToken()
}
}

public function generateForm()
public function generateForm(): string
{
Log::debug(__METHOD__);

Expand All @@ -85,7 +85,7 @@ public function generateForm()
}
}

protected function generateFormWithoutToken()
protected function generateFormWithoutToken(): string
{
Log::debug(__METHOD__, $this->getParameters());

Expand All @@ -107,7 +107,7 @@ protected function generateFormWithoutToken()
]);
}

protected function generateFormWithToken()
protected function generateFormWithToken(): string
{
Log::debug(__METHOD__, $this->getParameters());
$this->checkRequiredParameters([
Expand All @@ -133,7 +133,12 @@ protected function generateFormWithToken()
]);
}

protected function verifyTransaction()
/**
* @return bool
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function verifyTransaction(): bool
{
if ($this->getTransaction()->checkForVerify() == false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
Expand All @@ -144,7 +149,8 @@ protected function verifyTransaction()
'RefNum',
'ResNum',
'merchant_id',
'TRACENO',
'TraceNo',
'SecurePan'
]);

if ($this->State != 'OK') {
Expand All @@ -160,8 +166,10 @@ protected function verifyTransaction()
if (isset($response)) {
Log::info('VerifyTransaction response', ['response' => $response]);

if ($response == $this->getTransaction()->getPayableAmount()) { // check by transaction amount
$this->getTransaction()->setVerified();
if ($response == $this->getTransaction()->getPayableAmount()) {
// double check the amount by transaction amount
$this->getTransaction()->setCardNumber($this->SecurePan, false); // no save()
$this->getTransaction()->setVerified(); // with save()

return true;
} else {
Expand All @@ -176,7 +184,12 @@ protected function verifyTransaction()
}
}

protected function reverseTransaction()
/**
* @return bool
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function reverseTransaction(): bool
{
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
throw new Exception('larapay::larapay.could_not_reverse_payment');
Expand Down Expand Up @@ -240,6 +253,10 @@ public function canContinueWithCallbackParameters(): bool
return false;
}

/**
* @return string
* @throws \Tartan\Larapay\Adapter\Exception
*/
public function getGatewayReferenceId(): string
{
$this->checkRequiredParameters([
Expand All @@ -249,7 +266,12 @@ public function getGatewayReferenceId(): string
return $this->RefNum;
}

protected function getWSDL($type = null)
/**
* @param string $type
*
* @return string
*/
protected function getWSDL($type = null): string
{
if (config('larapay.mode') == 'production') {
switch (strtoupper($type)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Adapter/Zarinpal.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Zarinpal extends AdapterAbstract implements AdapterInterface
public $reverseSupport = false;

/**
* @return array
* @return string
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function requestToken()
protected function requestToken(): string
{
if ($this->getTransaction()->checkForRequestToken() == false) {
throw new Exception('larapay::larapay.could_not_request_payment');
Expand Down Expand Up @@ -83,7 +83,7 @@ protected function requestToken()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function generateForm()
protected function generateForm(): string
{
$authority = $this->requestToken();

Expand All @@ -99,7 +99,7 @@ protected function generateForm()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function verifyTransaction()
protected function verifyTransaction(): bool
{
if ($this->getTransaction()->checkForVerify() == false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
Expand Down
2 changes: 1 addition & 1 deletion src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __call ($name, $arguments)
try {
return call_user_func_array([$this->gateway, $name], $arguments); // call desire method
} catch (\Exception $e) {
Log::error($e->getMessage() .' #'.$e->getCode(). ' File:'.$e->getFile().':'.$e->getLine());
Log::error($e->getMessage() .' Code:'.$e->getCode(). ' File:'.$e->getFile().':'.$e->getLine());
throw $e;
}
}
Expand Down

0 comments on commit dc0fb24

Please sign in to comment.