summaryrefslogtreecommitdiffstats
path: root/Telegram/SourceFiles/payments/payments_form.h
blob: 92288605ced8a56c983486bd99f5238c893b986b (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
99
100
101
102
103
104
105
106
/*
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_data.h"

namespace Main {
class Session;
} // namespace Main

namespace Payments {

struct FormDetails {
	QString url;
	QString nativeProvider;
	QByteArray nativeParamsJson;
	UserId botId = 0;
	UserId providerId = 0;
	bool canSaveCredentials = false;
	bool passwordMissing = false;

	[[nodiscard]] bool valid() const {
		return !url.isEmpty();
	}
	[[nodiscard]] explicit operator bool() const {
		return valid();
	}
};

struct FormReady {};

struct FormError {
	QString type;
};

struct SendError {
	QString type;
};

struct VerificationNeeded {
	QString url;
};

struct PaymentFinished {
	MTPUpdates updates;
};

struct FormUpdate {
	std::variant<
		FormReady,
		FormError,
		SendError,
		VerificationNeeded,
		PaymentFinished> data;
};

class Form final {
public:
	Form(not_null<Main::Session*> session, FullMsgId itemId);

	[[nodiscard]] const Ui::Invoice &invoice() const {
		return _invoice;
	}
	[[nodiscard]] const FormDetails &details() const {
		return _details;
	}
	[[nodiscard]] const Ui::SavedInformation &savedInformation() const {
		return _savedInformation;
	}
	[[nodiscard]] const Ui::SavedCredentials &savedCredentials() const {
		return _savedCredentials;
	}

	[[nodiscard]] rpl::producer<FormUpdate> updates() const {
		return _updates.events();
	}

	void send(const QByteArray &serializedCredentials);

private:
	void requestForm();
	void processForm(const MTPDpayments_paymentForm &data);
	void processInvoice(const MTPDinvoice &data);
	void processDetails(const MTPDpayments_paymentForm &data);
	void processSavedInformation(const MTPDpaymentRequestedInfo &data);
	void processSavedCredentials(
		const MTPDpaymentSavedCredentialsCard &data);

	const not_null<Main::Session*> _session;
	MsgId _msgId = 0;

	Ui::Invoice _invoice;
	FormDetails _details;
	Ui::SavedInformation _savedInformation;
	Ui::SavedCredentials _savedCredentials;

	rpl::event_stream<FormUpdate> _updates;

};

} // namespace Payments