Skip to content

Commit

Permalink
Refactoring and code-formatting of the new ATM and WMC interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
baibaratsky committed Aug 11, 2016
1 parent 513cf98 commit b42913f
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 304 deletions.
42 changes: 20 additions & 22 deletions Api/ATM/ATM1/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public function __construct($authType = self::AUTH_CLASSIC)
protected function getValidationRules()
{
return array(
RequestValidator::TYPE_REQUIRED => array(
'price', 'payeePurse', 'currency'
)
RequestValidator::TYPE_REQUIRED => array('price', 'payeePurse', 'currency'),
);
}

Expand Down Expand Up @@ -73,23 +71,23 @@ public function getResponseClassName()
{
return Response::className();
}

/**
* @param string $lightCertificate
* @param string $lightKey
* @param string $lightPass
*/
public function cert($lightCertificate, $lightKey, $lightPass = '') {

/**
* @inheritdoc
*/
public function lightAuth($certificate, $key, $keyPassword = '')
{
if ($this->authType === self::AUTH_LIGHT) {
$this->setSignature(
$this->signLight(
$this->getSignerWmid() . $this->getCurrency() .
$this->getPayeePurse() . $this->getPrice(),
$lightKey, $lightPass
)
$this->signLight(
$this->getSignerWmid() . $this->getCurrency() . $this->getPayeePurse() . $this->getPrice(),
$key,
$keyPassword
)
);
}
parent::cert($lightCertificate, $lightKey, $lightPass);

parent::lightAuth($certificate, $key, $keyPassword);
}

/**
Expand All @@ -98,12 +96,12 @@ public function cert($lightCertificate, $lightKey, $lightPass = '') {
public function sign(Signer $requestSigner = null)
{
if ($this->authType === self::AUTH_CLASSIC) {
$this->setSignature(
$requestSigner->sign(
$this->getSignerWmid() . $this->getCurrency() .
$this->getPayeePurse() . $this->getPrice()
)
);
$this->setSignature(
$requestSigner->sign(
$this->getSignerWmid() . $this->getCurrency() .
$this->getPayeePurse() . $this->getPrice()
)
);
}
}

Expand Down
26 changes: 13 additions & 13 deletions Api/ATM/ATM1/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ public function __construct($response)
parent::__construct($response);

$responseObject = new \SimpleXMLElement($response);
$this->returnCode = (int) $responseObject->retval;
$this->returnDescription = (string) $responseObject->retdesc . '. '. (string) $responseObject->description;

$this->returnCode = (int)$responseObject->retval;
$this->returnDescription = (string)$responseObject->retdesc . '. ' . (string)$responseObject->description;

if (isset($responseObject->payment)) {
$payment = $responseObject->payment;
$this->currency = (string) $payment['currency'];
$this->exchange = (string) $payment['exchange'];
$this->payeePurse = (string) $payment->purse;
$this->upExchange = (float) $payment->upexchange;
$this->course = (float) $payment->course;
$this->price = (float) $payment->price;
$this->amount = (float) $payment->amount;
$this->rest = (float) $payment->rest;
$this->dayLimit = (float) $payment->limit->day;
$this->monthLimit = (float) $payment->limit->month;
$this->currency = (string)$payment['currency'];
$this->exchange = (string)$payment['exchange'];
$this->payeePurse = (string)$payment->purse;
$this->upExchange = (float)$payment->upexchange;
$this->course = (float)$payment->course;
$this->price = (float)$payment->price;
$this->amount = (float)$payment->amount;
$this->rest = (float)$payment->rest;
$this->dayLimit = (float)$payment->limit->day;
$this->monthLimit = (float)$payment->limit->month;
}
}

Expand Down
55 changes: 27 additions & 28 deletions Api/ATM/ATM2/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function __construct($authType = self::AUTH_CLASSIC)
protected function getValidationRules()
{
return array(
RequestValidator::TYPE_REQUIRED => array(
'lang', 'transactionId', 'currency', 'test', 'price', 'date', 'point'
)
RequestValidator::TYPE_REQUIRED => array(
'lang', 'transactionId', 'currency', 'test', 'price', 'date', 'point'
)
);
}

Expand Down Expand Up @@ -93,25 +93,24 @@ public function getResponseClassName()
{
return Response::className();
}

/**
* @param string $lightCertificate
* @param string $lightKey
* @param string $lightPass
*/
public function cert($lightCertificate, $lightKey, $lightPass = '') {
if ($this->authType === self::AUTH_LIGHT) {
$this->setSignature(
$this->signLight(
$this->getSignerWmid() . $this->getTransactionId() .
$this->getCurrency() . $this->getTest() .
$this->getPayeePurse() . $this->getPrice() .
$this->getDate()->format('Ymd H:i:s') . $this->getPoint(),
$lightKey, $lightPass
)
);
}
parent::cert($lightCertificate, $lightKey, $lightPass);

/**
* @inheritdoc
*/
public function lightAuth($certificate, $key, $keyPassword = '')
{
if ($this->authType === self::AUTH_LIGHT) {
$this->setSignature(
$this->signLight(
$this->getSignerWmid() . $this->getTransactionId() . $this->getCurrency() . $this->getTest()
. $this->getPayeePurse() . $this->getPrice() . $this->getDate()->format('Ymd H:i:s')
. $this->getPoint(),
$key,
$keyPassword
)
);
}
parent::lightAuth($certificate, $key, $keyPassword);
}

/**
Expand All @@ -121,12 +120,12 @@ public function sign(Signer $requestSigner = null)
{
if ($this->authType === self::AUTH_CLASSIC) {
$this->setSignature(
$requestSigner->sign(
$this->getSignerWmid() . $this->getTransactionId() .
$this->getCurrency() . $this->getTest() .
$this->getPayeePurse() . $this->getPrice() .
$this->getDate()->format('Ymd H:i:s') . $this->getPoint()
)
$requestSigner->sign(
$this->getSignerWmid() . $this->getTransactionId() .
$this->getCurrency() . $this->getTest() .
$this->getPayeePurse() . $this->getPrice() .
$this->getDate()->format('Ymd H:i:s') . $this->getPoint()
)
);
}
}
Expand Down
28 changes: 14 additions & 14 deletions Api/ATM/ATM2/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ public function __construct($response)

if (isset($responseObject->payment)) {
$payment = $responseObject->payment;
$this->id = (int) $payment['id'];
$this->currency = (string) $payment['currency'];
$this->test = (int) $payment['test'];
$this->payeePurse = (string) $payment->purse;
$this->price = (float) $payment->price;
$this->amount = (float) $payment->amount;
$this->comiss = (float) $payment->comiss;
$this->rest = (float) $payment->rest;
$this->date = self::createDateTime((string)$payment->date);
$this->point = (int) $payment->point;
$this->wmtranid = (int) $payment->wmtranid;
$this->dateupd = self::createDateTime((string)$payment->dateupd);
$this->dayLimit = (float) $payment->limit->day;
$this->monthLimit = (float) $payment->limit->month;
$this->id = (int)$payment['id'];
$this->currency = (string)$payment['currency'];
$this->test = (int)$payment['test'];
$this->payeePurse = (string)$payment->purse;
$this->price = (float)$payment->price;
$this->amount = (float)$payment->amount;
$this->comiss = (float)$payment->comiss;
$this->rest = (float)$payment->rest;
$this->date = self::createDateTime((string)$payment->date);
$this->point = (int)$payment->point;
$this->wmtranid = (int)$payment->wmtranid;
$this->dateupd = self::createDateTime((string)$payment->dateupd);
$this->dayLimit = (float)$payment->limit->day;
$this->monthLimit = (float)$payment->limit->month;
}
}

Expand Down
55 changes: 31 additions & 24 deletions Api/ATM/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ abstract class Request extends XmlRequest
const AUTH_SHA256 = 'sha256';
const AUTH_MD5 = 'md5';
const AUTH_SECRET_KEY = 'secret_key';

const AUTH_SIGN_TYPE_CLASSIC = 1;
const AUTH_SIGN_TYPE_LIGHT = 2;
CONST CURRENCY_EUR = 'EUR';
CONST CURRENCY_USD = 'USD';
CONST CURRENCY_RUB = 'RUB';

const CURRENCY_EUR = 'EUR';
const CURRENCY_USD = 'USD';
const CURRENCY_RUB = 'RUB';

/** @var string request/@lang */
protected $lang;
Expand All @@ -38,9 +39,9 @@ abstract class Request extends XmlRequest

/** @var string Light auth key file name (PEM) */
protected $lightKey;

/** @var string Light auth key password */
protected $lightPass;
protected $lightPassword;

/**
* @param string $authType
Expand All @@ -53,28 +54,29 @@ public function __construct($authType = self::AUTH_CLASSIC, $lang = 'en')

if (self::AUTH_CLASSIC == $authType) {
$this->authTypeNum = self::AUTH_SIGN_TYPE_CLASSIC;
} elseif(self::AUTH_LIGHT == $authType) {
} elseif (self::AUTH_LIGHT == $authType) {
$this->authTypeNum = self::AUTH_SIGN_TYPE_LIGHT;
}
$this->setLang($lang);
}

/**
* @param string $lightCertificate Light auth certificate file name (PEM)
* @param string $lightKey Light auth key file name (PEM)
* @param string $lightPass Light auth key pass
* @param string $certificate Light auth certificate file name (PEM)
* @param string $key Light auth key file name (PEM)
* @param string $keyPassword Light auth key password
*/
public function cert($lightCertificate, $lightKey, $lightPass = '')
public function lightAuth($certificate, $key, $keyPassword = '')
{
$this->lightCertificate = $lightCertificate;
$this->lightKey = $lightKey;
$this->lightPass = $lightPass;
$this->lightCertificate = $certificate;
$this->lightKey = $key;
$this->lightPassword = $keyPassword;
}

/**
* @param $data
*/
public function setSignature($data) {
public function setSignature($data)
{
$this->signature = $data;
}

Expand All @@ -101,12 +103,13 @@ public function getLightKey()
{
return $this->lightKey;
}

/**
* @return string
*/
public function getLightPass() {
return $this->lightPass;
public function getLightPassword()
{
return $this->lightPassword;
}

/**
Expand Down Expand Up @@ -153,28 +156,32 @@ protected function generateRequestNumber()
/**
* @param int $authTypeNum
*/
public function setAuthTypeNum($authTypeNum) {
public function setAuthTypeNum($authTypeNum)
{
$this->authTypeNum = $authTypeNum;
}

/**
* @return int|string
*/
public function getAuthTypeNum() {
public function getAuthTypeNum()
{
return $this->authTypeNum;
}

/**
* @param string $lang
*/
public function setLang($lang) {
public function setLang($lang)
{
$this->lang = $lang;
}

/**
* @return string
*/
public function getLang() {
public function getLang()
{
return $this->lang;
}
}
Loading

0 comments on commit b42913f

Please sign in to comment.