summaryrefslogtreecommitdiffstats
path: root/Telegram/SourceFiles/payments/payments_form.cpp
diff options
context:
space:
mode:
author23rd <23rd@vivaldi.net>2024-05-24 20:54:13 +0300
committerJohn Preston <johnprestonmail@gmail.com>2024-05-30 21:35:07 +0400
commitf08ff9247083c72de12fbcf7a9c6039673054fb5 (patch)
tree94a9f7129d538ccd7d99153b24b7511de996a250 /Telegram/SourceFiles/payments/payments_form.cpp
parent923aaec085cd10bd3dc87675307f3c811b489d44 (diff)
Added initial ability to provide data for non-panel payment forms.
Diffstat (limited to 'Telegram/SourceFiles/payments/payments_form.cpp')
-rw-r--r--Telegram/SourceFiles/payments/payments_form.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp
index b6512d532d..f3283b570a 100644
--- a/Telegram/SourceFiles/payments/payments_form.cpp
+++ b/Telegram/SourceFiles/payments/payments_form.cpp
@@ -376,7 +376,42 @@ void Form::requestForm() {
MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json))
)).done([=](const MTPpayments_PaymentForm &result) {
hideProgress();
- processForm(result);
+ result.match([&](const MTPDpayments_paymentForm &data) {
+ processForm(result);
+ }, [&](const MTPDpayments_paymentFormStars &data) {
+ _session->data().processUsers(data.vusers());
+ const auto currency = qs(data.vinvoice().data().vcurrency());
+ const auto &tlPrices = data.vinvoice().data().vprices().v;
+ const auto amount = tlPrices.empty()
+ ? 0
+ : tlPrices.front().data().vamount().v;
+ if (currency != "XTR" || !amount) {
+ using Type = Error::Type;
+ _updates.fire(Error{ Type::Form, u"Bad Stars Form."_q });
+ return;
+ }
+ const auto invoice = InvoiceCredits{
+ .session = _session,
+ .randomId = 0,
+ .credits = amount,
+ .currency = currency,
+ .amount = amount,
+ };
+ const auto formData = CreditsFormData{
+ .formId = data.vform_id().v,
+ .botId = data.vbot_id().v,
+ .title = qs(data.vtitle()),
+ .description = qs(data.vdescription()),
+ .photo = data.vphoto()
+ ? _session->data().photoFromWeb(
+ *data.vphoto(),
+ ImageLocation())
+ : nullptr,
+ .invoice = invoice,
+ .inputInvoice = inputInvoice(),
+ };
+ _updates.fire(CreditsPaymentStarted{ .data = formData });
+ });
}).fail([=](const MTP::Error &error) {
hideProgress();
_updates.fire(Error{ Error::Type::Form, error.type() });