From 7c895ec9bcafc170d50d23200e12d75e563a32ab Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 22 Nov 2024 15:27:14 -0500 Subject: [PATCH] Add CreateInvoiceLink method --- src/TgBotLib/Enums/Methods.php | 3 + src/TgBotLib/Objects/CreateInvoiceLink.php | 91 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/TgBotLib/Objects/CreateInvoiceLink.php diff --git a/src/TgBotLib/Enums/Methods.php b/src/TgBotLib/Enums/Methods.php index 8749fd5..e83cfea 100644 --- a/src/TgBotLib/Enums/Methods.php +++ b/src/TgBotLib/Enums/Methods.php @@ -121,6 +121,7 @@ use TgBotLib\Methods\UnpinAllGeneralForumTopicMessages; use TgBotLib\Methods\UnpinChatMessage; use TgBotLib\Methods\UploadStickerFile; + use TgBotLib\Objects\CreateInvoiceLink; enum Methods : string { @@ -241,6 +242,7 @@ case ANSWER_WEB_APP_QUERY = 'answerWebAppQuery'; case SAVE_PREPARED_INLINE_MESSAGE = 'savePreparedInlineMessage'; case SEND_INVOICE = 'sendInvoice'; + case CREATE_INVOICE_LINK = 'createInvoiceLink'; /** * Executes a command on the provided bot with the given parameters. @@ -371,6 +373,7 @@ 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), + self::CREATE_INVOICE_LINK => CreateInvoiceLink::execute($bot, $parameters), }; } } diff --git a/src/TgBotLib/Objects/CreateInvoiceLink.php b/src/TgBotLib/Objects/CreateInvoiceLink.php new file mode 100644 index 0000000..8567e21 --- /dev/null +++ b/src/TgBotLib/Objects/CreateInvoiceLink.php @@ -0,0 +1,91 @@ +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']); + } + + return (string)self::executeCurl(self::buildPost($bot, Methods::CREATE_INVOICE_LINK->value, $parameters)); + + } + + /** + * @inheritDoc + */ + public static function getRequiredParameters(): ?array + { + return [ + 'title', + 'description', + 'payload', + 'currency', + 'prices', + ]; + } + + /** + * @inheritDoc + */ + public static function getOptionalParameters(): ?array + { + return [ + 'business_connection_id', + 'provider_token', + 'subscription_period', + 'max_tip_amount', + 'suggested_tip_amounts', + 'provider_data', + 'photo_url', + 'photo_size', + 'photo_width', + 'photo_height', + 'need_name', + 'need_phone_number', + 'need_email', + 'need_shipping_address', + 'send_phone_number_to_provider', + 'send_email_to_provider', + 'is_flexible' + ]; + } + } \ No newline at end of file