Add CreateInvoiceLink method
This commit is contained in:
parent
79b5869ae4
commit
7c895ec9bc
2 changed files with 94 additions and 0 deletions
|
@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
91
src/TgBotLib/Objects/CreateInvoiceLink.php
Normal file
91
src/TgBotLib/Objects/CreateInvoiceLink.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace TgBotLib\Objects;
|
||||
|
||||
use TgBotLib\Abstracts\Method;
|
||||
use TgBotLib\Bot;
|
||||
use TgBotLib\Enums\Methods;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
|
||||
class CreateInvoiceLink extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(Bot $bot, array $parameters = []): string
|
||||
{
|
||||
if(isset($parameters['prices']))
|
||||
{
|
||||
$prices = [];
|
||||
foreach($parameters['prices'] as $price)
|
||||
{
|
||||
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']);
|
||||
}
|
||||
|
||||
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'
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue