diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index c1af45c5f..88983c580 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -3941,6 +3941,7 @@ void HistoryItem::createServiceFromMtp(const MTPDmessageService &message) { payment->slug = data.vinvoice_slug().value_or_empty(); payment->recurringInit = data.is_recurring_init(); payment->recurringUsed = data.is_recurring_used(); + payment->isCreditsCurrency = (currency == Ui::kCreditsCurrency); payment->amount = Ui::FillAmountAndCurrency(amount, currency); payment->invoiceLink = std::make_shared([=]( ClickContext context) { diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index 906fe18ce..8d262a52e 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -653,6 +653,7 @@ struct HistoryServicePayment ClickHandlerPtr invoiceLink; bool recurringInit = false; bool recurringUsed = false; + bool isCreditsCurrency = false; }; struct HistoryServiceSameBackground diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.cpp b/Telegram/SourceFiles/payments/payments_checkout_process.cpp index 597d7687b..3080c149b 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.cpp +++ b/Telegram/SourceFiles/payments/payments_checkout_process.cpp @@ -415,6 +415,11 @@ void CheckoutProcess::handleFormUpdate(const FormUpdate &update) { _nonPanelPaymentFormProcess( std::make_shared(data.data)); } + }, [&](const CreditsReceiptReady &data) { + if (_nonPanelPaymentFormProcess) { + _nonPanelPaymentFormProcess( + std::make_shared(data.data)); + } }, [&](const Error &error) { handleError(error); }); diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.h b/Telegram/SourceFiles/payments/payments_checkout_process.h index 2f939d5a6..3c7f112ca 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.h +++ b/Telegram/SourceFiles/payments/payments_checkout_process.h @@ -41,6 +41,7 @@ struct InvoiceCredits; struct InvoiceId; struct InvoicePremiumGiftCode; struct CreditsFormData; +struct CreditsReceiptData; enum class Mode { Payment, @@ -54,7 +55,9 @@ enum class CheckoutResult { Failed, }; -struct NonPanelPaymentForm : std::variant> { +struct NonPanelPaymentForm : std::variant< + std::shared_ptr, + std::shared_ptr> { using variant::variant; }; diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index c6ddd84a9..8dac6d0c5 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -499,12 +499,20 @@ void Form::processReceipt(const MTPDpayments_paymentReceipt &data) { void Form::processReceipt(const MTPDpayments_paymentReceiptStars &data) { _session->data().processUsers(data.vusers()); - data.vinvoice().match([&](const auto &data) { - processInvoice(data); - }); - processDetails(data); - fillPaymentMethodInformation(); - _updates.fire(FormReady{}); + const auto receiptData = CreditsReceiptData{ + .id = qs(data.vtransaction_id()), + .title = qs(data.vtitle()), + .description = qs(data.vdescription()), + .photo = data.vphoto() + ? _session->data().photoFromWeb( + *data.vphoto(), + ImageLocation()) + : nullptr, + .peerId = peerFromUser(data.vbot_id().v), + .credits = data.vtotal_amount().v, + .date = data.vdate().v, + }; + _updates.fire(CreditsReceiptReady{ .data = receiptData }); } void Form::processInvoice(const MTPDinvoice &data) { diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index 6507ffa13..cf4cef890 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -187,6 +187,16 @@ struct CreditsFormData { MTPInputInvoice inputInvoice; }; +struct CreditsReceiptData { + QString id; + QString title; + QString description; + PhotoData *photo = nullptr; + PeerId peerId = PeerId(0); + uint64 credits = 0; + TimeId date = 0; +}; + struct ToggleProgress { bool shown = true; }; @@ -212,6 +222,9 @@ struct PaymentFinished { struct CreditsPaymentStarted { CreditsFormData data; }; +struct CreditsReceiptReady { + CreditsReceiptData data; +}; struct Error { enum class Type { None, @@ -244,6 +257,7 @@ struct FormUpdate : std::variant< BotTrustRequired, PaymentFinished, CreditsPaymentStarted, + CreditsReceiptReady, Error> { using variant::variant; }; diff --git a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp index 47232ac8a..2369d3d5d 100644 --- a/Telegram/SourceFiles/payments/payments_non_panel_process.cpp +++ b/Telegram/SourceFiles/payments/payments_non_panel_process.cpp @@ -7,18 +7,25 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "payments/payments_non_panel_process.h" +#include "base/unixtime.h" +#include "boxes/send_credits_box.h" +#include "data/data_credits.h" +#include "history/history_item.h" +#include "history/history_item_components.h" #include "payments/payments_checkout_process.h" // NonPanelPaymentForm. #include "payments/payments_form.h" -#include "history/history_item.h" +#include "settings/settings_credits.h" #include "ui/layers/generic_box.h" #include "ui/text/format_values.h" #include "window/window_session_controller.h" -#include "boxes/send_credits_box.h" namespace Payments { namespace { bool IsCreditsInvoice(not_null item) { + if (const auto payment = item->Get()) { + return payment->isCreditsCurrency; + } const auto media = item->media(); const auto invoice = media ? media->invoice() : nullptr; return invoice && (invoice->currency == Ui::kCreditsCurrency); @@ -30,9 +37,25 @@ Fn ProcessNonPanelPaymentFormFactory( not_null controller) { return [=](NonPanelPaymentForm form) { using CreditsFormDataPtr = std::shared_ptr; + using CreditsReceiptPtr = std::shared_ptr; if (const auto creditsData = std::get_if(&form)) { controller->uiShow()->show(Box(Ui::SendCreditsBox, *creditsData)); } + if (const auto r = std::get_if(&form)) { + const auto receipt = *r; + const auto entry = Data::CreditsHistoryEntry{ + .id = receipt->id, + .credits = receipt->credits, + .date = base::unixtime::parse(receipt->date), + .peerType = Data::CreditsHistoryEntry::PeerType::Peer, + .bareId = receipt->peerId.value, + }; + controller->uiShow()->show(Box( + Settings::ReceiptCreditsBox, + controller, + nullptr, + entry)); + } }; }