Added method GetSTarTransactions

This commit is contained in:
netkas 2024-11-27 15:04:15 -05:00
parent 672ab564c2
commit 53acc6c664
4 changed files with 210 additions and 0 deletions

View file

@ -60,6 +60,7 @@
use TgBotLib\Methods\GetMyDescription; use TgBotLib\Methods\GetMyDescription;
use TgBotLib\Methods\GetMyName; use TgBotLib\Methods\GetMyName;
use TgBotLib\Methods\GetMyShortDescription; use TgBotLib\Methods\GetMyShortDescription;
use TgBotLib\Methods\GetStarTransactions;
use TgBotLib\Methods\GetStickerSet; use TgBotLib\Methods\GetStickerSet;
use TgBotLib\Methods\GetUpdates; use TgBotLib\Methods\GetUpdates;
use TgBotLib\Methods\GetUserChatBoosts; use TgBotLib\Methods\GetUserChatBoosts;
@ -247,6 +248,7 @@
case CREATE_INVOICE_LINK = 'createInvoiceLink'; case CREATE_INVOICE_LINK = 'createInvoiceLink';
case ANSWER_SHIPPING_QUERY = 'answerShippingQuery'; case ANSWER_SHIPPING_QUERY = 'answerShippingQuery';
case ANSWER_PRE_CHECKOUT_QUERY = 'answerPreCheckoutQuery'; case ANSWER_PRE_CHECKOUT_QUERY = 'answerPreCheckoutQuery';
case GET_STAR_TRANSACTIONS = 'getStarTransactions';
/** /**
* Executes a command on the provided bot with the given parameters. * Executes a command on the provided bot with the given parameters.
@ -380,6 +382,7 @@
self::CREATE_INVOICE_LINK => CreateInvoiceLink::execute($bot, $parameters), self::CREATE_INVOICE_LINK => CreateInvoiceLink::execute($bot, $parameters),
self::ANSWER_SHIPPING_QUERY => AnswerShippingQuery::execute($bot, $parameters), self::ANSWER_SHIPPING_QUERY => AnswerShippingQuery::execute($bot, $parameters),
self::ANSWER_PRE_CHECKOUT_QUERY => AnswerPreCheckoutQuery::execute($bot, $parameters), self::ANSWER_PRE_CHECKOUT_QUERY => AnswerPreCheckoutQuery::execute($bot, $parameters),
self::GET_STAR_TRANSACTIONS => GetStarTransactions::execute($bot, $parameters),
}; };
} }
} }

View file

@ -0,0 +1,39 @@
<?php
namespace TgBotLib\Methods;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
use TgBotLib\Enums\Methods;
use TgBotLib\Objects\StarTransactions;
class GetStarTransactions extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): StarTransactions
{
return StarTransactions::fromArray(self::executeCurl(self::buildPost($bot, Methods::GET_STAR_TRANSACTIONS->value, $parameters)));
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return null;
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'offset',
'limit'
];
}
}

View file

@ -0,0 +1,112 @@
<?php
namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Payments\TransactionPartner;
class StarTransaction implements ObjectTypeInterface
{
private string $id;
private int $amount;
private int $date;
private ?TransactionPartner $source;
private ?TransactionPartner $receiver;
/**
* Describes a Telegram Star transaction.
*
* @param array|null $data
*/
public function __construct(?array $data=null)
{
if($data == null)
{
return;
}
$this->id = $data['id'];
$this->amount = $data['amount'];
$this->date = $data['date'];
$this->source = isset($data['source']) ? TransactionPartner::fromArray($data['source']) : null;
$this->receiver = isset($data['receiver']) ? TransactionPartner::fromArray($data['receiver']) : null;
}
/**
* Unique identifier of the transaction. Coincides with the identifier of the original transaction for
* refund transactions. Coincides with SuccessfulPayment.telegram_payment_charge_id for
* successful incoming payments from users.
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Number of Telegram Stars transferred by the transaction
*
* @return int
*/
public function getAmount(): int
{
return $this->amount;
}
/**
* Date the transaction was created in Unix time
*
* @return int
*/
public function getDate(): int
{
return $this->date;
}
/**
* Optional. Source of an incoming transaction
* (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal).
* Only for incoming transactions
*
* @return TransactionPartner|null
*/
public function getSource(): ?TransactionPartner
{
return $this->source;
}
/**
* Optional. Receiver of an outgoing transaction
* (e.g., a user for a purchase refund, Fragment for a withdrawal).
* Only for outgoing transactions
*
* @return TransactionPartner|null
*/
public function getReceiver(): ?TransactionPartner
{
return $this->receiver;
}
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'id' => $this->id,
'amount' => $this->amount,
'date' => $this->date,
'source' => $this->source,
'receiver' => $this->receiver
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?StarTransaction
{
return new self($data);
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace TgBotLib\Objects;
use TgBotLib\Interfaces\ObjectTypeInterface;
class StarTransactions implements ObjectTypeInterface
{
/**
* @var StarTransaction[]
*/
private array $transactions;
/**
* Contains a list of Telegram Star transactions.
*
* @param array|null $data
*/
public function __construct(?array $data=null)
{
if($data == null)
{
return;
}
$this->transactions = array_map(fn(array $items) => StarTransaction::fromArray($items), $data['transactions'] ?? []);
}
/**
* The list of transactions
*
* @return StarTransaction[]
*/
public function getTransactions(): array
{
return $this->transactions;
}
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'transactions' => array_map(fn(StarTransaction $item) => $item->toArray(), $this->transactions)
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?StarTransactions
{
return new self($data);
}
}