Initial Commit

This commit is contained in:
2024-02-08 12:07:49 -07:00
parent 5813b1109f
commit 43077b57ed
5471 changed files with 682195 additions and 0 deletions
@@ -0,0 +1,37 @@
<?php
/**
* The MIT License
*
* Copyright (c) 2020 "YooMoney", NBСO LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace YooKassa\Request\Payments\Payment;
use YooKassa\Request\Payments\AbstractPaymentResponse;
/**
* Класс объекта ответа от API на запрос отмены платежа
*
* @package YooKassa\Request\Payments\Payment
*/
class CancelResponse extends AbstractPaymentResponse
{}
@@ -0,0 +1,74 @@
<?php
/**
* The MIT License
*
* Copyright (c) 2020 "YooMoney", NBСO LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace YooKassa\Request\Payments\Payment;
use YooKassa\Common\AbstractPaymentRequest;
use YooKassa\Model\AmountInterface;
use YooKassa\Model\ReceiptInterface;
/**
* Класс объекта запроса к API на подтверждение оплаты
*
* @property AmountInterface $amount Подтверждаемая сумма оплаты
* @property ReceiptInterface $receipt Данные фискального чека 54-ФЗ
*/
class CreateCaptureRequest extends AbstractPaymentRequest implements CreateCaptureRequestInterface
{
/**
* Валидирует объект запроса
* @return bool True если запрос валиден и его можно отправить в API, false если нет
*/
public function validate()
{
if ($this->_amount !== null) {
$value = $this->_amount->getValue();
if (empty($value) || $value <= 0.0) {
$this->setValidationError('Invalid amount value: ' . $value);
return false;
}
}
if ($this->getReceipt() && $this->getReceipt()->notEmpty()) {
$email = $this->getReceipt()->getCustomer()->getEmail();
$phone = $this->getReceipt()->getCustomer()->getPhone();
if (empty($email) && empty($phone)) {
$this->setValidationError('Both email and phone values are empty in receipt');
return false;
}
}
return true;
}
/**
* Возвращает билдер объектов запросов на подтверждение оплаты
* @return CreateCaptureRequestBuilder Инстанс билдера
*/
public static function builder()
{
return new CreateCaptureRequestBuilder();
}
}
@@ -0,0 +1,75 @@
<?php
/**
* The MIT License
*
* Copyright (c) 2020 "YooMoney", NBСO LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace YooKassa\Request\Payments\Payment;
use YooKassa\Common\AbstractPaymentRequestBuilder;
use YooKassa\Common\Exceptions\InvalidPropertyException;
use YooKassa\Common\Exceptions\InvalidRequestException;
class CreateCaptureRequestBuilder extends AbstractPaymentRequestBuilder
{
/**
* @var CreateCaptureRequest
*/
protected $currentObject;
/**
* @return CreateCaptureRequest
*/
protected function initCurrentObject()
{
parent::initCurrentObject();
return new CreateCaptureRequest();
}
/**
* Осуществляет сборку объекта запроса к API
* @param array|null $options Массив дополнительных настроек объекта
* @return CreateCaptureRequestInterface Иснатс объекта запроса к API
*
* @throws InvalidRequestException Выбрасывается если при валидации запроса произошла ошибка
* @throws InvalidPropertyException Выбрасывается если не удалось установить один из параметров, переданных в
* массиве настроек
*/
public function build(array $options = null)
{
if (!empty($options)) {
$this->setOptions($options);
}
if (!empty($this->transfers)) {
$this->currentObject->setTransfers($this->transfers);
}
if ($this->amount->getValue() > 0) {
$this->currentObject->setAmount($this->amount);
}
if ($this->receipt->notEmpty()) {
$this->currentObject->setReceipt($this->receipt);
}
return parent::build();
}
}
@@ -0,0 +1,79 @@
<?php
/**
* The MIT License
*
* Copyright (c) 2020 "YooMoney", NBСO LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace YooKassa\Request\Payments\Payment;
use YooKassa\Model\AmountInterface;
use YooKassa\Model\MonetaryAmount;
use YooKassa\Model\ReceiptInterface;
use YooKassa\Model\TransferInterface;
/**
* Interface CreateCaptureRequestInterface
*
* @package YooKassa\Request\Payments\Payment
*
* @property-read MonetaryAmount $amount Подтверждаемая сумма оплаты
* @property-read ReceiptInterface $receipt Данные фискального чека 54-ФЗ
*/
interface CreateCaptureRequestInterface
{
/**
* Возвращает подтвердаемую сумму оплаты
* @return AmountInterface Подтверждаемая сумма оплаты
*/
function getAmount();
/**
* Проверяет была ли установлена сумма оплаты
* @return bool True если сумма оплаты была установлена, false если нет
*/
function hasAmount();
/**
* Возвращает чек, если он есть
* @return ReceiptInterface|null Данные фискального чека 54-ФЗ или null если чека нет
* @since 1.0.2
*/
function getReceipt();
/**
* Проверяет наличие чека в создаваемом платеже
* @return bool True если чек есть, false если нет
* @since 1.0.2
*/
function hasReceipt();
/**
* @return bool
*/
function hasTransfers();
/**
* @return TransferInterface[]
*/
function getTransfers();
}
@@ -0,0 +1,155 @@
<?php
/**
* The MIT License
*
* Copyright (c) 2020 "YooMoney", NBСO LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace YooKassa\Request\Payments\Payment;
use YooKassa\Model\AmountInterface;
use YooKassa\Model\ReceiptItem;
use YooKassa\Model\TransferInterface;
/**
* Класс объекта осуществляющего сериализацию запроса к API на подтверждение заказа
*
* @package YooKassa\Request\Payments\Payment
*/
class CreateCaptureRequestSerializer
{
/**
* Сериализует объект запроса к API на подтверждение заказа в ассоциативный массив
*
* @param CreateCaptureRequestInterface $request Сериализуемый объект запроса
*
* @return array Ассоциативный массив содержащий информацию для отправки в API
*/
public function serialize(CreateCaptureRequestInterface $request)
{
$result = array();
if ($request->hasAmount()) {
$result['amount'] = $this->serializeAmount($request->getAmount());
}
if ($request->hasTransfers()) {
$result['transfers'] = $this->serializeTransfers($request->getTransfers());
}
if ($request->hasReceipt()) {
$receipt = $request->getReceipt();
if ($receipt->notEmpty()) {
$result['receipt'] = array();
/** @var ReceiptItem $item */
foreach ($receipt->getItems() as $item) {
$itemArray = array(
'description' => $item->getDescription(),
'amount' => array(
'value' => $item->getPrice()->getValue(),
'currency' => $item->getPrice()->getCurrency(),
),
'quantity' => $item->getQuantity(),
'vat_code' => $item->getVatCode(),
);
if ($value = $item->getPaymentSubject()) {
$itemArray['payment_subject'] = $value;
}
if ($value = $item->getPaymentMode()) {
$itemArray['payment_mode'] = $value;
}
if ($value = $item->getProductCode()) {
$itemArray['product_code'] = $value;
}
if ($value = $item->getCountryOfOriginCode()) {
$itemArray['country_of_origin_code'] = $value;
}
if ($value = $item->getCustomsDeclarationNumber()) {
$itemArray['customs_declaration_number'] = $value;
}
if ($value = $item->getExcise()) {
$itemArray['excise'] = $value;
}
$result['receipt']['items'][] = $itemArray;
}
if ($customer = $receipt->getCustomer()) {
$customerArray = array();
if ($value = $customer->getEmail()) {
$customerArray['email'] = $value;
}
if ($value = $customer->getPhone()) {
$customerArray['phone'] = $value;
}
if ($value = $customer->getFullName()) {
$customerArray['full_name'] = $value;
}
if ($value = $customer->getInn()) {
$customerArray['inn'] = $value;
}
$result['receipt']['customer'] = $customerArray;
}
if ($value = $receipt->getTaxSystemCode()) {
$result['receipt']['tax_system_code'] = $value;
}
}
}
return $result;
}
private function serializeAmount(AmountInterface $amount)
{
return array(
'value' => $amount->getValue(),
'currency' => $amount->getCurrency(),
);
}
/**
* @param TransferInterface[] $transfers
*
* @return array
*/
private function serializeTransfers(array $transfers)
{
$result = array();
foreach ($transfers as $transfer) {
$result[] = array(
'account_id' => $transfer->getAccountId(),
'amount' => $this->serializeAmount($transfer->getAmount())
);
}
return $result;
}
}
@@ -0,0 +1,37 @@
<?php
/**
* The MIT License
*
* Copyright (c) 2020 "YooMoney", NBСO LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace YooKassa\Request\Payments\Payment;
use YooKassa\Request\Payments\AbstractPaymentResponse;
/**
* Класс объекта ответа от API на запрос подтверждения платежа
*
* @package YooKassa\Request\Payments\Payment
*/
class CreateCaptureResponse extends AbstractPaymentResponse
{}