summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author23rd <23rd@vivaldi.net>2024-05-24 22:20:41 +0300
committerJohn Preston <johnprestonmail@gmail.com>2024-05-30 21:35:08 +0400
commitc27c567225affbb8bca12452192775e31bc463ed (patch)
treeade2d96ef511c6409651c0700030477312812006
parent93eff78cd6527b097adcfa218787c1be6c12e86c (diff)
Added initial support for non-panel credits receipts.
-rw-r--r--Telegram/SourceFiles/history/history_item.cpp1
-rw-r--r--Telegram/SourceFiles/history/history_item_components.h1
-rw-r--r--Telegram/SourceFiles/payments/payments_checkout_process.cpp5
-rw-r--r--Telegram/SourceFiles/payments/payments_checkout_process.h5
-rw-r--r--Telegram/SourceFiles/payments/payments_form.cpp20
-rw-r--r--Telegram/SourceFiles/payments/payments_form.h14
-rw-r--r--Telegram/SourceFiles/payments/payments_non_panel_process.cpp27
7 files changed, 64 insertions, 9 deletions
diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp
index c1af45c5f7..88983c5800 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<LambdaClickHandler>([=](
ClickContext context) {
diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h
index 906fe18ceb..8d262a52e3 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 597d7687b9..3080c149bf 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<CreditsFormData>(data.data));
}
+ }, [&](const CreditsReceiptReady &data) {
+ if (_nonPanelPaymentFormProcess) {
+ _nonPanelPaymentFormProcess(
+ std::make_shared<CreditsReceiptData>(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 2f939d5a68..3c7f112ca5 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<std::shared_ptr<CreditsFormData>> {
+struct NonPanelPaymentForm : std::variant<
+ std::shared_ptr<CreditsFormData>,
+ std::shared_ptr<CreditsReceiptData>> {
using variant::variant;
};
diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp
index c6ddd84a9f..8dac6d0c55 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 6507ffa138..cf4cef8903 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 47232ac8ac..2369d3d5d4 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<HistoryItem*> item) {
+ if (const auto payment = item->Get<HistoryServicePayment>()) {
+ 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<void(NonPanelPaymentForm)> ProcessNonPanelPaymentFormFactory(
not_null<Window::SessionController*> controller) {
return [=](NonPanelPaymentForm form) {
using CreditsFormDataPtr = std::shared_ptr<CreditsFormData>;
+ using CreditsReceiptPtr = std::shared_ptr<CreditsReceiptData>;
if (const auto creditsData = std::get_if<CreditsFormDataPtr>(&form)) {
controller->uiShow()->show(Box(Ui::SendCreditsBox, *creditsData));
}
+ if (const auto r = std::get_if<CreditsReceiptPtr>(&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));
+ }
};
}