payments_panel_data.h 3.9 KB

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