tgbotxx  1.1.6.9
Telegram Bot C++ Library
OrderInfo.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 namespace tgbotxx {
8  struct OrderInfo {
9  OrderInfo() = default;
10  explicit OrderInfo(const nl::json& json) {
11  fromJson(json);
12  }
13 
15  std::string name;
16 
18  std::string phoneNumber;
19 
21  std::string email;
22 
25 
28  nl::json toJson() const {
29  nl::json json = nl::json::object();
30  OBJECT_SERIALIZE_FIELD(json, "name", name);
31  OBJECT_SERIALIZE_FIELD(json, "phone_number", phoneNumber);
32  OBJECT_SERIALIZE_FIELD(json, "email", email);
33  OBJECT_SERIALIZE_FIELD_PTR(json, "shipping_address", shippingAddress);
34  return json;
35  }
36 
38  void fromJson(const nl::json& json) {
39  OBJECT_DESERIALIZE_FIELD(json, "name", name, "", true);
40  OBJECT_DESERIALIZE_FIELD(json, "phone_number", phoneNumber, "", true);
41  OBJECT_DESERIALIZE_FIELD(json, "email", email, "", true);
42  OBJECT_DESERIALIZE_FIELD_PTR(json, "shipping_address", shippingAddress, true);
43  }
44  };
45 }
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition: Object.hpp:22
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition: Object.hpp:70
#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:44
Definition: Api.hpp:14
std::shared_ptr< T > Ptr
Definition: Ptr.hpp:6
This object represents information about an order. https://core.telegram.org/bots/api#orderinfo.
Definition: OrderInfo.hpp:8
Ptr< ShippingAddress > shippingAddress
Optional. User shipping address.
Definition: OrderInfo.hpp:24
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: OrderInfo.hpp:38
std::string phoneNumber
Optional. User's phone number.
Definition: OrderInfo.hpp:18
nl::json toJson() const
Serializes this object to JSON.
Definition: OrderInfo.hpp:28
OrderInfo(const nl::json &json)
Definition: OrderInfo.hpp:10
std::string name
Optional. User name.
Definition: OrderInfo.hpp:15
std::string email
Optional. User email.
Definition: OrderInfo.hpp:21