-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from sergeynezbritskiy/dev
RC-1.0.0
- Loading branch information
Showing
65 changed files
with
3,120 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ composer.phar | |
/vendor/ | ||
/build/ | ||
.idea | ||
phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SergeyNezbritskiy\PrivatBank\Api; | ||
|
||
use SergeyNezbritskiy\PrivatBank\Merchant; | ||
|
||
/** | ||
* Interface RequiresAuthenticationInterface | ||
* @package SergeyNezbritskiy\PrivatBank\Api | ||
*/ | ||
interface AuthorizedRequestInterface extends RequestInterface | ||
{ | ||
|
||
/** | ||
* @param Merchant $merchant | ||
* @return void | ||
*/ | ||
public function setMerchant(Merchant $merchant); | ||
|
||
/** | ||
* @return Merchant | ||
*/ | ||
public function getMerchant(): Merchant; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SergeyNezbritskiy\PrivatBank\Api; | ||
|
||
/** | ||
* Interface HttpResponseInterface | ||
* @package SergeyNezbritskiy\PrivatBank\Api | ||
*/ | ||
interface HttpResponseInterface | ||
{ | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getContent(): string; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getStatusCode(): int; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getReasonPhrase(): string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SergeyNezbritskiy\PrivatBank\Base; | ||
|
||
use SergeyNezbritskiy\PrivatBank\Api\AuthorizedRequestInterface; | ||
use SergeyNezbritskiy\XmlIo\XmlWriter; | ||
|
||
/** | ||
* Class AbstractAuthorizedRequest | ||
* @package SergeyNezbritskiy\PrivatBank\Base | ||
*/ | ||
abstract class AbstractAuthorizedRequest extends AbstractRequest implements AuthorizedRequestInterface | ||
{ | ||
|
||
use HasMerchantTrait; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
abstract protected function getBodyMap(): array; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMethod(): string | ||
{ | ||
return 'POST'; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* @return array | ||
*/ | ||
protected function getBodyParams(array $params = []): array | ||
{ | ||
return [ | ||
'oper' => 'cmt', | ||
'wait' => $this->getClient()->getWaitTimeout(), | ||
'test' => $this->getClient()->isTestMode(), | ||
]; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* @return array | ||
*/ | ||
protected function getQueryParams(array $params = []): array | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @param $params | ||
* @return string | ||
*/ | ||
protected function getBody(array $params = []): string | ||
{ | ||
$xmlWriter = new XmlWriter(); | ||
$dataXml = $xmlWriter->toXml($params, $this->getBodyMap()); | ||
$dataContent = $this->getDataInnerXmlAsString($dataXml); | ||
$signature = $this->getMerchant()->calculateSignature($dataContent); | ||
$merchantId = $this->getMerchant()->getId(); | ||
|
||
$body = <<<XML | ||
<request version="1.0"> | ||
<merchant> | ||
<id>$merchantId</id> | ||
<signature>$signature</signature> | ||
</merchant> | ||
<data> | ||
$dataContent | ||
</data> | ||
</request> | ||
XML; | ||
|
||
return $body; | ||
|
||
} | ||
|
||
/** | ||
* @param \DOMDocument $xml | ||
* @return string | ||
*/ | ||
private function getDataInnerXmlAsString($xml) | ||
{ | ||
$innerXml = ''; | ||
foreach ($xml->childNodes as $node) { | ||
$innerXml .= $node->ownerDocument->saveXML($node, LIBXML_NOEMPTYTAG); | ||
} | ||
return $innerXml; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SergeyNezbritskiy\PrivatBank\Base; | ||
|
||
/** | ||
* Class AbstractPublicRequest | ||
* @package SergeyNezbritskiy\PrivatBank\Base | ||
*/ | ||
abstract class AbstractPublicRequest extends AbstractRequest | ||
{ | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getMethod(): string | ||
{ | ||
return 'GET'; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* @return array | ||
*/ | ||
protected function getBodyParams(array $params = array()): array | ||
{ | ||
return []; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.