mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Added initial support for non-panel credits receipts.
This commit is contained in:
parent
93eff78cd6
commit
c27c567225
7 changed files with 64 additions and 9 deletions
|
@ -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) {
|
||||
|
|
|
@ -653,6 +653,7 @@ struct HistoryServicePayment
|
|||
ClickHandlerPtr invoiceLink;
|
||||
bool recurringInit = false;
|
||||
bool recurringUsed = false;
|
||||
bool isCreditsCurrency = false;
|
||||
};
|
||||
|
||||
struct HistoryServiceSameBackground
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue