diff options
author | 23rd <23rd@vivaldi.net> | 2024-05-17 14:35:19 +0300 |
---|---|---|
committer | John Preston <johnprestonmail@gmail.com> | 2024-05-30 21:35:06 +0400 |
commit | ac2f35f12bb6b49e1ca8bf8b24c678b13ee38163 (patch) | |
tree | 43bd0dbf5819ca9034e06016e45a3c21ce197295 /Telegram/SourceFiles/payments/payments_form.cpp | |
parent | 39e03c3ca7265f722cf972add9249e4b8ca2385f (diff) |
Processed payments form with API scheme on layer 181.
Diffstat (limited to 'Telegram/SourceFiles/payments/payments_form.cpp')
-rw-r--r-- | Telegram/SourceFiles/payments/payments_form.cpp | 119 |
1 files changed, 69 insertions, 50 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); }); - } + }); + + processDetails(result); + result.match([&](const TLForm &data) { + if (const auto info = data.vsaved_info()) { + info->match([&](const auto &data) { + processSavedInformation(data); + }); + } + }, [](const TLCredits &) { + }); _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()), - }); + 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(); } - refreshPaymentMethodDetails(); - } - if (const auto additional = data.vadditional_methods()) { - processAdditionalPaymentMethods(additional->v); - } + 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)) { |