Added RevenueWithdrawalState objects

This commit is contained in:
netkas 2024-10-04 15:44:37 -04:00
parent 6839980fdb
commit 07140aa08f
5 changed files with 189 additions and 0 deletions

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Enums\Types;
enum RevenueWithdrawalType : string
{
case PENDING = 'pending';
case SUCCEEDED = 'succeed';
case FAILED = 'failed';
}

View 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')
};
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}