From 9a5923676ab207bc83bcb64d19af4275f59f5a78 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 28 May 2024 16:00:35 +0300 Subject: [PATCH] Added posting of payment event to webview bot after credits sending. --- Telegram/SourceFiles/boxes/send_credits_box.cpp | 1 - .../inline_bots/bot_attach_web_view.cpp | 3 ++- .../payments/payments_non_panel_process.cpp | 17 +++++++++++++++-- .../payments/payments_non_panel_process.h | 4 +++- .../settings/settings_credits_graphics.cpp | 1 - 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/boxes/send_credits_box.cpp b/Telegram/SourceFiles/boxes/send_credits_box.cpp index 309f4833c..2873b4ffe 100644 --- a/Telegram/SourceFiles/boxes/send_credits_box.cpp +++ b/Telegram/SourceFiles/boxes/send_credits_box.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "payments/payments_checkout_process.h" #include "payments/payments_form.h" -#include "payments/payments_form.h" #include "settings/settings_credits_graphics.h" #include "ui/controls/userpic_button.h" #include "ui/effects/premium_graphics.h" diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 03561bdd6..68da29a3a 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -610,7 +610,8 @@ void AttachWebView::botHandleInvoice(QString slug) { reactivate, _context ? Payments::ProcessNonPanelPaymentFormFactory( - _context->controller.get()) + _context->controller.get(), + reactivate) : nullptr); } diff --git a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp index 62a3b4681..efab4dd89 100644 --- a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp +++ b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp @@ -40,7 +40,8 @@ bool IsCreditsInvoice(not_null item) { } // namespace Fn ProcessNonPanelPaymentFormFactory( - not_null controller) { + not_null controller, + Fn maybeReturnToBot) { return [=](NonPanelPaymentForm form) { using CreditsFormDataPtr = std::shared_ptr; using CreditsReceiptPtr = std::shared_ptr; @@ -51,12 +52,24 @@ Fn ProcessNonPanelPaymentFormFactory( controller->session().user()); const auto sendBox = [=, weak = base::make_weak(controller)] { if (const auto strong = weak.get()) { - controller->uiShow()->show(Box( + const auto unsuccessful = std::make_shared(true); + const auto box = controller->uiShow()->show(Box( Ui::SendCreditsBox, form, crl::guard(strong, [=] { + *unsuccessful = false; Ui::StartFireworks(strong->content()); + if (maybeReturnToBot) { + maybeReturnToBot(CheckoutResult::Paid); + } }))); + box->boxClosing() | rpl::start_with_next([=] { + crl::on_main([=] { + if ((*unsuccessful) && maybeReturnToBot) { + maybeReturnToBot(CheckoutResult::Cancelled); + } + }); + }, box->lifetime()); } }; const auto weak = base::make_weak(controller); diff --git a/Telegram/SourceFiles/payments/payments_non_panel_process.h b/Telegram/SourceFiles/payments/payments_non_panel_process.h index 76939415d..fb647a72a 100644 --- a/Telegram/SourceFiles/payments/payments_non_panel_process.h +++ b/Telegram/SourceFiles/payments/payments_non_panel_process.h @@ -15,10 +15,12 @@ class SessionController; namespace Payments { +enum class CheckoutResult; struct NonPanelPaymentForm; Fn ProcessNonPanelPaymentFormFactory( - not_null controller); + not_null controller, + Fn maybeReturnToBot = nullptr); Fn ProcessNonPanelPaymentFormFactory( not_null controller, diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index 0cd0ae1a2..066adf6f0 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -23,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common_session.h" #include "settings/settings_credits_graphics.h" #include "statistics/widgets/chart_header_widget.h" -#include "ui/boxes/boost_box.h" // Ui::StartFireworks. #include "ui/controls/userpic_button.h" #include "ui/effects/credits_graphics.h" #include "ui/effects/premium_graphics.h"