TelegramBot / Api

Native PHP Wrapper for Telegram BOT API
MIT License
1.06k stars 324 forks source link

SuccessfulPayment not work, error or misuse #374

Open studiosacchetti opened 1 year ago

studiosacchetti commented 1 year ago

hello i'm about to test payment capabilities, but it seem that SuccessfulPayment event not trigger, i'm i doing something wrong or what? preCheckoutQuery and answerPreCheckoutQuery phase work great!

  $bot->preCheckoutQuery(function ($message) use ($bot) {

        $bot->answerPreCheckoutQuery($message->getId(), true);
    });

    $bot->on(function (\TelegramBot\Api\Types\Payments\SuccessfulPayment $update) use ($bot) {

        $message = $update->getMessage();
        $id = $message->getChat()->getId();
        $bot->sendMessage($id, 'it work!');

    });
DewFill commented 1 year ago

I have the same issue. Have you found a workaround?

studiosacchetti commented 1 year ago

this work for me!

            /**
             * validate order
             */
            $bot->on(function (\TelegramBot\Api\Types\Update $update) use ($bot) {
                $message = $update->getMessage();             
                $id = $message->getChat()->getId();

                $successful_payment = $message->getSuccessfulPayment();
                if ($successful_payment) {
                             $bot->sendMessage($id, 'it work!');
                 }
            }, function () {
                        return true;
                    });