From ac2f35f12bb6b49e1ca8bf8b24c678b13ee38163 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 17 May 2024 14:35:19 +0300 Subject: [PATCH] Processed payments form with API scheme on layer 181. --- .../SourceFiles/payments/payments_form.cpp | 121 ++++++++++-------- Telegram/SourceFiles/payments/payments_form.h | 4 +- 2 files changed, 72 insertions(+), 53 deletions(-) diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 59c8e5d658..16469cb1ed 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -359,12 +359,7 @@ void Form::requestForm() { MTP_dataJSON(MTP_bytes(Window::Theme::WebViewParams().json)) )).done([=](const MTPpayments_PaymentForm &result) { hideProgress(); - result.match([&](const MTPDpayments_paymentForm &data) { - processForm(data); - }, [&](const MTPDpayments_paymentFormStars &data) { - // #TODO stars - _updates.fire(Error{ Error::Type::Form }); - }); + processForm(result); }).fail([=](const MTP::Error &error) { hideProgress(); _updates.fire(Error{ Error::Type::Form, error.type() }); @@ -390,33 +385,44 @@ void Form::requestReceipt() { }).send(); } -void Form::processForm(const MTPDpayments_paymentForm &data) { - _session->data().processUsers(data.vusers()); +void Form::processForm(const MTPpayments_PaymentForm &result) { + using TLForm = MTPDpayments_paymentForm; + using TLCredits = MTPDpayments_paymentFormStars; + result.match([&](const auto &data) { + _session->data().processUsers(data.vusers()); - data.vinvoice().match([&](const auto &data) { - processInvoice(data); - }); - processDetails(data); - if (const auto info = data.vsaved_info()) { - info->match([&](const auto &data) { - processSavedInformation(data); + data.vinvoice().match([&](const auto &data) { + processInvoice(data); }); - } - _paymentMethod.savedCredentials.clear(); - _paymentMethod.savedCredentialsIndex = 0; - if (const auto credentials = data.vsaved_credentials()) { - _paymentMethod.savedCredentials.reserve(credentials->v.size()); - for (const auto &saved : credentials->v) { - _paymentMethod.savedCredentials.push_back({ - .id = qs(saved.data().vid()), - .title = qs(saved.data().vtitle()), + }); + + processDetails(result); + result.match([&](const TLForm &data) { + if (const auto info = data.vsaved_info()) { + info->match([&](const auto &data) { + processSavedInformation(data); }); } - refreshPaymentMethodDetails(); - } - if (const auto additional = data.vadditional_methods()) { - processAdditionalPaymentMethods(additional->v); - } + }, [](const TLCredits &) { + }); + _paymentMethod.savedCredentials.clear(); + _paymentMethod.savedCredentialsIndex = 0; + result.match([&](const TLForm &data) { + if (const auto credentials = data.vsaved_credentials()) { + _paymentMethod.savedCredentials.reserve(credentials->v.size()); + for (const auto &saved : credentials->v) { + _paymentMethod.savedCredentials.push_back({ + .id = qs(saved.data().vid()), + .title = qs(saved.data().vtitle()), + }); + } + refreshPaymentMethodDetails(); + } + if (const auto additional = data.vadditional_methods()) { + processAdditionalPaymentMethods(additional->v); + } + }, [](const TLCredits &) { + }); fillPaymentMethodInformation(); _updates.fire(FormReady{}); } @@ -479,31 +485,44 @@ void Form::processInvoice(const MTPDinvoice &data) { }; } -void Form::processDetails(const MTPDpayments_paymentForm &data) { - const auto nativeParams = data.vnative_params(); - auto nativeParamsJson = nativeParams - ? nativeParams->match( - [&](const MTPDdataJSON &data) { return data.vdata().v; }) - : QByteArray(); - _details = FormDetails{ - .formId = data.vform_id().v, - .url = qs(data.vurl()), - .nativeProvider = qs(data.vnative_provider().value_or_empty()), - .nativeParamsJson = std::move(nativeParamsJson), - .botId = data.vbot_id().v, - .providerId = data.vprovider_id().v, - .canSaveCredentials = data.is_can_save_credentials(), - .passwordMissing = data.is_password_missing(), - }; - _invoice.cover.title = qs(data.vtitle()); +void Form::processDetails(const MTPpayments_PaymentForm &result) { + using TLForm = MTPDpayments_paymentForm; + using TLCredits = MTPDpayments_paymentFormStars; + _details = result.match([&](const TLForm &data) { + const auto nativeParams = data.vnative_params(); + auto nativeParamsJson = nativeParams + ? nativeParams->match( + [&](const MTPDdataJSON &data) { return data.vdata().v; }) + : QByteArray(); + return FormDetails{ + .formId = data.vform_id().v, + .url = qs(data.vurl()), + .nativeProvider = qs(data.vnative_provider().value_or_empty()), + .nativeParamsJson = std::move(nativeParamsJson), + .botId = data.vbot_id().v, + .providerId = data.vprovider_id().v, + .canSaveCredentials = data.is_can_save_credentials(), + .passwordMissing = data.is_password_missing(), + }; + }, [](const TLCredits &data) { + return FormDetails{ + .formId = data.vform_id().v, + .botId = data.vbot_id().v, + }; + }); + _invoice.cover.title = result.match([](const auto &data) { + return qs(data.vtitle()); + }); _invoice.cover.description = TextUtilities::ParseEntities( - qs(data.vdescription()), + result.match([](const auto &d) { return qs(d.vdescription()); }), TextParseLinks | TextParseMultiline); if (_invoice.cover.thumbnail.isNull() && !_thumbnailLoadProcess) { - if (const auto photo = data.vphoto()) { - loadThumbnail( - _session->data().photoFromWeb(*photo, ImageLocation())); - } + result.match([&](const auto &data) { + if (const auto photo = data.vphoto()) { + loadThumbnail( + _session->data().photoFromWeb(*photo, ImageLocation())); + } + }); } if (const auto botId = _details.botId) { if (const auto bot = _session->data().userLoaded(botId)) { diff --git a/Telegram/SourceFiles/payments/payments_form.h b/Telegram/SourceFiles/payments/payments_form.h index 414eb0b021..68cb75cebe 100644 --- a/Telegram/SourceFiles/payments/payments_form.h +++ b/Telegram/SourceFiles/payments/payments_form.h @@ -285,10 +285,10 @@ private: void requestForm(); void requestReceipt(); - void processForm(const MTPDpayments_paymentForm &data); + void processForm(const MTPpayments_PaymentForm &result); void processReceipt(const MTPDpayments_paymentReceipt &data); void processInvoice(const MTPDinvoice &data); - void processDetails(const MTPDpayments_paymentForm &data); + void processDetails(const MTPpayments_PaymentForm &result); void processDetails(const MTPDpayments_paymentReceipt &data); void processSavedInformation(const MTPDpaymentRequestedInfo &data); void processAdditionalPaymentMethods(