From 53acc6c6645abba1aabec8f979af0341d577822e Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 27 Nov 2024 15:04:15 -0500 Subject: [PATCH] Added method GetSTarTransactions --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Methods/GetStarTransactions.php | 39 +++++++ src/TgBotLib/Objects/StarTransaction.php | 112 +++++++++++++++++++ src/TgBotLib/Objects/StarTransactions.php | 56 ++++++++++ 4 files changed, 210 insertions(+) create mode 100644 src/TgBotLib/Methods/GetStarTransactions.php create mode 100644 src/TgBotLib/Objects/StarTransaction.php create mode 100644 src/TgBotLib/Objects/StarTransactions.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 0807f4c..7912128 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -60,6 +60,7 @@ use TgBotLib\Methods\GetMyDescription; use TgBotLib\Methods\GetMyName; use TgBotLib\Methods\GetMyShortDescription; + use TgBotLib\Methods\GetStarTransactions; use TgBotLib\Methods\GetStickerSet; use TgBotLib\Methods\GetUpdates; use TgBotLib\Methods\GetUserChatBoosts; @@ -247,6 +248,7 @@ case CREATE_INVOICE_LINK = 'createInvoiceLink'; case ANSWER_SHIPPING_QUERY = 'answerShippingQuery'; case ANSWER_PRE_CHECKOUT_QUERY = 'answerPreCheckoutQuery'; + case GET_STAR_TRANSACTIONS = 'getStarTransactions'; /** * Executes a command on the provided bot with the given parameters. @@ -380,6 +382,7 @@ self::CREATE_INVOICE_LINK => CreateInvoiceLink::execute($bot, $parameters), self::ANSWER_SHIPPING_QUERY => AnswerShippingQuery::execute($bot, $parameters), self::ANSWER_PRE_CHECKOUT_QUERY => AnswerPreCheckoutQuery::execute($bot, $parameters), + self::GET_STAR_TRANSACTIONS => GetStarTransactions::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/GetStarTransactions.php b/src/TgBotLib/Methods/GetStarTransactions.php new file mode 100644 index 0000000..41812c1 --- /dev/null +++ b/src/TgBotLib/Methods/GetStarTransactions.php @@ -0,0 +1,39 @@ +value, $parameters))); + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return null; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'offset', + 'limit' + ]; + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/StarTransaction.php b/src/TgBotLib/Objects/StarTransaction.php new file mode 100644 index 0000000..76ca375 --- /dev/null +++ b/src/TgBotLib/Objects/StarTransaction.php @@ -0,0 +1,112 @@ +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); + } + } \ No newline at end of file diff --git a/src/TgBotLib/Objects/StarTransactions.php b/src/TgBotLib/Objects/StarTransactions.php new file mode 100644 index 0000000..a4e852c --- /dev/null +++ b/src/TgBotLib/Objects/StarTransactions.php @@ -0,0 +1,56 @@ +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); + } + } \ No newline at end of file