From c7f5a832830ff1bd126df975f3ee1113a24ac5f9 Mon Sep 17 00:00:00 2001 From: TiiFuchs <1958744+TiiFuchs@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:20:00 +0000 Subject: [PATCH] Update code to reflect latest changes to the Bot API documentation --- src/Layers/Generated.php | 2 +- src/Telegram/AffiliateInfo.php | 53 +++++++++++++++++++ src/Telegram/StarTransaction.php | 10 +++- src/Telegram/TransactionPartner.php | 1 + .../TransactionPartnerAffiliateProgram.php | 34 ++++++++++++ src/Telegram/TransactionPartnerUser.php | 12 +++-- 6 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 src/Telegram/AffiliateInfo.php create mode 100644 src/Telegram/TransactionPartnerAffiliateProgram.php diff --git a/src/Layers/Generated.php b/src/Layers/Generated.php index 0948223..1dc77d9 100644 --- a/src/Layers/Generated.php +++ b/src/Layers/Generated.php @@ -2440,7 +2440,7 @@ public function sendInvoice( * @param LabeledPrice[] $prices Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in Telegram Stars. * @param string $business_connection_id Unique identifier of the business connection on behalf of which the link will be created. For payments in Telegram Stars only. * @param string $provider_token Payment provider token, obtained via @BotFather. Pass an empty string for payments in Telegram Stars. - * @param int $subscription_period The number of seconds the subscription will be active for before the next payment. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. + * @param int $subscription_period The number of seconds the subscription will be active for before the next payment. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be 2592000 (30 days) if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must no exceed 2500 Telegram Stars. * @param int $max_tip_amount The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in Telegram Stars. * @param int[] $suggested_tip_amounts A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount. * @param string $provider_data JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. diff --git a/src/Telegram/AffiliateInfo.php b/src/Telegram/AffiliateInfo.php new file mode 100644 index 0000000..c7c0a0c --- /dev/null +++ b/src/Telegram/AffiliateInfo.php @@ -0,0 +1,53 @@ +Optional. The bot or the user that received an affiliate commission if it was received by a bot or a user */ + public ?User $affiliate_user = null; + + /** Optional. The chat that received an affiliate commission if it was received by a chat */ + public ?Chat $affiliate_chat = null; + + /** Optional. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds */ + public ?int $nanostar_amount = null; + + /** + * @param int $commission_per_mille The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars received by the bot from referred users + * @param int $amount Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for refunds + * @param User $affiliate_user Optional. The bot or the user that received an affiliate commission if it was received by a bot or a user + * @param Chat $affiliate_chat Optional. The chat that received an affiliate commission if it was received by a chat + * @param int $nanostar_amount Optional. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds + */ + public static function make( + int $commission_per_mille, + int $amount, + ?User $affiliate_user = null, + ?Chat $affiliate_chat = null, + ?int $nanostar_amount = null, + ): static { + return new static([ + 'commission_per_mille' => $commission_per_mille, + 'amount' => $amount, + 'affiliate_user' => $affiliate_user, + 'affiliate_chat' => $affiliate_chat, + 'nanostar_amount' => $nanostar_amount, + ]); + } +} diff --git a/src/Telegram/StarTransaction.php b/src/Telegram/StarTransaction.php index 238166b..bf630ca 100644 --- a/src/Telegram/StarTransaction.php +++ b/src/Telegram/StarTransaction.php @@ -16,12 +16,15 @@ class StarTransaction extends Type /** 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. */ public string $id; - /** Number of Telegram Stars transferred by the transaction */ + /** Integer amount of Telegram Stars transferred by the transaction */ public int $amount; /** Date the transaction was created in Unix time */ public int $date; + /** Optional. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999 */ + public ?int $nanostar_amount = null; + /** Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal). Only for incoming transactions */ public ?TransactionPartner $source = null; @@ -30,8 +33,9 @@ class StarTransaction extends Type /** * @param string $id 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. - * @param int $amount Number of Telegram Stars transferred by the transaction + * @param int $amount Integer amount of Telegram Stars transferred by the transaction * @param int $date Date the transaction was created in Unix time + * @param int $nanostar_amount Optional. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999 * @param TransactionPartner $source Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal). Only for incoming transactions * @param TransactionPartner $receiver Optional. Receiver of an outgoing transaction (e.g., a user for a purchase refund, Fragment for a withdrawal). Only for outgoing transactions */ @@ -39,6 +43,7 @@ public static function make( string $id, int $amount, int $date, + ?int $nanostar_amount = null, ?TransactionPartner $source = null, ?TransactionPartner $receiver = null, ): static { @@ -46,6 +51,7 @@ public static function make( 'id' => $id, 'amount' => $amount, 'date' => $date, + 'nanostar_amount' => $nanostar_amount, 'source' => $source, 'receiver' => $receiver, ]); diff --git a/src/Telegram/TransactionPartner.php b/src/Telegram/TransactionPartner.php index 13c98df..4cd6eba 100644 --- a/src/Telegram/TransactionPartner.php +++ b/src/Telegram/TransactionPartner.php @@ -22,6 +22,7 @@ public static function factory(array $data, ?Bot $bot = null): self { return match ($data['type']) { 'user' => new TransactionPartnerUser($data, $bot), + 'affiliate_program' => new TransactionPartnerAffiliateProgram($data, $bot), 'fragment' => new TransactionPartnerFragment($data, $bot), 'telegram_ads' => new TransactionPartnerTelegramAds($data, $bot), 'telegram_api' => new TransactionPartnerTelegramApi($data, $bot), diff --git a/src/Telegram/TransactionPartnerAffiliateProgram.php b/src/Telegram/TransactionPartnerAffiliateProgram.php new file mode 100644 index 0000000..24861af --- /dev/null +++ b/src/Telegram/TransactionPartnerAffiliateProgram.php @@ -0,0 +1,34 @@ +Optional. Information about the bot that sponsored the affiliate program */ + public ?User $sponsor_user = null; + + /** + * @param int $commission_per_mille The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users + * @param User $sponsor_user Optional. Information about the bot that sponsored the affiliate program + */ + public static function make(int $commission_per_mille, ?User $sponsor_user = null): static + { + return new static([ + 'commission_per_mille' => $commission_per_mille, + 'sponsor_user' => $sponsor_user, + ]); + } +} diff --git a/src/Telegram/TransactionPartnerUser.php b/src/Telegram/TransactionPartnerUser.php index 088eb1d..f22656d 100644 --- a/src/Telegram/TransactionPartnerUser.php +++ b/src/Telegram/TransactionPartnerUser.php @@ -17,6 +17,9 @@ class TransactionPartnerUser extends TransactionPartner /** Information about the user */ public User $user; + /** Optional. Information about the affiliate that received a commission via this transaction */ + public ?AffiliateInfo $affiliate = null; + /** Optional. Bot-specified invoice payload */ public ?string $invoice_payload = null; @@ -34,26 +37,29 @@ class TransactionPartnerUser extends TransactionPartner public ?string $paid_media_payload = null; /** Optional. The gift sent to the user by the bot */ - public ?string $gift = null; + public ?Gift $gift = null; /** * @param User $user Information about the user + * @param AffiliateInfo $affiliate Optional. Information about the affiliate that received a commission via this transaction * @param string $invoice_payload Optional. Bot-specified invoice payload * @param int $subscription_period Optional. The duration of the paid subscription * @param PaidMedia[] $paid_media Optional. Information about the paid media bought by the user * @param string $paid_media_payload Optional. Bot-specified paid media payload - * @param string $gift Optional. The gift sent to the user by the bot + * @param Gift $gift Optional. The gift sent to the user by the bot */ public static function make( User $user, + ?AffiliateInfo $affiliate = null, ?string $invoice_payload = null, ?int $subscription_period = null, ?array $paid_media = null, ?string $paid_media_payload = null, - ?string $gift = null, + ?Gift $gift = null, ): static { return new static([ 'user' => $user, + 'affiliate' => $affiliate, 'invoice_payload' => $invoice_payload, 'subscription_period' => $subscription_period, 'paid_media' => $paid_media,