tgbotxx 1.2.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
TransactionPartner.hpp
Go to the documentation of this file.
1#pragma once
9#include <vector>
10
11namespace tgbotxx {
12
16 TransactionPartner() = default;
17 explicit TransactionPartner(const nl::json& json) {
19 }
20 virtual ~TransactionPartner() = default;
21
23 std::string type;
24
27 [[nodiscard]] virtual nl::json toJson() const {
28 nl::json json = nl::json::object();
30 return json;
31 }
32
34 virtual void fromJson(const nl::json& json) {
35 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
36 }
37 };
38
42 type = "user";
43 }
47
49 std::string transactionType;
50
53
56
58 std::string invoicePayload;
59
61 std::int32_t subscriptionPeriod{};
62
64 std::vector<Ptr<PaidMedia>> paidMedia;
65
67 std::string paidMediaPayload;
68
71
74
77 [[nodiscard]] nl::json toJson() const override {
79 OBJECT_SERIALIZE_FIELD(json, "transaction_type", transactionType);
82 OBJECT_SERIALIZE_FIELD(json, "invoice_payload", invoicePayload);
83 OBJECT_SERIALIZE_FIELD(json, "subscription_period", subscriptionPeriod);
85 OBJECT_SERIALIZE_FIELD(json, "paid_media_payload", paidMediaPayload);
87 OBJECT_SERIALIZE_FIELD(json, "premium_subscription_duration", premiumSubscriptionDuration);
88 return json;
89 }
90
92 void fromJson(const nl::json& json) override {
94 OBJECT_DESERIALIZE_FIELD(json, "transaction_type", transactionType, "", false);
95 OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, false);
96 OBJECT_DESERIALIZE_FIELD_PTR(json, "affiliate", affiliate, true);
97 OBJECT_DESERIALIZE_FIELD(json, "invoice_payload", invoicePayload, "", true);
98 OBJECT_DESERIALIZE_FIELD(json, "subscription_period", subscriptionPeriod, 0, true);
100 OBJECT_DESERIALIZE_FIELD(json, "paid_media_payload", paidMediaPayload, "", true);
101 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, true);
102 OBJECT_DESERIALIZE_FIELD(json, "premium_subscription_duration", premiumSubscriptionDuration, 0, true);
103 }
104 };
105
109 type = "chat";
110 }
111 explicit TransactionPartnerChat(const nl::json& json) {
113 }
114
117
120
122 [[nodiscard]] nl::json toJson() const override {
123 nl::json json = TransactionPartner::toJson();
126 return json;
127 }
128
130 void fromJson(const nl::json& json) override {
132 OBJECT_DESERIALIZE_FIELD_PTR(json, "chat", chat, false);
133 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, true);
134 }
135 };
136
140 type = "affiliate_program";
141 }
145
148
150 std::int32_t commissionPerMille{};
151
152 [[nodiscard]] nl::json toJson() const override {
153 nl::json json = TransactionPartner::toJson();
155 OBJECT_SERIALIZE_FIELD(json, "commission_per_mille", commissionPerMille);
156 return json;
157 }
158
159 void fromJson(const nl::json& json) override {
161 OBJECT_DESERIALIZE_FIELD_PTR(json, "sponsor_user", sponsorUser, true);
162 OBJECT_DESERIALIZE_FIELD(json, "commission_per_mille", commissionPerMille, 0, false);
163 }
164 };
165
169 type = "fragment";
170 }
174
177
178 [[nodiscard]] nl::json toJson() const override {
179 nl::json json = TransactionPartner::toJson();
180 OBJECT_SERIALIZE_FIELD_PTR(json, "withdrawal_state", withdrawalState);
181 return json;
182 }
183
184 void fromJson(const nl::json& json) override {
186 OBJECT_DESERIALIZE_FIELD_PTR(json, "withdrawal_state", withdrawalState, true);
187 }
188 };
189
193 type = "telegram_ads";
194 }
198
199 [[nodiscard]] nl::json toJson() const override {
200 nl::json json = TransactionPartner::toJson();
201 return json;
202 }
203
204 void fromJson(const nl::json& json) override {
206 }
207 };
208
212 type = "telegram_api";
213 }
217
219 std::int32_t requestCount{};
220
221 [[nodiscard]] nl::json toJson() const override {
222 nl::json json = TransactionPartner::toJson();
223 OBJECT_SERIALIZE_FIELD(json, "request_count", requestCount);
224 return json;
225 }
226
227 void fromJson(const nl::json& json) override {
229 OBJECT_DESERIALIZE_FIELD(json, "request_count", requestCount, 0, false);
230 }
231 };
232
236 type = "other";
237 }
241
242 [[nodiscard]] nl::json toJson() const override {
243 nl::json json = TransactionPartner::toJson();
244 return json;
245 }
246
247 void fromJson(const nl::json& json) override {
249 }
250 };
251
252}
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition Object.hpp:22
#define OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field)
Definition Object.hpp:27
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition Object.hpp:72
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:46
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition Object.hpp:89
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
Describes a transaction with an affiliate program.
nl::json toJson() const override
Serializes this object to JSON.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
Ptr< User > sponsorUser
Optional. Information about the bot sponsoring the affiliate program.
std::int32_t commissionPerMille
Number of Telegram Stars received per 1000 Stars of referred users.
Describes a transaction with a chat.
Ptr< Chat > chat
Information about the chat.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
Ptr< Gift > gift
Optional. Gift sent to the chat by the bot.
TransactionPartnerChat(const nl::json &json)
nl::json toJson() const override
Serializes this object to JSON.
Describes a withdrawal transaction with Fragment.
Ptr< RevenueWithdrawalState > withdrawalState
Optional. State of the withdrawal if transaction is outgoing.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
nl::json toJson() const override
Serializes this object to JSON.
Base class for all transaction partners https://core.telegram.org/bots/api#transactionpartner.
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
virtual nl::json toJson() const
Serializes this object to JSON.
TransactionPartner(const nl::json &json)
std::string type
Type of the transaction partner.
virtual ~TransactionPartner()=default
Describes a transaction with an unknown source or recipient.
TransactionPartnerOther(const nl::json &json)
nl::json toJson() const override
Serializes this object to JSON.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
Describes a withdrawal transaction to Telegram Ads platform.
nl::json toJson() const override
Serializes this object to JSON.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
Describes a transaction for paid broadcasting (Telegram API).
nl::json toJson() const override
Serializes this object to JSON.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::int32_t requestCount
Number of successful requests exceeding regular limits that were billed.
Describes a transaction with a user.
Ptr< User > user
Information about the user.
std::string paidMediaPayload
Optional. Bot-specified paid media payload.
TransactionPartnerUser(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::string invoicePayload
Optional. Bot-specified invoice payload.
std::string transactionType
Type of the transaction, e.g., "invoice_payment", "paid_media_payment", etc.
std::vector< Ptr< PaidMedia > > paidMedia
Optional. Information about the paid media bought by the user.
Ptr< AffiliateInfo > affiliate
Optional. Affiliate that received a commission via this transaction.
std::int32_t premiumSubscriptionDuration
Optional. Number of months for gifted Telegram Premium subscription.
Ptr< Gift > gift
Optional. Gift sent to the user by the bot.
std::int32_t subscriptionPeriod
Optional. Duration of paid subscription.
nl::json toJson() const override
Serializes this object to JSON.