1 /*
2 This file is part of Telegram Desktop,
3 the official desktop application for the Telegram messaging service.
4 
5 For license and copyright information please follow this link:
6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
7 */
8 #pragma once
9 
10 namespace Payments::Ui {
11 
12 struct LabeledPrice {
13 	QString label;
14 	int64 price = 0;
15 };
16 
17 struct Cover {
18 	QString title;
19 	QString description;
20 	QString seller;
21 	QImage thumbnail;
22 };
23 
24 struct Receipt {
25 	TimeId date = 0;
26 	int64 totalAmount = 0;
27 	QString currency;
28 	bool paid = false;
29 
emptyReceipt30 	[[nodiscard]] bool empty() const {
31 		return !paid;
32 	}
33 	[[nodiscard]] explicit operator bool() const {
34 		return !empty();
35 	}
36 };
37 
38 struct Invoice {
39 	Cover cover;
40 
41 	std::vector<LabeledPrice> prices;
42 	std::vector<int64> suggestedTips;
43 	int64 tipsMax = 0;
44 	int64 tipsSelected = 0;
45 	QString currency;
46 	Receipt receipt;
47 
48 	bool isNameRequested = false;
49 	bool isPhoneRequested = false;
50 	bool isEmailRequested = false;
51 	bool isShippingAddressRequested = false;
52 	bool isFlexible = false;
53 	bool isTest = false;
54 
55 	QString provider;
56 	bool phoneSentToProvider = false;
57 	bool emailSentToProvider = false;
58 
validInvoice59 	[[nodiscard]] bool valid() const {
60 		return !currency.isEmpty() && (!prices.empty() || tipsMax);
61 	}
62 	[[nodiscard]] explicit operator bool() const {
63 		return valid();
64 	}
65 };
66 
67 struct ShippingOption {
68 	QString id;
69 	QString title;
70 	std::vector<LabeledPrice> prices;
71 };
72 
73 struct ShippingOptions {
74 	QString currency;
75 	std::vector<ShippingOption> list;
76 	QString selectedId;
77 };
78 
79 struct Address {
80 	QString address1;
81 	QString address2;
82 	QString city;
83 	QString state;
84 	QString countryIso2;
85 	QString postcode;
86 
validAddress87 	[[nodiscard]] bool valid() const {
88 		return !address1.isEmpty()
89 			&& !city.isEmpty()
90 			&& !countryIso2.isEmpty();
91 	}
92 	[[nodiscard]] explicit operator bool() const {
93 		return valid();
94 	}
95 
96 	inline bool operator==(const Address &other) const {
97 		return (address1 == other.address1)
98 			&& (address2 == other.address2)
99 			&& (city == other.city)
100 			&& (state == other.state)
101 			&& (countryIso2 == other.countryIso2)
102 			&& (postcode == other.postcode);
103 	}
104 	inline bool operator!=(const Address &other) const {
105 		return !(*this == other);
106 	}
107 };
108 
109 struct RequestedInformation {
110 	QString defaultPhone;
111 	QString defaultCountry;
112 	bool save = true;
113 
114 	QString name;
115 	QString phone;
116 	QString email;
117 	Address shippingAddress;
118 
emptyRequestedInformation119 	[[nodiscard]] bool empty() const {
120 		return name.isEmpty()
121 			&& phone.isEmpty()
122 			&& email.isEmpty()
123 			&& !shippingAddress;
124 	}
125 	[[nodiscard]] explicit operator bool() const {
126 		return !empty();
127 	}
128 
129 	inline bool operator==(const RequestedInformation &other) const {
130 		return (name == other.name)
131 			&& (phone == other.phone)
132 			&& (email == other.email)
133 			&& (shippingAddress == other.shippingAddress);
134 	}
135 	inline bool operator!=(const RequestedInformation &other) const {
136 		return !(*this == other);
137 	}
138 };
139 
140 enum class InformationField {
141 	ShippingStreet,
142 	ShippingCity,
143 	ShippingState,
144 	ShippingCountry,
145 	ShippingPostcode,
146 	Name,
147 	Email,
148 	Phone,
149 };
150 
151 struct NativeMethodDetails {
152 	QString defaultCountry;
153 
154 	bool supported = false;
155 	bool needCountry = false;
156 	bool needZip = false;
157 	bool needCardholderName = false;
158 	bool canSaveInformation = false;
159 };
160 
161 struct PaymentMethodDetails {
162 	QString title;
163 	NativeMethodDetails native;
164 	QString url;
165 	QString provider;
166 	bool ready = false;
167 	bool canSaveInformation = false;
168 };
169 
170 enum class CardField {
171 	Number,
172 	Cvc,
173 	ExpireDate,
174 	Name,
175 	AddressCountry,
176 	AddressZip,
177 };
178 
179 struct UncheckedCardDetails {
180 	QString number;
181 	QString cvc;
182 	uint32 expireYear = 0;
183 	uint32 expireMonth = 0;
184 	QString cardholderName;
185 	QString addressCountry;
186 	QString addressZip;
187 };
188 
189 } // namespace Payments::Ui
190