From 491ec2db7f554f180898fab1bd6d96d9bcdd2dfe Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 1 Apr 2021 18:39:44 +0400 Subject: [PATCH] Always show footer in webview in payments. --- Telegram/Resources/langs/lang.strings | 9 ++++-- .../payments/payments_checkout_process.cpp | 5 +++- .../SourceFiles/payments/payments_form.cpp | 1 + .../SourceFiles/payments/ui/payments.style | 3 ++ .../payments/ui/payments_edit_information.cpp | 2 +- .../payments/ui/payments_panel.cpp | 30 +++++++++++++++++-- .../SourceFiles/payments/ui/payments_panel.h | 5 +++- .../payments/ui/payments_panel_data.h | 1 + 8 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0594f9d1b..607d83829 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1879,9 +1879,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_payments_info_name" = "Name"; "lng_payments_info_email" = "Email"; "lng_payments_info_phone" = "Phone"; -"lng_payments_to_provider_phone_email" = "Phone and Email will be passed to {bot_name} as billing info."; -"lng_payments_to_provider_email" = "Email will be passed to {bot_name} as billing info."; -"lng_payments_to_provider_phone" = "Phone will be passed to {bot_name} as billing info."; +"lng_payments_to_provider_phone_email" = "Phone and Email will be passed to {provider} as billing info."; +"lng_payments_to_provider_email" = "Email will be passed to {provider} as billing info."; +"lng_payments_to_provider_phone" = "Phone will be passed to {provider} as billing info."; +"lng_payments_processed_by" = "Processed by {provider}"; +"lng_payments_warning_title" = "Warning"; +"lng_payments_warning_body" = "Neither Telegram, nor {bot1} will have access to your credit card information. Credit card details will be handled only by the payment system, {provider}.\n\nPayments will go directly to the developer of {bot2}. Telegram cannot provide any guarantees, so proceed at your own risk. In case of problems, please contact the developer of {bot3} or your bank."; "lng_payments_shipping_address_title" = "Shipping Information"; "lng_payments_card_title" = "New Card"; "lng_payments_card_number" = "Card Number"; diff --git a/Telegram/SourceFiles/payments/payments_checkout_process.cpp b/Telegram/SourceFiles/payments/payments_checkout_process.cpp index 290b7762c..878f9066b 100644 --- a/Telegram/SourceFiles/payments/payments_checkout_process.cpp +++ b/Telegram/SourceFiles/payments/payments_checkout_process.cpp @@ -167,7 +167,10 @@ void CheckoutProcess::handleFormUpdate(const FormUpdate &update) { _submitState = SubmitState::Validated; requestPassword(); }, [&](const VerificationNeeded &data) { - if (!_panel->showWebview(data.url, false)) { + auto bottomText = tr::lng_payments_processed_by( + lt_provider, + rpl::single(_form->invoice().provider)); + if (!_panel->showWebview(data.url, false, std::move(bottomText))) { File::OpenUrl(data.url); close(); } diff --git a/Telegram/SourceFiles/payments/payments_form.cpp b/Telegram/SourceFiles/payments/payments_form.cpp index 614a81232..b2133bbe0 100644 --- a/Telegram/SourceFiles/payments/payments_form.cpp +++ b/Telegram/SourceFiles/payments/payments_form.cpp @@ -405,6 +405,7 @@ void Form::refreshPaymentMethodDetails() { const auto &saved = _paymentMethod.savedCredentials; const auto &entered = _paymentMethod.newCredentials; _paymentMethod.ui.title = entered ? entered.title : saved.title; + _paymentMethod.ui.provider = _invoice.provider; _paymentMethod.ui.ready = entered || saved; _paymentMethod.ui.native.defaultCountry = defaultCountry(); _paymentMethod.ui.canSaveInformation diff --git a/Telegram/SourceFiles/payments/ui/payments.style b/Telegram/SourceFiles/payments/ui/payments.style index 737c7b836..7ec1a7149 100644 --- a/Telegram/SourceFiles/payments/ui/payments.style +++ b/Telegram/SourceFiles/payments/ui/payments.style @@ -28,6 +28,9 @@ paymentsTitle: FlatLabel(paymentsDescription) { paymentsSeller: FlatLabel(paymentsDescription) { textFg: windowSubTextFg; } +paymentsWebviewBottom: FlatLabel(defaultFlatLabel) { + textFg: windowSubTextFg; +} paymentsPriceLabel: paymentsDescription; paymentsPriceAmount: defaultFlatLabel; paymentsFullPriceLabel: paymentsTitle; diff --git a/Telegram/SourceFiles/payments/ui/payments_edit_information.cpp b/Telegram/SourceFiles/payments/ui/payments_edit_information.cpp index 486842957..d62abd1ad 100644 --- a/Telegram/SourceFiles/payments/ui/payments_edit_information.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_edit_information.cpp @@ -189,7 +189,7 @@ not_null EditInformation::setupContent() { : emailToProvider ? tr::lng_payments_to_provider_email : tr::lng_payments_to_provider_phone)( - lt_bot_name, + lt_provider, rpl::single(_invoice.provider)), st::paymentsToProviderLabel), st::paymentsToProviderPadding); diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.cpp b/Telegram/SourceFiles/payments/ui/payments_panel.cpp index c49819c3e..885e74a00 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_panel.cpp @@ -235,10 +235,15 @@ void Panel::chooseTips(const Invoice &invoice) { } void Panel::showEditPaymentMethod(const PaymentMethodDetails &method) { + auto bottomText = method.canSaveInformation + ? rpl::producer() + : tr::lng_payments_processed_by( + lt_provider, + rpl::single(method.provider)); _widget->setTitle(tr::lng_payments_card_title()); if (method.native.supported) { showEditCard(method.native, CardField::Number); - } else if (!showWebview(method.url, true)) { + } else if (!showWebview(method.url, true, std::move(bottomText))) { // #TODO payments errors not supported } else if (method.canSaveInformation) { const auto &padding = st::paymentsPanelPadding; @@ -255,12 +260,33 @@ void Panel::showEditPaymentMethod(const PaymentMethodDetails &method) { } } -bool Panel::showWebview(const QString &url, bool allowBack) { +bool Panel::showWebview( + const QString &url, + bool allowBack, + rpl::producer bottomText) { if (!_webview && !createWebview()) { return false; } _webview->navigate(url); _widget->setBackAllowed(allowBack); + if (bottomText) { + const auto &padding = st::paymentsPanelPadding; + const auto label = CreateChild( + _webviewBottom.get(), + std::move(bottomText), + st::paymentsWebviewBottom); + const auto height = padding.top() + + label->heightNoMargins() + + padding.bottom(); + rpl::combine( + _webviewBottom->widthValue(), + label->widthValue() + ) | rpl::start_with_next([=](int outerWidth, int width) { + label->move((outerWidth - width) / 2, padding.top()); + }, label->lifetime()); + label->show(); + _webviewBottom->resize(_webviewBottom->width(), height); + } return true; } diff --git a/Telegram/SourceFiles/payments/ui/payments_panel.h b/Telegram/SourceFiles/payments/ui/payments_panel.h index 488419a54..01cb5a490 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel.h +++ b/Telegram/SourceFiles/payments/ui/payments_panel.h @@ -69,7 +69,10 @@ public: void choosePaymentMethod(const PaymentMethodDetails &method); void askSetPassword(); - bool showWebview(const QString &url, bool allowBack); + bool showWebview( + const QString &url, + bool allowBack, + rpl::producer bottomText); [[nodiscard]] rpl::producer<> backRequests() const; diff --git a/Telegram/SourceFiles/payments/ui/payments_panel_data.h b/Telegram/SourceFiles/payments/ui/payments_panel_data.h index 6df01a54d..77ae15bc1 100644 --- a/Telegram/SourceFiles/payments/ui/payments_panel_data.h +++ b/Telegram/SourceFiles/payments/ui/payments_panel_data.h @@ -162,6 +162,7 @@ struct PaymentMethodDetails { QString title; NativeMethodDetails native; QString url; + QString provider; bool ready = false; bool canSaveInformation = false; };