Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added consuming an entitlement #1170

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3780,6 +3780,16 @@ class DPP_EXPORT cluster {
*/
void entitlement_test_delete(snowflake entitlement_id, command_completion_event_t callback = utility::log_error());

/**
* @brief For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
*
* @see https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* @param entitlement_id The entitlement to mark as consumed.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::confirmation object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void entitlement_consume(snowflake entitlement_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Returns all SKUs for a given application.
* @note Because of how Discord's SKU and subscription systems work, you will see two SKUs for your premium offering.
Expand Down
11 changes: 11 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_entitlement_test_delete(snowflake entitlement_id);

/**
* @brief For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
*
* @see dpp::cluster::entitlement_consume
* @see https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* @param entitlement_id The entitlement to mark as consumed.
* @return confirmation returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_entitlement_consume(snowflake entitlement_id);

/**
* @brief Get the gateway information for the bot using the token
* @see dpp::cluster::get_gateway_bot
Expand Down
14 changes: 14 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,20 @@ entitlement entitlement_test_create_sync(const class entitlement& new_entitlemen
*/
confirmation entitlement_test_delete_sync(snowflake entitlement_id);

/**
* @brief For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
*
* @see dpp::cluster::entitlement_consume
* @see https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* @param entitlement_id The entitlement to mark as consumed.
* @return confirmation returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
confirmation entitlement_consume_sync(snowflake entitlement_id);

/**
* @brief Get the gateway information for the bot using the token
* @see dpp::cluster::get_gateway_bot
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/cluster/entitlement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ void cluster::entitlement_test_delete(const class snowflake entitlement_id, comm
rest_request<confirmation>(this, API_PATH "/applications", me.id.str(), "entitlements/" + entitlement_id.str(), m_delete, "", callback);
}

void cluster::entitlement_consume(const class snowflake entitlement_id, command_completion_event_t callback) {
rest_request<confirmation>(this, API_PATH "/applications", me.id.str(), "entitlements/" + entitlement_id.str() + "/consume", m_post, "", callback);
}

} // namespace dpp
4 changes: 4 additions & 0 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ async<confirmation_callback_t> cluster::co_entitlement_test_delete(const class s
return async{ this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_test_delete), entitlement_id };
}

async<confirmation_callback_t> cluster::co_entitlement_consume(const class snowflake entitlement_id) {
return async{ this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_consume), entitlement_id };
}

async<confirmation_callback_t> cluster::co_get_gateway_bot() {
return async{ this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::get_gateway_bot) };
}
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ confirmation cluster::entitlement_test_delete_sync(const class snowflake entitle
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_test_delete), entitlement_id);
}

confirmation cluster::entitlement_consume_sync(const class snowflake entitlement_id) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_consume), entitlement_id);
}

gateway cluster::get_gateway_bot_sync() {
return dpp::sync<gateway>(this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::get_gateway_bot));
}
Expand Down
Loading