Added RevenueWithdrawalState objects
This commit is contained in:
parent
6839980fdb
commit
07140aa08f
5 changed files with 189 additions and 0 deletions
10
src/TgBotLib/Enums/Types/RevenueWithdrawalType.php
Normal file
10
src/TgBotLib/Enums/Types/RevenueWithdrawalType.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Enums\Types;
|
||||||
|
|
||||||
|
enum RevenueWithdrawalType : string
|
||||||
|
{
|
||||||
|
case PENDING = 'pending';
|
||||||
|
case SUCCEEDED = 'succeed';
|
||||||
|
case FAILED = 'failed';
|
||||||
|
}
|
44
src/TgBotLib/Objects/Payments/RevenueWithdrawalState.php
Normal file
44
src/TgBotLib/Objects/Payments/RevenueWithdrawalState.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects\Payments;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use TgBotLib\Enums\Types\RevenueWithdrawalType;
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
use TgBotLib\Objects\Payments\RevenueWithdrawalState\RevenueWithdrawalStateFailed;
|
||||||
|
use TgBotLib\Objects\Payments\RevenueWithdrawalState\RevenueWithdrawalStatePending;
|
||||||
|
use TgBotLib\Objects\Payments\RevenueWithdrawalState\RevenueWithdrawalStateSucceeded;
|
||||||
|
|
||||||
|
abstract class RevenueWithdrawalState implements ObjectTypeInterface
|
||||||
|
{
|
||||||
|
protected RevenueWithdrawalType $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public abstract function toArray(): ?array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function fromArray(?array $data): ?RevenueWithdrawalState
|
||||||
|
{
|
||||||
|
if(is_null($data))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($data['type']))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('type is not provided');
|
||||||
|
}
|
||||||
|
|
||||||
|
return match(RevenueWithdrawalType::tryFrom($data['type']))
|
||||||
|
{
|
||||||
|
RevenueWithdrawalType::SUCCEEDED => RevenueWithdrawalStateSucceeded::fromArray($data),
|
||||||
|
RevenueWithdrawalType::FAILED => RevenueWithdrawalStateFailed::fromArray($data),
|
||||||
|
RevenueWithdrawalType::PENDING => RevenueWithdrawalStatePending::fromArray($data),
|
||||||
|
default => throw new InvalidArgumentException('Unknown RevenueWithdrawalType')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects\Payments\RevenueWithdrawalState;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\RevenueWithdrawalType;
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
use TgBotLib\Objects\Payments\RevenueWithdrawalState;
|
||||||
|
|
||||||
|
class RevenueWithdrawalStateFailed extends RevenueWithdrawalState implements ObjectTypeInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function toArray(): ?array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => $this->type->value,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function fromArray(?array $data): ?RevenueWithdrawalStateFailed
|
||||||
|
{
|
||||||
|
if (is_null($data))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new self();
|
||||||
|
$object->type = RevenueWithdrawalType::FAILED;
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects\Payments\RevenueWithdrawalState;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\RevenueWithdrawalType;
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
use TgBotLib\Objects\Payments\RevenueWithdrawalState;
|
||||||
|
|
||||||
|
class RevenueWithdrawalStatePending extends RevenueWithdrawalState implements ObjectTypeInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function toArray(): ?array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => $this->type->value,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function fromArray(?array $data): ?RevenueWithdrawalStatePending
|
||||||
|
{
|
||||||
|
if (is_null($data))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new self();
|
||||||
|
$object->type = RevenueWithdrawalType::PENDING;
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Objects\Payments\RevenueWithdrawalState;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\RevenueWithdrawalType;
|
||||||
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
|
use TgBotLib\Objects\Payments\RevenueWithdrawalState;
|
||||||
|
|
||||||
|
class RevenueWithdrawalStateSucceeded extends RevenueWithdrawalState implements ObjectTypeInterface
|
||||||
|
{
|
||||||
|
private int $date;
|
||||||
|
private string $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date the withdrawal was completed in Unix time
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getDate(): int
|
||||||
|
{
|
||||||
|
return $this->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An HTTPS URL that can be used to see transaction details
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getUrl(): string
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function toArray(): ?array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => $this->type->value,
|
||||||
|
'date' => $this->date,
|
||||||
|
'url' => $this->url,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function fromArray(?array $data): ?RevenueWithdrawalStateSucceeded
|
||||||
|
{
|
||||||
|
if (is_null($data))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new self();
|
||||||
|
$object->type = RevenueWithdrawalType::SUCCEEDED;
|
||||||
|
$object->date = $data['date'];
|
||||||
|
$object->url = $data['url'];
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue