From 1cc35080884f42925fb4c9644212c834716562d3 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sat, 29 Jun 2024 16:01:34 +0300 Subject: [PATCH] Add `refundStarPayment` method --- CHANGELOG.md | 1 + src/Method/Payment/RefundStarPayment.php | 45 +++++++++++++++++++ src/TelegramBotApi.php | 13 ++++++ .../Method/Payment/RefundStarPaymentTest.php | 36 +++++++++++++++ tests/TelegramBotApiTest.php | 12 +++++ 5 files changed, 107 insertions(+) create mode 100644 src/Method/Payment/RefundStarPayment.php create mode 100644 tests/Method/Payment/RefundStarPaymentTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 46dcf66..3b9d2bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ - New #81: Add `sendInvoice` method. - New #82: Add `createInvoiceLink` method. - New #83: Add `answerShippingQuery` and `answerPreCheckoutQuery` methods, and `ShippingOption` type. +- New #84: Add `refundStarPayment` method. - Chg #24: Move update methods to `Vjik\TelegramBot\Api\Method\Update` namespace, and update types to `Vjik\TelegramBot\Api\Type\Update` namespace. - Chg #30: Remove `TelegramRequestWithFilesInterface`. diff --git a/src/Method/Payment/RefundStarPayment.php b/src/Method/Payment/RefundStarPayment.php new file mode 100644 index 0000000..52b66e7 --- /dev/null +++ b/src/Method/Payment/RefundStarPayment.php @@ -0,0 +1,45 @@ + $this->userId, + 'telegram_payment_charge_id' => $this->telegramPaymentChargeId, + ]; + } + + public function prepareResult(mixed $result): true + { + ValueHelper::assertTrueResult($result); + return $result; + } +} diff --git a/src/TelegramBotApi.php b/src/TelegramBotApi.php index 18ddb91..f3300d6 100644 --- a/src/TelegramBotApi.php +++ b/src/TelegramBotApi.php @@ -55,6 +55,7 @@ use Vjik\TelegramBot\Api\Method\Payment\AnswerShippingQuery; use Vjik\TelegramBot\Api\Method\Payment\CreateInvoiceLink; use Vjik\TelegramBot\Api\Method\Payment\GetStarTransactions; +use Vjik\TelegramBot\Api\Method\Payment\RefundStarPayment; use Vjik\TelegramBot\Api\Method\Payment\SendInvoice; use Vjik\TelegramBot\Api\Method\PinChatMessage; use Vjik\TelegramBot\Api\Method\PromoteChatMember; @@ -1261,6 +1262,18 @@ public function promoteChatMember( ); } + /** + * @see https://core.telegram.org/bots/api#refundstarpayment + * + * @psalm-suppress MixedInferredReturnType,MixedReturnStatement + */ + public function refundStarPayment(int $userId, string $telegramPaymentChargeId): FailResult|true + { + return $this->send( + new RefundStarPayment($userId, $telegramPaymentChargeId) + ); + } + /** * @see https://core.telegram.org/bots/api#reopenforumtopic * diff --git a/tests/Method/Payment/RefundStarPaymentTest.php b/tests/Method/Payment/RefundStarPaymentTest.php new file mode 100644 index 0000000..50f742c --- /dev/null +++ b/tests/Method/Payment/RefundStarPaymentTest.php @@ -0,0 +1,36 @@ +assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('refundStarPayment', $method->getApiMethod()); + $this->assertSame( + [ + 'user_id' => 1, + 'telegram_payment_charge_id' => 'test', + ], + $method->getData() + ); + } + + public function testPrepareResult(): void + { + $method = new RefundStarPayment(1, 'test'); + + $preparedResult = $method->prepareResult(true); + + $this->assertTrue($preparedResult); + } +} diff --git a/tests/TelegramBotApiTest.php b/tests/TelegramBotApiTest.php index 52002f9..3529170 100644 --- a/tests/TelegramBotApiTest.php +++ b/tests/TelegramBotApiTest.php @@ -1130,6 +1130,18 @@ public function testPromoteChatMember(): void $this->assertTrue($result); } + public function testRefundStarPayment(): void + { + $api = $this->createApi([ + 'ok' => true, + 'result' => true, + ]); + + $result = $api->refundStarPayment(1, 'test'); + + $this->assertTrue($result); + } + public function testReopenForumTopic(): void { $api = $this->createApi([