Add SendInvoice method and object

This commit is contained in:
netkas 2024-11-22 15:18:02 -05:00
parent cef24db929
commit 4735af473f
3 changed files with 106 additions and 0 deletions

View file

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

View file

@ -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)));
}
/**

View file

@ -0,0 +1,65 @@
<?php
namespace TgBotLib\Objects;
use TgBotLib\Abstracts\Method;
use TgBotLib\Bot;
class SendInvoice extends Method
{
/**
* @inheritDoc
*/
public static function execute(Bot $bot, array $parameters = []): Message
{
}
/**
* @inheritDoc
*/
public static function getRequiredParameters(): ?array
{
return [
'chat_id',
'title',
'description',
'payload',
'currency',
'prices',
];
}
/**
* @inheritDoc
*/
public static function getOptionalParameters(): ?array
{
return [
'message_thread_id',
'provider_token',
'max_tip_amount',
'suggested_tip_amounts',
'start_parameter',
'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',
'disable_notification',
'protect_content',
'allow_paid_broadcast',
'message_effect_id',
'reply_parameters',
'reply_markup'
];
}
}