Skip to content

Commit cbe762b

Browse files
committed
I noticed that the onSuccessfulPayment method is not available in the current version of the tgbot-cpp library. This makes it challenging to handle successful payment events directly using the library.
Could you let me know if there are any plans to add this method in future updates? If yes, when can we expect it to be implemented? Thank you for your work on this library, and I look forward to your response! Best regards,
1 parent 0aba021 commit cbe762b

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.10.2)
22
project(TgBot)
33

4+
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
5+
46
if(POLICY CMP0074)
57
cmake_policy(SET CMP0074 NEW) # find_package() uses <PackageName>_ROOT variables
68
endif()

include/tgbot/EventBroadcaster.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ friend EventHandler;
4343
typedef std::function<void (const PollAnswer::Ptr)> PollAnswerListener;
4444
typedef std::function<void (const ChatMemberUpdated::Ptr)> ChatMemberUpdatedListener;
4545
typedef std::function<void (const ChatJoinRequest::Ptr)> ChatJoinRequestListener;
46+
typedef std::function<void (const SuccessfulPayment::Ptr)> SuccessfulPaymentListener;
4647

4748
/**
4849
* @brief Registers listener which receives new incoming message of any kind - text, photo, sticker, etc.
@@ -202,6 +203,16 @@ friend EventHandler;
202203
_onChatJoinRequestListeners.push_back(listener);
203204
}
204205

206+
/**
207+
* @brief Registers listener which receives information about successful payments.
208+
* This listener is triggered when a successful payment is received by the bot.
209+
*
210+
* @param listener Listener.
211+
*/
212+
inline void onSuccessfulPayment(const SuccessfulPaymentListener& listener) {
213+
_onSuccessfulPaymentListeners.push_back(listener);
214+
}
215+
205216
private:
206217
template<typename ListenerType, typename ObjectType>
207218
inline void broadcast(const std::vector<ListenerType>& listeners, const ObjectType object) const {
@@ -278,6 +289,10 @@ friend EventHandler;
278289
broadcast<ChatJoinRequestListener, ChatJoinRequest::Ptr>(_onChatJoinRequestListeners, result);
279290
}
280291

292+
inline void broadcastSuccessfulPayment(const SuccessfulPayment::Ptr& payment) const {
293+
broadcast<SuccessfulPaymentListener, SuccessfulPayment::Ptr>(_onSuccessfulPaymentListeners, payment);
294+
}
295+
281296
std::vector<MessageListener> _onAnyMessageListeners;
282297
std::unordered_map<std::string, MessageListener> _onCommandListeners;
283298
std::vector<MessageListener> _onUnknownCommandListeners;
@@ -293,6 +308,8 @@ friend EventHandler;
293308
std::vector<ChatMemberUpdatedListener> _onMyChatMemberListeners;
294309
std::vector<ChatMemberUpdatedListener> _onChatMemberListeners;
295310
std::vector<ChatJoinRequestListener> _onChatJoinRequestListeners;
311+
std::vector<SuccessfulPaymentListener> _onSuccessfulPaymentListeners;
312+
296313
};
297314

298315
}

src/EventHandler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ void EventHandler::handleMessage(const Message::Ptr& message) const {
7272
} else {
7373
_broadcaster.broadcastNonCommandMessage(message);
7474
}
75+
76+
if (message->successfulPayment != nullptr) {
77+
_broadcaster.broadcastSuccessfulPayment(message->successfulPayment);
78+
}
7579
}
7680

7781
}

0 commit comments

Comments
 (0)