mirror of
https://git.yoomoney.ru/scm/sdk/yookassa-sdk-php.git
synced 2026-08-31 12:38:44 +00:00
@@ -1,3 +1,6 @@
|
||||
### v2.0.4 от 28.12.2020
|
||||
* Оптимизация получения списка платежей
|
||||
|
||||
### v2.0.3 от 10.12.2020
|
||||
* Возвращены методы для email и phone в receipt
|
||||
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
"email": "cms@yoomoney.ru"
|
||||
}
|
||||
],
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.4",
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"ext-curl": "*",
|
||||
|
||||
+2
-1
@@ -90,7 +90,7 @@ class Client extends BaseClient
|
||||
/**
|
||||
* Текущая версия библиотеки
|
||||
*/
|
||||
const SDK_VERSION = '2.0.3';
|
||||
const SDK_VERSION = '2.0.4';
|
||||
|
||||
/**
|
||||
* Получить список платежей магазина.
|
||||
@@ -107,6 +107,7 @@ class Client extends BaseClient
|
||||
* @throws TooManyRequestsException
|
||||
* @throws UnauthorizedException
|
||||
* @throws ExtensionNotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getPayments($filter = null)
|
||||
{
|
||||
|
||||
@@ -56,66 +56,66 @@ abstract class AbstractPaymentResponse extends Payment implements PaymentInterfa
|
||||
/**
|
||||
* Конструктор, устанавливает настройки платежа из ассоциативного массива
|
||||
*
|
||||
* @param array $paymentInfo Массив с информацией о платеже, пришедший от API
|
||||
* @param array $sourceArray Массив с информацией о платеже, пришедший от API
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($paymentInfo)
|
||||
public function fromArray($sourceArray)
|
||||
{
|
||||
$this->setId($paymentInfo['id']);
|
||||
$this->setStatus($paymentInfo['status']);
|
||||
$this->setAmount($this->factoryAmount($paymentInfo['amount']));
|
||||
$this->setCreatedAt($paymentInfo['created_at']);
|
||||
$this->setPaid($paymentInfo['paid']);
|
||||
$this->setRefundable($paymentInfo['refundable']);
|
||||
if (!empty($paymentInfo['test'])) {
|
||||
$this->setTest($paymentInfo['test']);
|
||||
$this->setId($sourceArray['id']);
|
||||
$this->setStatus($sourceArray['status']);
|
||||
$this->setAmount($this->factoryAmount($sourceArray['amount']));
|
||||
$this->setCreatedAt($sourceArray['created_at']);
|
||||
$this->setPaid($sourceArray['paid']);
|
||||
$this->setRefundable($sourceArray['refundable']);
|
||||
if (!empty($sourceArray['test'])) {
|
||||
$this->setTest($sourceArray['test']);
|
||||
}
|
||||
if (!empty($paymentInfo['payment_method'])) {
|
||||
$this->setPaymentMethod($this->factoryPaymentMethod($paymentInfo['payment_method']));
|
||||
if (!empty($sourceArray['payment_method'])) {
|
||||
$this->setPaymentMethod($this->factoryPaymentMethod($sourceArray['payment_method']));
|
||||
}
|
||||
|
||||
if (!empty($paymentInfo['description'])) {
|
||||
$this->setDescription($paymentInfo['description']);
|
||||
if (!empty($sourceArray['description'])) {
|
||||
$this->setDescription($sourceArray['description']);
|
||||
}
|
||||
|
||||
if (!empty($paymentInfo['recipient'])) {
|
||||
if (!empty($sourceArray['recipient'])) {
|
||||
$recipient = new Recipient();
|
||||
if (!empty($paymentInfo['recipient']['account_id'])) {
|
||||
$recipient->setAccountId($paymentInfo['recipient']['account_id']);
|
||||
if (!empty($sourceArray['recipient']['account_id'])) {
|
||||
$recipient->setAccountId($sourceArray['recipient']['account_id']);
|
||||
}
|
||||
if (!empty($paymentInfo['recipient']['gateway_id'])) {
|
||||
$recipient->setGatewayId($paymentInfo['recipient']['gateway_id']);
|
||||
if (!empty($sourceArray['recipient']['gateway_id'])) {
|
||||
$recipient->setGatewayId($sourceArray['recipient']['gateway_id']);
|
||||
}
|
||||
$this->setRecipient($recipient);
|
||||
}
|
||||
if (!empty($paymentInfo['captured_at'])) {
|
||||
$this->setCapturedAt(strtotime($paymentInfo['captured_at']));
|
||||
if (!empty($sourceArray['captured_at'])) {
|
||||
$this->setCapturedAt(strtotime($sourceArray['captured_at']));
|
||||
}
|
||||
if (!empty($paymentInfo['expires_at'])) {
|
||||
$this->setExpiresAt($paymentInfo['expires_at']);
|
||||
if (!empty($sourceArray['expires_at'])) {
|
||||
$this->setExpiresAt($sourceArray['expires_at']);
|
||||
}
|
||||
if (!empty($paymentInfo['confirmation'])) {
|
||||
$confirmationType = $paymentInfo['confirmation']['type'];
|
||||
if (!empty($sourceArray['confirmation'])) {
|
||||
$confirmationType = $sourceArray['confirmation']['type'];
|
||||
switch ($confirmationType) {
|
||||
case ConfirmationType::REDIRECT:
|
||||
$confirmation = new ConfirmationRedirect();
|
||||
if (!empty($paymentInfo['confirmation']['confirmation_url'])) {
|
||||
$confirmation->setConfirmationUrl($paymentInfo['confirmation']['confirmation_url']);
|
||||
if (!empty($sourceArray['confirmation']['confirmation_url'])) {
|
||||
$confirmation->setConfirmationUrl($sourceArray['confirmation']['confirmation_url']);
|
||||
}
|
||||
if (empty($paymentInfo['confirmation']['enforce'])) {
|
||||
if (empty($sourceArray['confirmation']['enforce'])) {
|
||||
$confirmation->setEnforce(false);
|
||||
} else {
|
||||
$confirmation->setEnforce($paymentInfo['confirmation']['enforce']);
|
||||
$confirmation->setEnforce($sourceArray['confirmation']['enforce']);
|
||||
}
|
||||
if (!empty($paymentInfo['confirmation']['return_url'])) {
|
||||
$confirmation->setReturnUrl($paymentInfo['confirmation']['return_url']);
|
||||
if (!empty($sourceArray['confirmation']['return_url'])) {
|
||||
$confirmation->setReturnUrl($sourceArray['confirmation']['return_url']);
|
||||
}
|
||||
break;
|
||||
|
||||
case ConfirmationType::EMBEDDED:
|
||||
$confirmation = new ConfirmationEmbedded();
|
||||
if (!empty($paymentInfo['confirmation']['confirmation_token'])) {
|
||||
$confirmation->setConfirmationToken($paymentInfo['confirmation']['confirmation_token']);
|
||||
if (!empty($sourceArray['confirmation']['confirmation_token'])) {
|
||||
$confirmation->setConfirmationToken($sourceArray['confirmation']['confirmation_token']);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -133,8 +133,8 @@ abstract class AbstractPaymentResponse extends Payment implements PaymentInterfa
|
||||
|
||||
case ConfirmationType::QR:
|
||||
$confirmation = new ConfirmationQr();
|
||||
if (!empty($paymentInfo['confirmation']['confirmation_data'])) {
|
||||
$confirmation->setConfirmationData($paymentInfo['confirmation']['confirmation_data']);
|
||||
if (!empty($sourceArray['confirmation']['confirmation_data'])) {
|
||||
$confirmation->setConfirmationData($sourceArray['confirmation']['confirmation_data']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -145,44 +145,44 @@ abstract class AbstractPaymentResponse extends Payment implements PaymentInterfa
|
||||
throw new InvalidArgumentException('confirmation type '.$confirmationType.' is incorrect');
|
||||
}
|
||||
}
|
||||
if (!empty($paymentInfo['refunded_amount'])) {
|
||||
$this->setRefundedAmount($this->factoryAmount($paymentInfo['refunded_amount']));
|
||||
if (!empty($sourceArray['refunded_amount'])) {
|
||||
$this->setRefundedAmount($this->factoryAmount($sourceArray['refunded_amount']));
|
||||
}
|
||||
if (!empty($paymentInfo['receipt_registration'])) {
|
||||
$this->setReceiptRegistration($paymentInfo['receipt_registration']);
|
||||
if (!empty($sourceArray['receipt_registration'])) {
|
||||
$this->setReceiptRegistration($sourceArray['receipt_registration']);
|
||||
}
|
||||
if (!empty($paymentInfo['metadata'])) {
|
||||
if (!empty($sourceArray['metadata'])) {
|
||||
$metadata = new Metadata();
|
||||
foreach ($paymentInfo['metadata'] as $key => $value) {
|
||||
foreach ($sourceArray['metadata'] as $key => $value) {
|
||||
$metadata->offsetSet($key, $value);
|
||||
}
|
||||
$this->setMetadata($metadata);
|
||||
}
|
||||
if (!empty($paymentInfo['cancellation_details'])) {
|
||||
$cancellationDetails = $paymentInfo['cancellation_details'];
|
||||
if (!empty($sourceArray['cancellation_details'])) {
|
||||
$cancellationDetails = $sourceArray['cancellation_details'];
|
||||
$party = isset($cancellationDetails['party']) ? $cancellationDetails['party'] : null;
|
||||
$reason = isset($cancellationDetails['reason']) ? $cancellationDetails['reason'] : null;
|
||||
$this->setCancellationDetails(new CancellationDetails($party, $reason));
|
||||
}
|
||||
if (!empty($paymentInfo['authorization_details'])) {
|
||||
$authorizationDetails = $paymentInfo['authorization_details'];
|
||||
if (!empty($sourceArray['authorization_details'])) {
|
||||
$authorizationDetails = $sourceArray['authorization_details'];
|
||||
$rrn = isset($authorizationDetails['rrn']) ? $authorizationDetails['rrn'] : null;
|
||||
$authCode = isset($authorizationDetails['auth_code']) ? $authorizationDetails['auth_code'] : null;
|
||||
$this->setAuthorizationDetails(new AuthorizationDetails($rrn, $authCode));
|
||||
}
|
||||
if (!empty($paymentInfo['transfers'])) {
|
||||
if (!empty($sourceArray['transfers'])) {
|
||||
$transfers = array();
|
||||
foreach ($paymentInfo['transfers'] as $transferDefinition) {
|
||||
foreach ($sourceArray['transfers'] as $transferDefinition) {
|
||||
$transfers[] = new Transfer($transferDefinition);
|
||||
}
|
||||
|
||||
$this->setTransfers($transfers);
|
||||
}
|
||||
if (!empty($paymentInfo['income_amount'])) {
|
||||
$this->setIncomeAmount($this->factoryAmount($paymentInfo['income_amount']));
|
||||
if (!empty($sourceArray['income_amount'])) {
|
||||
$this->setIncomeAmount($this->factoryAmount($sourceArray['income_amount']));
|
||||
}
|
||||
if (!empty($paymentInfo['requestor'])) {
|
||||
$this->setRequestor($paymentInfo['requestor']);
|
||||
if (!empty($sourceArray['requestor'])) {
|
||||
$this->setRequestor($sourceArray['requestor']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,25 +26,16 @@
|
||||
|
||||
namespace YooKassa\Request\Payments;
|
||||
|
||||
use YooKassa\Model\AuthorizationDetails;
|
||||
use YooKassa\Model\CancellationDetails;
|
||||
use YooKassa\Model\Confirmation\ConfirmationRedirect;
|
||||
use YooKassa\Model\Confirmation\ConfirmationExternal;
|
||||
use YooKassa\Model\ConfirmationType;
|
||||
use YooKassa\Model\Metadata;
|
||||
use YooKassa\Model\MonetaryAmount;
|
||||
use YooKassa\Model\Payment;
|
||||
use Exception;
|
||||
use YooKassa\Common\AbstractObject;
|
||||
use YooKassa\Model\PaymentInterface;
|
||||
use YooKassa\Model\PaymentMethod\AbstractPaymentMethod;
|
||||
use YooKassa\Model\PaymentMethod\PaymentMethodFactory;
|
||||
use YooKassa\Model\Recipient;
|
||||
|
||||
/**
|
||||
* Класс объекта ответа от API со списком платежей магазина
|
||||
*
|
||||
* @package YooKassa\Request\Payments
|
||||
*/
|
||||
class PaymentsResponse
|
||||
class PaymentsResponse extends AbstractObject
|
||||
{
|
||||
/**
|
||||
* @var PaymentInterface[] Массив платежей
|
||||
@@ -59,86 +50,18 @@ class PaymentsResponse
|
||||
/**
|
||||
* Конструктор, устанавливает свойства объекта из пришедшего из API ассоциативного массива
|
||||
*
|
||||
* @param array $options Массив настроек, пришедший от API
|
||||
* @throws \Exception
|
||||
* @param array $sourceArray Массив настроек, пришедший от API
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($options)
|
||||
public function fromArray($sourceArray)
|
||||
{
|
||||
$this->items = array();
|
||||
foreach ($options['items'] as $paymentInfo) {
|
||||
$payment = new Payment();
|
||||
$payment->setId($paymentInfo['id']);
|
||||
$payment->setStatus($paymentInfo['status']);
|
||||
$payment->setAmount(new MonetaryAmount(
|
||||
$paymentInfo['amount']['value'],
|
||||
$paymentInfo['amount']['currency']
|
||||
));
|
||||
if (!empty($paymentInfo['description'])) {
|
||||
$payment->setDescription($paymentInfo['description']);
|
||||
}
|
||||
$payment->setCreatedAt(strtotime($paymentInfo['created_at']));
|
||||
if (!empty($paymentInfo['payment_method'])
|
||||
&& $method = $this->factoryPaymentMethod($paymentInfo['payment_method'])) {
|
||||
$payment->setPaymentMethod($method);
|
||||
}
|
||||
$payment->setPaid($paymentInfo['paid']);
|
||||
$payment->setRefundable($paymentInfo['refundable']);
|
||||
|
||||
if (!empty($paymentInfo['recipient'])) {
|
||||
$recipient = new Recipient();
|
||||
$recipient->setAccountId($paymentInfo['recipient']['account_id']);
|
||||
$recipient->setGatewayId($paymentInfo['recipient']['gateway_id']);
|
||||
$payment->setRecipient($recipient);
|
||||
}
|
||||
if (!empty($paymentInfo['captured_at'])) {
|
||||
$payment->setCapturedAt(strtotime($paymentInfo['captured_at']));
|
||||
}
|
||||
if (!empty($paymentInfo['confirmation'])) {
|
||||
if ($paymentInfo['confirmation']['type'] === ConfirmationType::REDIRECT) {
|
||||
$confirmation = new ConfirmationRedirect();
|
||||
$confirmation->setConfirmationUrl($paymentInfo['confirmation']['confirmation_url']);
|
||||
if (!empty($paymentInfo['confirmation']['enforce'])) {
|
||||
$confirmation->setEnforce($paymentInfo['confirmation']['enforce']);
|
||||
}
|
||||
if (!empty($paymentInfo['confirmation']['return_url'])) {
|
||||
$confirmation->setReturnUrl($paymentInfo['confirmation']['return_url']);
|
||||
}
|
||||
} else {
|
||||
$confirmation = new ConfirmationExternal();
|
||||
}
|
||||
$payment->setConfirmation($confirmation);
|
||||
}
|
||||
if (!empty($paymentInfo['refunded_amount'])) {
|
||||
$payment->setRefundedAmount(new MonetaryAmount(
|
||||
$paymentInfo['refunded_amount']['value'], $paymentInfo['refunded_amount']['currency']
|
||||
));
|
||||
}
|
||||
if (!empty($paymentInfo['receipt_registration'])) {
|
||||
$payment->setReceiptRegistration($paymentInfo['receipt_registration']);
|
||||
}
|
||||
if (!empty($paymentInfo['metadata'])) {
|
||||
$metadata = new Metadata();
|
||||
foreach ($paymentInfo['metadata'] as $key => $value) {
|
||||
$metadata->offsetSet($key, $value);
|
||||
}
|
||||
$payment->setMetadata($metadata);
|
||||
}
|
||||
if (!empty($paymentInfo['cancellation_details'])) {
|
||||
$cancellationDetails = $paymentInfo['cancellation_details'];
|
||||
$party = isset($cancellationDetails['party']) ? $cancellationDetails['party'] : null;
|
||||
$reason = isset($cancellationDetails['reason']) ? $cancellationDetails['reason'] : null;
|
||||
$payment->setCancellationDetails(new CancellationDetails($party, $reason));
|
||||
}
|
||||
if (!empty($paymentInfo['authorization_details'])) {
|
||||
$authorizationDetails = $paymentInfo['authorization_details'];
|
||||
$rrn = isset($authorizationDetails['rrn']) ? $authorizationDetails['rrn'] : null;
|
||||
$authCode = isset($authorizationDetails['auth_code']) ? $authorizationDetails['auth_code'] : null;
|
||||
$payment->setAuthorizationDetails(new AuthorizationDetails($rrn, $authCode));
|
||||
}
|
||||
foreach ($sourceArray['items'] as $paymentInfo) {
|
||||
$payment = new PaymentResponse($paymentInfo);
|
||||
$this->items[] = $payment;
|
||||
}
|
||||
if (!empty($options['next_cursor'])) {
|
||||
$this->nextCursor = $options['next_cursor'];
|
||||
if (!empty($sourceArray['next_cursor'])) {
|
||||
$this->nextCursor = $sourceArray['next_cursor'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,19 +92,4 @@ class PaymentsResponse
|
||||
return $this->nextCursor !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Фабричный метод для создания объектов методов оплаты
|
||||
*
|
||||
* @param array $options Массив настроек метода оплаты
|
||||
*
|
||||
* @return AbstractPaymentMethod Используемый способ оплаты
|
||||
*/
|
||||
private function factoryPaymentMethod($options)
|
||||
{
|
||||
if (empty($options)) return null;
|
||||
|
||||
$factory = new PaymentMethodFactory();
|
||||
|
||||
return $factory->factoryFromArray($options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user