From 4735af473f0104db68ddc42d4a89c7290fde5469 Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 22 Nov 2024 15:18:02 -0500 Subject: [PATCH] Add SendInvoice method and object --- src/TgBotLib/Enums/Methods.php | 3 ++ src/TgBotLib/Methods/SendInvoice.php | 38 ++++++++++++++++ src/TgBotLib/Objects/SendInvoice.php | 65 ++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 src/TgBotLib/Objects/SendInvoice.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 5bbcddb..8749fd5 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -79,6 +79,7 @@ use TgBotLib\Methods\SendContact; use TgBotLib\Methods\SendDice; use TgBotLib\Methods\SendDocument; + use TgBotLib\Methods\SendInvoice; use TgBotLib\Methods\SendLocation; use TgBotLib\Methods\SendMediaGroup; use TgBotLib\Methods\SendMessage; @@ -239,6 +240,7 @@ case ANSWER_INLINE_QUERY = 'answerInlineQuery'; case ANSWER_WEB_APP_QUERY = 'answerWebAppQuery'; case SAVE_PREPARED_INLINE_MESSAGE = 'savePreparedInlineMessage'; + case SEND_INVOICE = 'sendInvoice'; /** * Executes a command on the provided bot with the given parameters. @@ -368,6 +370,7 @@ self::ANSWER_INLINE_QUERY => AnswerInlineQuery::execute($bot, $parameters), self::ANSWER_WEB_APP_QUERY => AnswerWebAppQuery::execute($bot, $parameters), self::SAVE_PREPARED_INLINE_MESSAGE => SavePreparedInlineMessage::execute($bot, $parameters), + self::SEND_INVOICE => SendInvoice::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Methods/SendInvoice.php b/src/TgBotLib/Methods/SendInvoice.php index 0df9e66..4f971b6 100644 --- a/src/TgBotLib/Methods/SendInvoice.php +++ b/src/TgBotLib/Methods/SendInvoice.php @@ -4,6 +4,7 @@ use TgBotLib\Abstracts\Method; use TgBotLib\Bot; + use TgBotLib\Enums\Methods; use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Objects\Message; @@ -22,10 +23,47 @@ { if($price instanceof ObjectTypeInterface) { + $prices[] = $price->toArray(); + } + if(is_array($price)) + { + $prices[] = $price; } } + + $parameters['prices'] = json_encode($parameters); } + + if(isset($parameters['suggested_tip_amounts']) && is_array($parameters['suggested_tip_amounts'])) + { + $parameters['suggested_tip_amounts'] = json_encode($parameters['suggested_tip_amounts']); + } + + if(isset($parameters['provider_data']) && is_array($parameters['provider_data'])) + { + $parameters['provider_data'] = json_encode($parameters['provider_data']) + } + + if(isset($parameters['reply_parameters']) && $parameters['reply_parameters'] instanceof ObjectTypeInterface) + { + $parameters['reply_parameters'] = $parameters['reply_parameters']->toArray(); + } + + if(isset($parameters['reply_markup'])) + { + if($parameters['reply_markup'] instanceof ObjectTypeInterface) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']->toArray()); + } + + if(is_array($parameters['reply_markup'])) + { + $parameters['reply_markup'] = json_encode($parameters['reply_markup']); + } + } + + return Message::fromArray(self::executeCurl(self::buildPost($bot, Methods::SEND_INVOICE->value, $parameters))); } /** diff --git a/src/TgBotLib/Objects/SendInvoice.php b/src/TgBotLib/Objects/SendInvoice.php new file mode 100644 index 0000000..d7537e0 --- /dev/null +++ b/src/TgBotLib/Objects/SendInvoice.php @@ -0,0 +1,65 @@ +