tgbotxx 1.1.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) {
18 _fromJson(json);
19 }
20 virtual ~TransactionPartner() = default;
21
23 std::string type;
24
27 virtual nl::json toJson() const {
28 nl::json json = nl::json::object();
29 OBJECT_SERIALIZE_FIELD(json, "type", type);
30 return json;
31 }
32
34 virtual void fromJson(const nl::json& json) {
35 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
36 }
37
38 private:
40 void _fromJson(const nl::json& json) {
41 fromJson(json);
42 }
43 };
44
50 explicit TransactionPartnerUser(const nl::json& json) : TransactionPartner(json) {
52 }
53
55 std::string transactionType;
56
59
62
64 std::string invoicePayload;
65
67 std::int32_t subscriptionPeriod{};
68
70 std::vector<Ptr<PaidMedia>> paidMedia;
71
73 std::string paidMediaPayload;
74
77
80
83 nl::json toJson() const override {
84 nl::json json = TransactionPartner::toJson();
85 OBJECT_SERIALIZE_FIELD(json, "transaction_type", transactionType);
86 OBJECT_SERIALIZE_FIELD_PTR(json, "user", user);
87 OBJECT_SERIALIZE_FIELD_PTR(json, "affiliate", affiliate);
88 OBJECT_SERIALIZE_FIELD(json, "invoice_payload", invoicePayload);
89 OBJECT_SERIALIZE_FIELD(json, "subscription_period", subscriptionPeriod);
91 OBJECT_SERIALIZE_FIELD(json, "paid_media_payload", paidMediaPayload);
92 OBJECT_SERIALIZE_FIELD_PTR(json, "gift", gift);
93 OBJECT_SERIALIZE_FIELD(json, "premium_subscription_duration", premiumSubscriptionDuration);
94 return json;
95 }
96
98 void fromJson(const nl::json& json) override {
100 OBJECT_DESERIALIZE_FIELD(json, "transaction_type", transactionType, "", false);
101 OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, false);
102 OBJECT_DESERIALIZE_FIELD_PTR(json, "affiliate", affiliate, true);
103 OBJECT_DESERIALIZE_FIELD(json, "invoice_payload", invoicePayload, "", true);
104 OBJECT_DESERIALIZE_FIELD(json, "subscription_period", subscriptionPeriod, 0, true);
105 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "paid_media", paidMedia, true);
106 OBJECT_DESERIALIZE_FIELD(json, "paid_media_payload", paidMediaPayload, "", true);
107 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, true);
108 OBJECT_DESERIALIZE_FIELD(json, "premium_subscription_duration", premiumSubscriptionDuration, 0, true);
109 }
110 };
111
117 explicit TransactionPartnerChat(const nl::json& json) : TransactionPartner(json) {
119 }
120
123
126
128 nl::json toJson() const override {
129 nl::json json = TransactionPartner::toJson();
130 OBJECT_SERIALIZE_FIELD_PTR(json, "chat", chat);
131 OBJECT_SERIALIZE_FIELD_PTR(json, "gift", gift);
132 return json;
133 }
134
136 void fromJson(const nl::json& json) override {
138 OBJECT_DESERIALIZE_FIELD_PTR(json, "chat", chat, false);
139 OBJECT_DESERIALIZE_FIELD_PTR(json, "gift", gift, true);
140 }
141 };
142
148 explicit TransactionPartnerAffiliateProgram(const nl::json& json) : TransactionPartner(json) {
149 TransactionPartner::type = "affiliate_program";
150 }
151
154
156 std::int32_t commissionPerMille{};
157
158 nl::json toJson() const override {
159 nl::json json = TransactionPartner::toJson();
160 OBJECT_SERIALIZE_FIELD_PTR(json, "sponsor_user", sponsorUser);
161 OBJECT_SERIALIZE_FIELD(json, "commission_per_mille", commissionPerMille);
162 return json;
163 }
164
165 void fromJson(const nl::json& json) override {
167 OBJECT_DESERIALIZE_FIELD_PTR(json, "sponsor_user", sponsorUser, true);
168 OBJECT_DESERIALIZE_FIELD(json, "commission_per_mille", commissionPerMille, 0, false);
169 }
170 };
171
177 explicit TransactionPartnerFragment(const nl::json& json) : TransactionPartner(json) {
178 TransactionPartner::type = "fragment";
179 }
180
183
184 nl::json toJson() const override {
185 nl::json json = TransactionPartner::toJson();
186 OBJECT_SERIALIZE_FIELD_PTR(json, "withdrawal_state", withdrawalState);
187 return json;
188 }
189
190 void fromJson(const nl::json& json) override {
192 OBJECT_DESERIALIZE_FIELD_PTR(json, "withdrawal_state", withdrawalState, true);
193 }
194 };
195
201 explicit TransactionPartnerTelegramAds(const nl::json& json) : TransactionPartner(json) {
202 TransactionPartner::type = "telegram_ads";
203 }
204 };
205
211 explicit TransactionPartnerTelegramApi(const nl::json& json) : TransactionPartner(json) {
212 TransactionPartner::type = "telegram_api";
213 }
214
216 std::int32_t requestCount{};
217
218 nl::json toJson() const override {
219 nl::json json = TransactionPartner::toJson();
220 OBJECT_SERIALIZE_FIELD(json, "request_count", requestCount);
221 return json;
222 }
223
224 void fromJson(const nl::json& json) override {
226 OBJECT_DESERIALIZE_FIELD(json, "request_count", requestCount, 0, false);
227 }
228 };
229
235 explicit TransactionPartnerOther(const nl::json& json) : TransactionPartner(json) {
236 TransactionPartner::type = "other";
237 }
238 };
239
240}
#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)
Describes a withdrawal transaction to Telegram Ads platform.
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.