Skip to content

Commit

Permalink
Merge pull request #14 from yandex-money/release/v1.2.0
Browse files Browse the repository at this point in the history
Обновлен SDK до версии 1.6.4
  • Loading branch information
tonchik-tm authored Jul 10, 2020
2 parents e21424d + 2784ea5 commit 2936e36
Show file tree
Hide file tree
Showing 54 changed files with 1,978 additions and 83 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
### v1.2.0 от 10.07.2020
* Обновлен SDK до версии 1.6.4

### v1.1.1 от 29.01.2020
* фикс мелких багов
* Фикс мелких багов

### v1.1.0 от 12.11.2019
* Обновлен SDK
Expand Down
4 changes: 2 additions & 2 deletions payment/YandexMoneyApi/YandexMoneyApi.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Version: 1.1.0
* Version: 1.2.0
* License: Любое использование Вами программы означает полное и безоговорочное принятие Вами условий лицензионного договора, размещенного по адресу https://money.yandex.ru/doc.xml?id=527132 (далее – «Лицензионный договор»). Если Вы не принимаете условия Лицензионного договора в полном объёме, Вы не имеете права использовать программу в каких-либо целях.
*/

require_once 'api/Simpla.php';
require_once 'autoload.php';
define('YAMONEY_MODULE_VERSION', '1.1.1');
define('YAMONEY_MODULE_VERSION', '1.2.0');

use YandexCheckout\Client;
use YandexCheckout\Model\Payment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Client extends BaseClient
/**
* Текущая версия библиотеки
*/
const SDK_VERSION = '1.5.2';
const SDK_VERSION = '1.6.4';

/**
* Получить список платежей магазина.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,27 @@ public function setLogger($logger);
* @return UserAgent
*/
public function getUserAgent();

/**
* @param $shopId
* @return mixed
*/
public function setShopId($shopId);

/**
* @param $shopPassword
* @return mixed
*/
public function setShopPassword($shopPassword);

/**
* @param $bearerToken
* @return mixed
*/
public function setBearerToken($bearerToken);

/**
* @param array $config
*/
public function setConfig($config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public function setMaxRequestAttempts($attempts)
*/
protected function encodeData($serializedData)
{
if ($serializedData === array()) {
return '{}';
}

$result = json_encode($serializedData);
if ($result === false) {
$errorCode = json_last_error();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function call($path, $method, $queryParams, $httpBody = null, $headers =

$url = $this->prepareUrl($path, $queryParams);

$this->prepareCurl($method, $httpBody, $headers, $url);
$this->prepareCurl($method, $httpBody, $this->implodeHeaders($headers), $url);

list($httpHeaders, $httpBody, $responseInfo) = $this->sendRequest();

Expand Down Expand Up @@ -313,7 +313,7 @@ public function getConfig()
}

/**
* @param mixed $config
* @inheritDoc
*/
public function setConfig($config)
{
Expand Down Expand Up @@ -410,14 +410,18 @@ private function prepareHeaders($headers)
throw new AuthorizeException('Authorization headers not set');
}

$headers = array_map(function ($key, $value) {
return $key . ":" . $value;
}, array_keys($headers), $headers);


return $headers;
}

/**
* @param array $headers
* @return array
*/
private function implodeHeaders($headers)
{
return array_map(function ($key, $value) { return $key . ':' . $value; }, array_keys($headers), $headers);
}

/**
* @param $path
* @param $method
Expand All @@ -429,16 +433,21 @@ private function logRequestParams($path, $method, $queryParams, $httpBody, $head
{
if ($this->logger !== null) {
$message = 'Send request: ' . $method . ' ' . $path;
$context = array();
if (!empty($queryParams)) {
$message .= ' with query params: ' . json_encode($queryParams);
$context['_params'] = $queryParams;
}
if (!empty($httpBody)) {
$message .= ' with body: ' . $httpBody;
$data = json_decode($httpBody, true);
if (JSON_ERROR_NONE !== json_last_error()) {
$data = $httpBody;
}
$context['_body'] = $data;
}
if (!empty($headers)) {
$message .= ' with headers: ' . json_encode($headers);
$context['_headers'] = $headers;
}
$this->logger->info($message);
$this->logger->info($message, $context);
}
}

Expand Down Expand Up @@ -467,12 +476,19 @@ private function prepareUrl($path, $queryParams)
private function logResponse($httpBody, $responseInfo, $httpHeaders)
{
if ($this->logger !== null) {
$message = 'Response with code ' . $responseInfo['http_code'] . ' received with headers: '
. json_encode($httpHeaders);
$message = 'Response with code ' . $responseInfo['http_code'] . ' received.';
$context = array();
if (!empty($httpBody)) {
$message .= ' and body: ' . $httpBody;
$data = json_decode($httpBody, true);
if (JSON_ERROR_NONE !== json_last_error()) {
$data = $httpBody;
}
$context['_body'] = $data;
}
if (!empty($httpHeaders)) {
$context['_headers'] = $httpHeaders;
}
$this->logger->info($message);
$this->logger->info($message, $context);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ private function parseSmartLinuxRelease()
foreach ($files as $file) {
if (is_file($file)) {
$lines = array_filter(array_map(array($this, 'callbackSmartLinux'), file($file)));
foreach ($lines as $line) {
$vars[strtoupper($line[0])] = trim($line[1]);
if (is_array($lines)) {
foreach ($lines as $line) {
$vars[strtoupper($line[0])] = trim($line[1]);
}
}
}
}
Expand Down Expand Up @@ -260,7 +262,12 @@ private function parseSimpleLinuxRelease()
foreach ($files as $file) {
if (is_file($file)) {
$data = array_map(array($this, 'callbackSimpleLinux'), file($file));
$vars = array_merge($vars, array_shift($data));
if (!empty($data)) {
$array = array_shift($data);
if (!empty($array) && is_array($array)) {
$vars = array_merge($vars, $array);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
use YandexCheckout\Model\AmountInterface;
use YandexCheckout\Model\Receipt;
use YandexCheckout\Model\ReceiptInterface;
use YandexCheckout\Model\Transfer;
use YandexCheckout\Model\TransferInterface;

/**
* Класс объекта запроса к API
*
* @property AmountInterface $amount Сумма
* @property ReceiptInterface $receipt Данные фискального чека 54-ФЗ
* @property TransferInterface[] $transfers Данные о распределении платежа между магазинами
*
* @since 1.0.18
*/
Expand All @@ -51,6 +54,11 @@ class AbstractPaymentRequest extends AbstractRequest
*/
protected $_receipt;

/**
* @var TransferInterface[]
*/
protected $_transfers = array();

/**
* Возвращает сумму оплаты
* @return AmountInterface Сумма оплаты
Expand Down Expand Up @@ -118,6 +126,34 @@ public function removeReceipt()
$this->_receipt = null;
}

/**
* Устанавливает transfers (массив распределения денег между магазинами)
* @param TransferInterface[]|array $value
*/
public function setTransfers($value)
{
if (!is_array($value)) {
$message = 'Transfers must be an array of TransferInterface';
throw new InvalidPropertyValueTypeException($message, 0, 'Payment.transfers', $value);
}

$transfers = array();
foreach ($value as $item) {
if (is_array($item)) {
$item = new Transfer($item);
}

if (!($item instanceof TransferInterface)) {
$message = 'Transfers must be an array of TransferInterface';
throw new InvalidPropertyValueTypeException($message, 0, 'Payment.transfers', $value);
}

$transfers[] = $item;
}

$this->_transfers = $transfers;
}

/**
* Валидирует объект запроса
* @return bool True если запрос валиден и его можно отправить в API, false если нет
Expand All @@ -131,10 +167,38 @@ public function validate()

$value = $this->_amount->getValue();
if (empty($value) || $value <= 0.0) {
$this->setValidationError('Invalid payment amount value: '.$value);
$this->setValidationError('Invalid payment amount value: ' . $value);

return false;
}

if (!empty($this->_transfers)) {
$sum = 0;
foreach ($this->_transfers as $transfer) {
if ($transfer->getAmount() === null) {
$this->setValidationError('Payment amount not specified');
return false;
}

$value = $transfer->getAmount()->getValue();
if (empty($value) || $value <= 0.0) {
$this->setValidationError('Invalid transfer amount value: ' . $value);
return false;
}
$sum += (float) $value;

$accountId = $transfer->getAccountId();
if (empty($accountId)) {
$this->setValidationError('Transfer account id not specified');
return false;
}
}

if ($sum !== (float) $this->getAmount()->getValue()) {
$this->setValidationError('Transfer amount sum does not match top-level amount');
}
}

if ($this->_receipt !== null && $this->_receipt->notEmpty()) {
$email = $this->_receipt->getEmail();
$phone = $this->_receipt->getPhone();
Expand All @@ -146,4 +210,14 @@ public function validate()

return true;
}
}

public function hasTransfers()
{
return !empty($this->_transfers);
}

public function getTransfers()
{
return $this->_transfers;
}
}
Loading

0 comments on commit 2936e36

Please sign in to comment.