summaryrefslogtreecommitdiffstats
path: root/Telegram/SourceFiles/payments/payments_checkout_process.h
blob: de9d37724b9dd4fa12fc2cbc5be4ad1e6dd5ae7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
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
*/
#pragma once

#include "payments/ui/payments_panel_delegate.h"
#include "base/weak_ptr.h"

class HistoryItem;

namespace Main {
class Session;
} // namespace Main

namespace Payments::Ui {
class Panel;
enum class InformationField;
enum class CardField;
} // namespace Payments::Ui

namespace Payments {

class Form;
struct FormUpdate;
struct Error;

class CheckoutProcess final
	: public base::has_weak_ptr
	, private Ui::PanelDelegate {
	struct PrivateTag {};

public:
	static void Start(not_null<const HistoryItem*> item);

	CheckoutProcess(
		not_null<Main::Session*> session,
		FullMsgId itemId,
		PrivateTag);
	~CheckoutProcess();

	void requestActivate();

private:
	enum class SubmitState {
		None,
		Validation,
		Validated,
		Finishing,
	};
	[[nodiscard]] not_null<PanelDelegate*> panelDelegate();

	void handleFormUpdate(const FormUpdate &update);
	void handleError(const Error &error);

	void showForm();
	void showEditInformation(Ui::InformationField field);
	void showInformationError(Ui::InformationField field);
	void showCardError(Ui::CardField field);
	void chooseShippingOption();
	void editPaymentMethod();

	void performInitialSilentValidation();

	void panelRequestClose() override;
	void panelCloseSure() override;
	void panelSubmit() override;
	void panelWebviewMessage(const QJsonDocument &message) override;
	bool panelWebviewNavigationAttempt(const QString &uri) override;

	void panelEditPaymentMethod() override;
	void panelEditShippingInformation() override;
	void panelEditName() override;
	void panelEditEmail() override;
	void panelEditPhone() override;
	void panelChooseShippingOption() override;
	void panelChangeShippingOption(const QString &id) override;

	void panelValidateInformation(Ui::RequestedInformation data) override;
	void panelValidateCard(Ui::UncheckedCardDetails data) override;
	void panelShowBox(object_ptr<Ui::BoxContent> box) override;

	QString panelWebviewDataPath() override;

	const not_null<Main::Session*> _session;
	const std::unique_ptr<Form> _form;
	const std::unique_ptr<Ui::Panel> _panel;
	SubmitState _submitState = SubmitState::None;
	bool _initialSilentValidation = false;

	rpl::lifetime _lifetime;

};

} // namespace Payments