Initial Commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace YooKassa\Model\Receipt;
|
||||
|
||||
|
||||
use YooKassa\Common\AbstractEnum;
|
||||
|
||||
class AgentType extends AbstractEnum
|
||||
{
|
||||
const BANKING_PAYMENT_AGENT = 'banking_payment_agent';
|
||||
const BANKING_PAYMENT_SUBAGENT = 'banking_payment_subagent';
|
||||
const PAYMENT_AGENT = 'payment_agent';
|
||||
const PAYMENT_SUBAGENT = 'payment_subagent';
|
||||
const ATTORNEY = 'attorney';
|
||||
const COMMISSIONER = 'commissioner';
|
||||
const AGENT = 'agent';
|
||||
|
||||
protected static $validValues = array(
|
||||
self::BANKING_PAYMENT_AGENT => true,
|
||||
self::BANKING_PAYMENT_SUBAGENT => true,
|
||||
self::PAYMENT_AGENT => true,
|
||||
self::PAYMENT_SUBAGENT => true,
|
||||
self::ATTORNEY => true,
|
||||
self::COMMISSIONER => true,
|
||||
self::AGENT => true,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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\Model\Receipt;
|
||||
|
||||
|
||||
use YooKassa\Common\AbstractEnum;
|
||||
|
||||
class PaymentMode extends AbstractEnum
|
||||
{
|
||||
const FULL_PREPAYMENT = 'full_prepayment';
|
||||
const PARTIAL_PREPAYMENT = 'partial_prepayment';
|
||||
const ADVANCE = 'advance';
|
||||
const FULL_PAYMENT = 'full_payment';
|
||||
const PARTIAL_PAYMENT = 'partial_payment';
|
||||
const CREDIT = 'credit';
|
||||
const CREDIT_PAYMENT = 'credit_payment';
|
||||
|
||||
protected static $validValues = array(
|
||||
self::FULL_PREPAYMENT => true,
|
||||
self::PARTIAL_PREPAYMENT => true,
|
||||
self::ADVANCE => true,
|
||||
self::FULL_PAYMENT => true,
|
||||
self::PARTIAL_PAYMENT => true,
|
||||
self::CREDIT => true,
|
||||
self::CREDIT_PAYMENT => true,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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\Model\Receipt;
|
||||
|
||||
|
||||
use YooKassa\Common\AbstractEnum;
|
||||
|
||||
class PaymentSubject extends AbstractEnum
|
||||
{
|
||||
const COMMODITY = 'commodity';
|
||||
const EXCISE = 'excise';
|
||||
const JOB = 'job';
|
||||
const SERVICE = 'service';
|
||||
const GAMBLING_BET = 'gambling_bet';
|
||||
const GAMBLING_PRIZE = 'gambling_prize';
|
||||
const LOTTERY = 'lottery';
|
||||
const LOTTERY_PRIZE = 'lottery_prize';
|
||||
const INTELLECTUAL_ACTIVITY = 'intellectual_activity';
|
||||
const PAYMENT = 'payment';
|
||||
const AGENT_COMMISSION = 'agent_commission';
|
||||
const PROPERTY_RIGHT = 'property_right';
|
||||
const NON_OPERATING_GAIN = 'non_operating_gain';
|
||||
const INSURANCE_PREMIUM = 'insurance_premium';
|
||||
const SALES_TAX = 'sales_tax';
|
||||
const RESORT_FEE = 'resort_fee';
|
||||
const COMPOSITE = 'composite';
|
||||
const ANOTHER = 'another';
|
||||
|
||||
protected static $validValues = array(
|
||||
self::COMMODITY => true,
|
||||
self::EXCISE => true,
|
||||
self::JOB => true,
|
||||
self::SERVICE => true,
|
||||
self::GAMBLING_BET => true,
|
||||
self::GAMBLING_PRIZE => true,
|
||||
self::LOTTERY => true,
|
||||
self::LOTTERY_PRIZE => true,
|
||||
self::INTELLECTUAL_ACTIVITY => true,
|
||||
self::PAYMENT => true,
|
||||
self::AGENT_COMMISSION => true,
|
||||
self::PROPERTY_RIGHT => true,
|
||||
self::NON_OPERATING_GAIN => true,
|
||||
self::INSURANCE_PREMIUM => true,
|
||||
self::SALES_TAX => true,
|
||||
self::RESORT_FEE => true,
|
||||
self::COMPOSITE => true,
|
||||
self::ANOTHER => true,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
<?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\Model\Receipt;
|
||||
|
||||
|
||||
use YooKassa\Common\AbstractObject;
|
||||
use YooKassa\Common\Exceptions\EmptyPropertyValueException;
|
||||
use YooKassa\Common\Exceptions\InvalidPropertyValueException;
|
||||
use YooKassa\Common\Exceptions\InvalidPropertyValueTypeException;
|
||||
use YooKassa\Helpers\TypeCast;
|
||||
use YooKassa\Model\AmountInterface;
|
||||
use YooKassa\Model\CurrencyCode;
|
||||
|
||||
/**
|
||||
* Class ReceiptItemAmount
|
||||
* @package YooKassa\Model\Receipt
|
||||
*
|
||||
* @method fromArray($sourceArray)
|
||||
*/
|
||||
class ReceiptItemAmount extends AbstractObject implements AmountInterface
|
||||
{
|
||||
/**
|
||||
* @var int Сумма
|
||||
*/
|
||||
private $_value = 0;
|
||||
|
||||
/**
|
||||
* @var string Код валюты
|
||||
*/
|
||||
private $_currency = CurrencyCode::RUB;
|
||||
|
||||
/**
|
||||
* MonetaryAmount constructor.
|
||||
* @param string|null $value Сумма
|
||||
* @param string|null $currency Код валюты
|
||||
*/
|
||||
public function __construct($value = null, $currency = null)
|
||||
{
|
||||
if ($value !== null && $value > 0.0) {
|
||||
$this->setValue($value);
|
||||
}
|
||||
if ($currency !== null) {
|
||||
$this->setCurrency($currency);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает значение суммы
|
||||
* @return string Сумма
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
if ($this->_value < 10) {
|
||||
return '0.0' . $this->_value;
|
||||
} elseif ($this->_value < 100) {
|
||||
return '0.' . $this->_value;
|
||||
} else {
|
||||
return substr($this->_value, 0, -2) . '.' . substr($this->_value, -2);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
throw new EmptyPropertyValueException('Empty amount value', 0, 'amount.value');
|
||||
}
|
||||
if (!is_numeric($value)) {
|
||||
throw new InvalidPropertyValueTypeException('Invalid amount value type', 0, 'amount.value', $value);
|
||||
}
|
||||
if ($value < 0.0) {
|
||||
throw new InvalidPropertyValueException('Invalid amount value: "'.$value.'"', 0, 'amount.value', $value);
|
||||
}
|
||||
$castedValue = (int)round($value * 100.0);
|
||||
if ($castedValue < 0.0) {
|
||||
throw new InvalidPropertyValueException('Invalid amount value: "'.$value.'"', 0, 'amount.value', $value);
|
||||
}
|
||||
$this->_value = $castedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает сумму в копейках в виде целого числа
|
||||
* @return int Сумма в копейках/центах
|
||||
*/
|
||||
public function getIntegerValue()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает валюту
|
||||
* @return string Код валюты
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->_currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает код валюты
|
||||
* @param string $value Код валюты
|
||||
*
|
||||
* @throws EmptyPropertyValueException Генерируется если было передано пустое значение
|
||||
* @throws InvalidPropertyValueTypeException Генерируется если было передано значение невалидного типа
|
||||
* @throws InvalidPropertyValueException Генерируется если был передан неподдерживаемый код валюты
|
||||
*/
|
||||
public function setCurrency($value)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
throw new EmptyPropertyValueException('Empty currency value', 0, 'amount.currency');
|
||||
}
|
||||
if (TypeCast::canCastToEnumString($value)) {
|
||||
$value = strtoupper((string)$value);
|
||||
if (CurrencyCode::valueExists($value)) {
|
||||
$this->_currency = $value;
|
||||
} else {
|
||||
throw new InvalidPropertyValueException(
|
||||
'Invalid currency value: "' . $value . '"', 0, 'amount.currency', $value
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidPropertyValueTypeException('Invalid currency value type', 0, 'amount.currency', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Умножает текущую сумму на указанный коэффициент
|
||||
* @param float $coefficient Множитель
|
||||
*
|
||||
* @throws EmptyPropertyValueException Выбрасывается если передано пустое значение
|
||||
* @throws InvalidPropertyValueTypeException Выбрасывается если было передано не число
|
||||
* @throws InvalidPropertyValueException Выбрасывается если переданное значение меньше или равно нулю, либо если
|
||||
* после умножения получили значение равное нулю
|
||||
*/
|
||||
public function multiply($coefficient)
|
||||
{
|
||||
if ($coefficient === null || $coefficient === '') {
|
||||
throw new EmptyPropertyValueException('Empty coefficient in multiply method', 0, 'amount.value');
|
||||
}
|
||||
if (!is_numeric($coefficient)) {
|
||||
throw new InvalidPropertyValueTypeException(
|
||||
'Invalid coefficient type in multiply method', 0, 'amount.value', $coefficient
|
||||
);
|
||||
}
|
||||
if ($coefficient <= 0.0) {
|
||||
throw new InvalidPropertyValueException(
|
||||
'Invalid coefficient in multiply method: "' . $coefficient . '"', 0, 'amount.value', $coefficient
|
||||
);
|
||||
}
|
||||
$castedValue = (int)round($coefficient * $this->_value);
|
||||
if ($castedValue === 0) {
|
||||
throw new InvalidPropertyValueException(
|
||||
'Invalid coefficient value in multiply method: "' . $coefficient . '"', 0, 'amount.value', $coefficient
|
||||
);
|
||||
}
|
||||
$this->_value = $castedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Увеличивает сумму на указанное значение
|
||||
* @param int $value Значение которое будет прибавлено к текущему
|
||||
*
|
||||
* @throws EmptyPropertyValueException Выбрасывается если передано пустое значение
|
||||
* @throws InvalidPropertyValueTypeException Выбрасывается если было передано не число
|
||||
* @throws InvalidPropertyValueException Выбрасывается если после сложения получилась сумма меньше или равная нулю
|
||||
*/
|
||||
public function increase($value)
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
throw new EmptyPropertyValueException('Empty amount value in increase method', 0, 'amount.value');
|
||||
}
|
||||
if (!is_numeric($value)) {
|
||||
throw new InvalidPropertyValueTypeException(
|
||||
'Invalid amount value type in increase method', 0, 'amount.value', $value
|
||||
);
|
||||
}
|
||||
$castedValue = (int)round($this->_value + $value * 100.0);
|
||||
if ($castedValue <= 0) {
|
||||
throw new InvalidPropertyValueException(
|
||||
'Invalid amount value in increase method: "' . $value . '"', 0, 'amount.value', $value
|
||||
);
|
||||
}
|
||||
$this->_value = $castedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return array(
|
||||
'value' => sprintf('%.2f',$this->_value / 100.0),
|
||||
'currency' => $this->_currency,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\Model\Receipt;
|
||||
|
||||
|
||||
use YooKassa\Common\AbstractEnum;
|
||||
|
||||
class SettlementType extends AbstractEnum
|
||||
{
|
||||
const CASHLESS = 'cashless';
|
||||
const PREPAYMENT = 'prepayment';
|
||||
const POSTPAYMENT = 'postpayment';
|
||||
const CONSIDERATION = 'consideration';
|
||||
|
||||
protected static $validValues = array(
|
||||
self::CASHLESS => true,
|
||||
self::PREPAYMENT => true,
|
||||
self::POSTPAYMENT => true,
|
||||
self::CONSIDERATION => true,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user