diff options
author | JellyBrick <shlee1503@naver.com> | 2018-06-22 19:40:41 +0900 |
---|---|---|
committer | JellyBrick <shlee1503@naver.com> | 2018-06-22 19:40:41 +0900 |
commit | 03cd6820af477475a196ab85971f4245057841e4 (patch) | |
tree | cf46fbdcbdd7d0b8ddb43a9588c4b0a85dd1af02 /include | |
parent | a854dd975f13e71338c80d85717be6fb6e8c185a (diff) |
Bot API 3.0 Invoice method implemented
Diffstat (limited to 'include')
-rw-r--r-- | include/tgbot/Api.h | 62 | ||||
-rw-r--r-- | include/tgbot/TgTypeParser.h | 4 | ||||
-rw-r--r-- | include/tgbot/types/InlineKeyboardButton.h | 13 | ||||
-rw-r--r-- | include/tgbot/types/Message.h | 33 | ||||
-rw-r--r-- | include/tgbot/types/Update.h | 16 |
5 files changed, 109 insertions, 19 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index cb07aac..75b01a5 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -185,6 +185,66 @@ public: const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** + * @brief Use this method to send invoices. + * @param chatId Unique identifier for the target private chat. + * @param title Product name, 1-32 characters. + * @param description Product description, 1-255 characters. + * @param payload Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes. + * @param providerToken Payments provider token, obtained via Botfather. + * @param startParameter Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter. + * @param currency Three-letter ISO 4217 currency code. + * @param prices Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.) + * @param providerData Optional. JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. + * @param photoUrl Optional. URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for. + * @param photoSize Optional. Photo size + * @param photoWidth Optional. Photo width + * @param photoHeight Optional. Photo height + * @param needName Optional. Pass True, if you require the user's full name to complete the order. + * @param needPhoneNumber Optional. Pass True, if you require the user's phone number to complete the order. + * @param needEmail Optional. Pass True, if you require the user's email address to complete the order. + * @param needShippingAdress Optional. Pass True, if you require the user's shipping address to complete the order. + * @param sendPhoneNumberToProvider Optional. Pass True, if user's phone number should be sent to provider. + * @param sendEmailToProvider Optional. Pass True, if user's email address should be sent to provider + * @param isFlexible Optional. Pass True, if the final price depends on the shipping method. + * @param replyToMessageId Optional. If the message is a reply, ID of the original message. + * @param replyMarkup Optional. A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. + * @param disableNotification Optional. Sends the message silently. Users will receive a notification with no sound. + * @return On success, the sent Message is returned. + */ + Message::Ptr sendInvoice(int64_t chatId, const std::string& title, const std::string& description, const std::string& payload, + const std::string& providerToken, const std::string& startParameter, const std::string& currency, const std::vector<LabeledPrice>& prices, + const std::string& providerData, const std::string& photoUrl = "", int32_t photoSize = 0, + int32_t photoWidth = 0, int32_t photoHeight = 0, bool needName = false, + bool needPhoneNumber = false, bool needEmail = false, bool needShippingAdress = false, + bool sendPhoneNumberToProvider = false, bool sendEmailToProvider = false, bool isFlexible = false, + int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; + + /** + * @brief Use this method to reply to shipping queries. + * + * If you sent an invoice requesting a shipping address and the parameter isFlexible was specified, the Bot API will send an Update with a shipping_query field to the bot. + * @param shippingQueryId Unique identifier for the query to be answered. + * @param ok Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible) + * @param shippingOptions Optional. Required if ok is True. A JSON-serialized array of available shipping options. + * @param errorMessage Optional. Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user. + * @return On success, True is returned. + */ + bool answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector<ShippingOption>& shippingOptions = nullptr, const std::string& errorMessage = "") const; + + /** + * @brief Use this method to respond to such pre-checkout queries. + * + * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field preCheckoutQuery. + * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. + * + * @param preCheckoutQueryId Unique identifier for the query to be answered + * @param ok Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems. + * @param errorMessage Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user. + * @return On success, True is returned. + */ + bool answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage = "") const; + + /** * @brief Use this method to send .webp stickers. * @param chatId Unique identifier for the target chat. * @param sticker Sticker to send. @@ -214,7 +274,7 @@ public: * @return On success, a StickerSet object is returned. */ StickerSet::Ptr getStickerSet(const std::string& name) const; - + /** * @brief Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). * @param userId User identifier of sticker file owner. diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 6df9f36..1784383 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -413,6 +413,10 @@ public: } private: + inline void removeLastComma(std::string& input) const { + input.erase(input.length() - 1); + } + template<typename T> void appendToJson(std::string& json, const std::string& varName, const std::shared_ptr<T>& value) const { if (value == nullptr) { diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h index 51ec58f..bee3398 100644 --- a/include/tgbot/types/InlineKeyboardButton.h +++ b/include/tgbot/types/InlineKeyboardButton.h @@ -44,16 +44,23 @@ public: std::string switchInlineQuery; /** - * @brief Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. - */ + * @brief Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. + */ std::string switchInlineQueryCurrentChat; /** * @brief Optional. Description of the game that will be launched when the user presses the button. * - * NOTE: This type of button must always be the first button in the first row. + * Note: This type of button must always be the first button in the first row. */ CallbackGame::Ptr callbackGame; + + /** + * @brief Optional. Specify True, to send a Pay button. + * + * Note: This type of button must always be the first button in the first row. + */ + bool pay = false; }; } diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index 4f982fa..db330a4 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -41,6 +41,8 @@ #include "tgbot/types/MessageEntity.h" #include "tgbot/types/Venue.h" #include "tgbot/types/Voice.h" +#include "tgbot/types/Invoice.h" +#include "tgbot/types/SuccessfulPayment.h" namespace TgBot { @@ -53,15 +55,6 @@ class Message { public: typedef std::shared_ptr<Message> Ptr; - Message(){ - deleteChatPhoto = false; - groupChatCreated = false; - supergroupChatCreated = false; - channelChatCreated = false; - migrateToChatId = 0; - migrateFromChatId = 0; - } - /** * @brief Unique message identifier. */ @@ -220,32 +213,32 @@ public: /** * @brief Optional. Informs that the group photo was deleted. */ - bool deleteChatPhoto; + bool deleteChatPhoto = false; /** * @brief Optional. Informs that the group has been created. */ - bool groupChatCreated; + bool groupChatCreated = false; /** * @brief Optional. Service message: the supergroup has been created. */ - bool supergroupChatCreated; + bool supergroupChatCreated = false; /** * @brief Optional. Service message: the channel has been created. */ - bool channelChatCreated; + bool channelChatCreated = false; /** * @brief Optional. The group has been migrated to a supergroup with the specified identifier, not exceeding 1e13 by absolute value. */ - int64_t migrateToChatId; + int64_t migrateToChatId = 0; /** * @brief Optional. The supergroup has been migrated from a group with the specified identifier, not exceeding 1e13 by absolute value */ - int64_t migrateFromChatId; + int64_t migrateFromChatId = 0; /** * @brief Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply. @@ -253,6 +246,16 @@ public: Message::Ptr pinnedMessage; /** + * @brief Optional. Message is an invoice for a payment, information about the invoice. + */ + Invoice::Ptr invoice; + + /** + * @brief Optional. Message is a service message about a successful payment, information about the payment. + */ + SuccessfulPayment::Ptr successfulPayment; + + /** * @brief Optional. The domain name of the website on which the user has logged in. */ std::string connectedWebsite; diff --git a/include/tgbot/types/Update.h b/include/tgbot/types/Update.h index 61111b5..1dcac76 100644 --- a/include/tgbot/types/Update.h +++ b/include/tgbot/types/Update.h @@ -29,6 +29,8 @@ #include "tgbot/types/InlineQuery.h" #include "tgbot/types/ChosenInlineResult.h" #include "tgbot/types/CallbackQuery.h" +#include "tgbot/types/ShippingQuery.h" +#include "tgbot/types/PreCheckoutQuery.h" namespace TgBot { @@ -81,6 +83,20 @@ public: * @brief Optional. New incoming callback query. */ CallbackQuery::Ptr callbackQuery; + + /** + * @brief Optional. New incoming shipping query. + * + * Only for invoices with flexible price + */ + ShippingQuery::Ptr shippingQuery; + + /** + * @brief Optional. New incoming pre-checkout query. + * + * Contains full information about checkout + */ + PreCheckoutQuery::Ptr preCheckoutQuery; }; } |