Skip to content

Commit 4af6f4a

Browse files
authored
Merge branch 'danog:v8' into media_thumbs
2 parents 5085e4d + 3e4c678 commit 4af6f4a

File tree

10 files changed

+208
-7
lines changed

10 files changed

+208
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ Some of MadelineProto's core components are also available as separate, standalo
172172
* [danog\MadelineProto\EventHandler\Message\Service\DialogMemberLeft »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMemberLeft.html) - A member left the chat or channel.
173173
* [danog\MadelineProto\EventHandler\Message\Service\DialogMembersJoined »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMembersJoined.html) - Some members joined the chat or channel.
174174
* [danog\MadelineProto\EventHandler\Message\Service\DialogMessagePinned »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogMessagePinned.html) - A message was pinned in a chat.
175+
* [danog\MadelineProto\EventHandler\Message\Service\DialogPaymentSent »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPaymentSent.html) - A payment was sent.
176+
* [danog\MadelineProto\EventHandler\Message\Service\DialogPaymentSentMe »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPaymentSentMe.html) - A user just sent a payment to me (a bot).
175177
* [danog\MadelineProto\EventHandler\Message\Service\DialogPeerRequested »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPeerRequested.html) - Contains info about a peer that the user shared with the bot after clicking on a [keyboardButtonRequestPeer](https://docs.madelineproto.xyz/API_docs/constructors/keyboardButtonRequestPeer.html) button.
176178
* [danog\MadelineProto\EventHandler\Message\Service\DialogPhoneCall »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPhoneCall.html) - A phone call.
177179
* [danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged »](https://docs.madelineproto.xyz/PHP/danog/MadelineProto/EventHandler/Message/Service/DialogPhotoChanged.html) - The photo of the dialog was changed or deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of MadelineProto.
5+
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7+
* See the GNU Affero General Public License for more details.
8+
* You should have received a copy of the GNU General Public License along with MadelineProto.
9+
* If not, see <http://www.gnu.org/licenses/>.
10+
*
11+
* @author Mahdi <mahdi.talaee1379@gmail.com>
12+
* @copyright 2016-2025 Mahdi <mahdi.talaee1379@gmail.com>
13+
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
14+
* @link https://docs.madelineproto.xyz MadelineProto documentation
15+
*/
16+
17+
namespace danog\MadelineProto\EventHandler\Message\Service;
18+
19+
use danog\MadelineProto\EventHandler\Message\ServiceMessage;
20+
use danog\MadelineProto\MTProto;
21+
22+
/**
23+
* A payment was sent.
24+
*/
25+
class DialogPaymentSent extends ServiceMessage
26+
{
27+
public function __construct(
28+
MTProto $API,
29+
array $rawMessage,
30+
array $info,
31+
/** Whether this is the first payment of a recurring payment we just subscribed to */
32+
public readonly ?bool $recurringInit,
33+
/** Whether this payment is part of a recurring payment */
34+
public readonly ?bool $recurringUsed,
35+
/** Three-letter ISO 4217 currency code */
36+
public readonly string $currency,
37+
/** Price of the product in the smallest units of the currency */
38+
public readonly int $totalAmount,
39+
/** An invoice slug taken from an invoice deep link or from the premium_invoice_slug app config parameter */
40+
public readonly ?string $invoiceSlug,
41+
/** The date that subscription has been ended */
42+
public readonly ?int $subscriptionUntilDate
43+
) {
44+
parent::__construct($API, $rawMessage, $info);
45+
}
46+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of MadelineProto.
5+
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7+
* See the GNU Affero General Public License for more details.
8+
* You should have received a copy of the GNU General Public License along with MadelineProto.
9+
* If not, see <http://www.gnu.org/licenses/>.
10+
*
11+
* @author Mahdi <mahdi.talaee1379@gmail.com>
12+
* @copyright 2016-2025 Mahdi <mahdi.talaee1379@gmail.com>
13+
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
14+
* @link https://docs.madelineproto.xyz MadelineProto documentation
15+
*/
16+
17+
namespace danog\MadelineProto\EventHandler\Message\Service;
18+
19+
use danog\MadelineProto\EventHandler\Message\ServiceMessage;
20+
use danog\MadelineProto\EventHandler\Payments\PaymentCharge;
21+
use danog\MadelineProto\EventHandler\Payments\PaymentRequestedInfo;
22+
use danog\MadelineProto\MTProto;
23+
use danog\MadelineProto\TL\Types\Bytes;
24+
25+
/**
26+
* A user just sent a payment to me (a bot).
27+
*/
28+
class DialogPaymentSentMe extends ServiceMessage
29+
{
30+
public function __construct(
31+
MTProto $API,
32+
array $rawMessage,
33+
array $info,
34+
/** Whether this is the first payment of a recurring payment we just subscribed to */
35+
public readonly ?bool $recurringInit,
36+
/** Whether this payment is part of a recurring payment */
37+
public readonly ?bool $recurringUsed,
38+
/** Three-letter ISO 4217 currency code */
39+
public readonly string $currency,
40+
/** Price of the product in the smallest units of the currency */
41+
public readonly int $totalAmount,
42+
/** Bot specified invoice payload */
43+
public readonly Bytes $payload,
44+
/** Order info provided by the user */
45+
public readonly ?PaymentRequestedInfo $paymentInfo,
46+
/** Identifier of the shipping option chosen by the user */
47+
public readonly ?string $shippingOptionId,
48+
/** Provider payment identifier */
49+
public readonly PaymentCharge $charge,
50+
/** The date that subscription has been ended */
51+
public readonly ?int $subscriptionUntilDate
52+
) {
53+
parent::__construct($API, $rawMessage, $info);
54+
}
55+
56+
public function refundStars(
57+
int $userId
58+
): void {
59+
$this->getClient()->methodCallAsyncRead(
60+
'payments.refundStarsCharge',
61+
[
62+
'user_id' => $userId,
63+
'charge_id' => $this->charge->id,
64+
]
65+
);
66+
}
67+
}

src/EventHandler/Payments/Payment.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
use danog\MadelineProto\EventHandler\Update;
2020
use danog\MadelineProto\MTProto;
21+
use danog\MadelineProto\TL\Types\Bytes;
2122

2223
/**
2324
* This object contains information about an incoming pre-checkout query.
@@ -29,7 +30,7 @@ class Payment extends Update
2930
/** User who sent the query */
3031
public readonly int $userId;
3132
/** Bot specified invoice payload */
32-
public readonly string $payload;
33+
public readonly Bytes $payload;
3334
/** Order info provided by the user */
3435
public readonly ?PaymentRequestedInfo $info;
3536
/** Identifier of the shipping option chosen by the user */
@@ -45,7 +46,7 @@ public function __construct(MTProto $API, array $rawRequestedPayment)
4546
$this->queryId = $rawRequestedPayment['query_id'];
4647
$this->userId = $rawRequestedPayment['user_id'];
4748
$this->payload = $rawRequestedPayment['payload'];
48-
$this->info = isset($rawRequestedPayment['payload']) ? new PaymentRequestedInfo(
49+
$this->info = isset($rawRequestedPayment['info']) ? new PaymentRequestedInfo(
4950
$rawRequestedPayment['name'],
5051
$rawRequestedPayment['phone'],
5152
$rawRequestedPayment['email'],
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* This file is part of MadelineProto.
5+
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7+
* See the GNU Affero General Public License for more details.
8+
* You should have received a copy of the GNU General Public License along with MadelineProto.
9+
* If not, see <http://www.gnu.org/licenses/>.
10+
*
11+
* @author Mahdi <mahdi.talaee1379@gmail.com>
12+
* @copyright 2016-2025 Mahdi <mahdi.talaee1379@gmail.com>
13+
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
14+
* @link https://docs.madelineproto.xyz MadelineProto documentation
15+
*/
16+
17+
namespace danog\MadelineProto\EventHandler\Payments;
18+
19+
use JsonSerializable;
20+
use ReflectionClass;
21+
use ReflectionProperty;
22+
23+
/**
24+
* Payment identifier.
25+
*/
26+
class PaymentCharge implements JsonSerializable
27+
{
28+
29+
public function __construct(
30+
/** Telegram payment identifier */
31+
public readonly string $id,
32+
/** Provider payment identifier */
33+
public readonly string $providerChargeId
34+
) {
35+
36+
}
37+
38+
/** @internal */
39+
public function jsonSerialize(): mixed
40+
{
41+
$res = ['_' => static::class];
42+
$refl = new ReflectionClass($this);
43+
foreach ($refl->getProperties(ReflectionProperty::IS_PUBLIC) as $prop) {
44+
$res[$prop->getName()] = $prop->getValue($this);
45+
}
46+
return $res;
47+
}
48+
}

src/MTProtoTools/UpdateHandler.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
use danog\MadelineProto\EventHandler\Message\Service\DialogGameScore;
6767
use danog\MadelineProto\EventHandler\Message\Service\DialogGeoProximityReached;
6868
use danog\MadelineProto\EventHandler\Message\Service\DialogGiftPremium;
69+
use danog\MadelineProto\EventHandler\Message\Service\DialogGiftStars;
6970
use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCall;
7071
use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallInvited;
7172
use danog\MadelineProto\EventHandler\Message\Service\DialogGroupCall\GroupCallScheduled;
@@ -74,6 +75,8 @@
7475
use danog\MadelineProto\EventHandler\Message\Service\DialogMemberLeft;
7576
use danog\MadelineProto\EventHandler\Message\Service\DialogMembersJoined;
7677
use danog\MadelineProto\EventHandler\Message\Service\DialogMessagePinned;
78+
use danog\MadelineProto\EventHandler\Message\Service\DialogPaymentSent;
79+
use danog\MadelineProto\EventHandler\Message\Service\DialogPaymentSentMe;
7780
use danog\MadelineProto\EventHandler\Message\Service\DialogPeerRequested;
7881
use danog\MadelineProto\EventHandler\Message\Service\DialogPhoneCall;
7982
use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged;
@@ -89,6 +92,8 @@
8992
use danog\MadelineProto\EventHandler\Message\Service\DialogTopicEdited;
9093
use danog\MadelineProto\EventHandler\Message\Service\DialogWebView;
9194
use danog\MadelineProto\EventHandler\Payments\Payment;
95+
use danog\MadelineProto\EventHandler\Payments\PaymentCharge;
96+
use danog\MadelineProto\EventHandler\Payments\PaymentRequestedInfo;
9297
use danog\MadelineProto\EventHandler\Payments\StarGift;
9398
use danog\MadelineProto\EventHandler\Pinned;
9499
use danog\MadelineProto\EventHandler\Pinned\PinnedChannelMessages;
@@ -133,7 +138,6 @@
133138
use danog\MadelineProto\UpdateHandlerType;
134139
use danog\MadelineProto\VoIP\DiscardReason;
135140
use danog\MadelineProto\VoIPController;
136-
use DialogGiftStars;
137141
use Revolt\EventLoop;
138142
use SplQueue;
139143
use Throwable;
@@ -722,6 +726,38 @@ public function wrapMessage(array $message, bool $scheduled = false): ?AbstractM
722726
) : null,
723727
$message['action']['convert_stars'],
724728
),
729+
'messageActionPaymentSent' => new DialogPaymentSent(
730+
$this,
731+
$message,
732+
$info,
733+
$message['action']['recurring_init'] ?? null,
734+
$message['action']['recurring_used'] ?? null,
735+
$message['action']['currency'],
736+
$message['action']['total_amount'],
737+
$message['action']['invoice_slug'] ?? null,
738+
$message['action']['subscription_until_date'] ?? null
739+
),
740+
'messageActionPaymentSentMe' => new DialogPaymentSentMe(
741+
$this,
742+
$message,
743+
$info,
744+
$message['action']['recurring_init'] ?? null,
745+
$message['action']['recurring_used'] ?? null,
746+
$message['action']['currency'],
747+
$message['action']['total_amount'],
748+
$message['action']['payload'],
749+
isset($message['action']['info']) ? new PaymentRequestedInfo(
750+
$message['action']['info']['name'],
751+
$message['action']['info']['phone'],
752+
$message['action']['info']['email']
753+
) : null,
754+
$message['action']['shipping_option_id'] ?? null,
755+
new PaymentCharge(
756+
$message['action']['charge']['id'],
757+
$message['action']['charge']['provider_charge_id']
758+
),
759+
$message['action']['subscription_until_date'] ?? null
760+
),
725761
'messageActionGiftPremium' => new DialogGiftPremium(
726762
$this,
727763
$message,

src/RPCErrorException.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ public static function make(
644644
'STARGIFT_INVALID' => new self($rpc, 'The passed [inputInvoiceStarGift](https://core.telegram.org/constructor/inputInvoiceStarGift) is invalid.', $code, $caller, $previous),
645645
'STARGIFT_USAGE_LIMITED' => new self($rpc, 'The gift is sold out.', $code, $caller, $previous),
646646
'STARREF_AWAITING_END' => new self($rpc, 'The previous referral program was terminated less than 24 hours ago: further changes can be made after the date specified in userFull.starref_program.end_date.', $code, $caller, $previous),
647+
'STARREF_EXPIRED' => new self($rpc, 'The specified referral link is invalid.', $code, $caller, $previous),
647648
'STARREF_HASH_REVOKED' => new self($rpc, 'The specified affiliate link was already revoked.', $code, $caller, $previous),
648649
'STARREF_PERMILLE_INVALID' => new self($rpc, 'The specified commission_permille is invalid: the minimum and maximum values for this parameter are contained in the [starref_min_commission_permille](https://core.telegram.org/api/config#starref-min-commission-permille) and [starref_max_commission_permille](https://core.telegram.org/api/config#starref-max-commission-permille) client configuration parameters.', $code, $caller, $previous),
649650
'STARREF_PERMILLE_TOO_LOW' => new self($rpc, 'The specified commission_permille is too low: the minimum and maximum values for this parameter are contained in the [starref_min_commission_permille](https://core.telegram.org/api/config#starref-min-commission-permille) and [starref_max_commission_permille](https://core.telegram.org/api/config#starref-max-commission-permille) client configuration parameters.', $code, $caller, $previous),

src/v3.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tools/fuzzer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ function getTL(TLSchema $schema)
5454
$res = '';
5555

5656
echo "Bot login:".PHP_EOL;
57-
$bot = new \danog\MadelineProto\API('bot.madeline');
57+
$bot = new \danog\MadelineProto\API('fuzz_bot.madeline');
5858
$bot->start();
5959
$bot->updateSettings($schema);
6060
Assert::true($bot->isSelfBot(), "bot.madeline is not a bot!");
6161
$bot->restart();
6262

6363
echo "User login:".PHP_EOL;
64-
$user = new \danog\MadelineProto\API('user.madeline');
64+
$user = new \danog\MadelineProto\API('fuzz_user.madeline');
6565
$user->start();
6666
$user->updateSettings($schema);
6767
Assert::true($user->isSelfUser(), "user.madeline is not a user!");

0 commit comments

Comments
 (0)