2021-03-23 12:34:34 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "payments/ui/payments_panel.h"
|
|
|
|
|
|
|
|
#include "payments/ui/payments_form_summary.h"
|
2021-03-23 16:06:59 +00:00
|
|
|
#include "payments/ui/payments_edit_information.h"
|
2021-03-25 15:27:30 +00:00
|
|
|
#include "payments/ui/payments_edit_card.h"
|
2021-03-23 12:34:34 +00:00
|
|
|
#include "payments/ui/payments_panel_delegate.h"
|
|
|
|
#include "ui/widgets/separate_panel.h"
|
2021-03-23 16:06:59 +00:00
|
|
|
#include "ui/boxes/single_choice_box.h"
|
2021-03-23 12:34:34 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "styles/style_payments.h"
|
|
|
|
#include "styles/style_passport.h"
|
|
|
|
|
|
|
|
namespace Payments::Ui {
|
|
|
|
|
|
|
|
Panel::Panel(not_null<PanelDelegate*> delegate)
|
|
|
|
: _delegate(delegate)
|
|
|
|
, _widget(std::make_unique<SeparatePanel>()) {
|
|
|
|
_widget->setTitle(tr::lng_payments_checkout_title());
|
|
|
|
_widget->setInnerSize(st::passportPanelSize);
|
2021-03-24 11:30:01 +00:00
|
|
|
_widget->setWindowFlag(Qt::WindowStaysOnTopHint, false);
|
2021-03-23 12:34:34 +00:00
|
|
|
|
|
|
|
_widget->closeRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_delegate->panelRequestClose();
|
|
|
|
}, _widget->lifetime());
|
|
|
|
|
|
|
|
_widget->closeEvents(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_delegate->panelCloseSure();
|
|
|
|
}, _widget->lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
Panel::~Panel() = default;
|
|
|
|
|
|
|
|
void Panel::requestActivate() {
|
|
|
|
_widget->showAndActivate();
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:06:59 +00:00
|
|
|
void Panel::showForm(
|
|
|
|
const Invoice &invoice,
|
|
|
|
const RequestedInformation ¤t,
|
2021-03-25 15:27:30 +00:00
|
|
|
const NativePaymentDetails &native,
|
2021-03-23 16:06:59 +00:00
|
|
|
const ShippingOptions &options) {
|
2021-03-23 12:34:34 +00:00
|
|
|
_widget->showInner(
|
2021-03-23 16:06:59 +00:00
|
|
|
base::make_unique_q<FormSummary>(
|
|
|
|
_widget.get(),
|
|
|
|
invoice,
|
|
|
|
current,
|
2021-03-25 15:27:30 +00:00
|
|
|
native,
|
2021-03-23 16:06:59 +00:00
|
|
|
options,
|
|
|
|
_delegate));
|
2021-03-24 11:30:01 +00:00
|
|
|
_widget->setBackAllowed(false);
|
2021-03-23 16:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::showEditInformation(
|
|
|
|
const Invoice &invoice,
|
|
|
|
const RequestedInformation ¤t,
|
2021-03-25 15:27:30 +00:00
|
|
|
InformationField field) {
|
2021-03-24 11:30:01 +00:00
|
|
|
auto edit = base::make_unique_q<EditInformation>(
|
2021-03-23 16:06:59 +00:00
|
|
|
_widget.get(),
|
|
|
|
invoice,
|
|
|
|
current,
|
|
|
|
field,
|
2021-03-24 11:30:01 +00:00
|
|
|
_delegate);
|
2021-03-25 15:27:30 +00:00
|
|
|
_weakEditInformation = edit.get();
|
2021-03-24 11:30:01 +00:00
|
|
|
_widget->showInner(std::move(edit));
|
|
|
|
_widget->setBackAllowed(true);
|
2021-03-25 15:27:30 +00:00
|
|
|
_weakEditInformation->setFocus(field);
|
2021-03-24 11:30:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-25 15:27:30 +00:00
|
|
|
void Panel::showInformationError(
|
2021-03-24 11:30:01 +00:00
|
|
|
const Invoice &invoice,
|
|
|
|
const RequestedInformation ¤t,
|
2021-03-25 15:27:30 +00:00
|
|
|
InformationField field) {
|
|
|
|
if (_weakEditInformation) {
|
|
|
|
_weakEditInformation->showError(field);
|
2021-03-24 11:30:01 +00:00
|
|
|
} else {
|
|
|
|
showEditInformation(invoice, current, field);
|
2021-03-25 15:27:30 +00:00
|
|
|
if (_weakEditInformation
|
|
|
|
&& field == InformationField::ShippingCountry) {
|
|
|
|
_weakEditInformation->showError(field);
|
2021-03-24 11:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-23 16:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::chooseShippingOption(const ShippingOptions &options) {
|
|
|
|
showBox(Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
auto list = options.list | ranges::views::transform(
|
|
|
|
&ShippingOption::title
|
|
|
|
) | ranges::to_vector;
|
|
|
|
const auto i = ranges::find(
|
|
|
|
options.list,
|
|
|
|
options.selectedId,
|
|
|
|
&ShippingOption::id);
|
|
|
|
const auto save = [=](int option) {
|
|
|
|
_delegate->panelChangeShippingOption(options.list[option].id);
|
|
|
|
};
|
|
|
|
SingleChoiceBox(box, {
|
|
|
|
.title = tr::lng_payments_shipping_method(),
|
|
|
|
.options = list,
|
|
|
|
.initialSelection = (i != end(options.list)
|
|
|
|
? (i - begin(options.list))
|
|
|
|
: -1),
|
|
|
|
.callback = save,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2021-03-25 15:27:30 +00:00
|
|
|
void Panel::choosePaymentMethod(const NativePaymentDetails &native) {
|
|
|
|
Expects(native.supported);
|
|
|
|
|
|
|
|
if (!native.ready) {
|
|
|
|
showEditCard(native, CardField::Number);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto title = native.credentialsTitle;
|
|
|
|
showBox(Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
const auto save = [=](int option) {
|
|
|
|
if (option) {
|
|
|
|
showEditCard(native, CardField::Number);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
SingleChoiceBox(box, {
|
|
|
|
.title = tr::lng_payments_payment_method(),
|
|
|
|
.options = { native.credentialsTitle, "New Card..." }, // #TODO payments lang
|
|
|
|
.initialSelection = 0,
|
|
|
|
.callback = save,
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::showEditCard(
|
|
|
|
const NativePaymentDetails &native,
|
|
|
|
CardField field) {
|
|
|
|
auto edit = base::make_unique_q<EditCard>(
|
|
|
|
_widget.get(),
|
|
|
|
native,
|
|
|
|
field,
|
|
|
|
_delegate);
|
|
|
|
_weakEditCard = edit.get();
|
|
|
|
_widget->showInner(std::move(edit));
|
|
|
|
_widget->setBackAllowed(true);
|
|
|
|
_weakEditCard->setFocus(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Panel::showCardError(
|
|
|
|
const NativePaymentDetails &native,
|
|
|
|
CardField field) {
|
|
|
|
if (_weakEditCard) {
|
|
|
|
_weakEditCard->showError(field);
|
|
|
|
} else {
|
|
|
|
showEditCard(native, field);
|
|
|
|
if (_weakEditCard
|
|
|
|
&& field == CardField::AddressCountry) {
|
|
|
|
_weakEditCard->showError(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:30:01 +00:00
|
|
|
rpl::producer<> Panel::backRequests() const {
|
|
|
|
return _widget->backRequests();
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:06:59 +00:00
|
|
|
void Panel::showBox(object_ptr<Ui::BoxContent> box) {
|
|
|
|
_widget->showBox(
|
|
|
|
std::move(box),
|
|
|
|
Ui::LayerOption::KeepOther,
|
|
|
|
anim::type::normal);
|
|
|
|
}
|
|
|
|
|
2021-03-24 11:30:01 +00:00
|
|
|
void Panel::showToast(const TextWithEntities &text) {
|
2021-03-23 16:06:59 +00:00
|
|
|
_widget->showToast(text);
|
2021-03-23 12:34:34 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 11:30:01 +00:00
|
|
|
rpl::lifetime &Panel::lifetime() {
|
|
|
|
return _widget->lifetime();
|
|
|
|
}
|
|
|
|
|
2021-03-23 12:34:34 +00:00
|
|
|
} // namespace Payments::Ui
|