From 4e5c4a601c382969b5da65160893d870f8a49875 Mon Sep 17 00:00:00 2001 From: ZyGout Date: Fri, 27 Jun 2025 01:00:22 -0400 Subject: [PATCH] feat(billing): add cancel subscription method to BillingManager.fetchCurrentSubscription() --- src/managers/BillingManager.js | 40 ++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/managers/BillingManager.js b/src/managers/BillingManager.js index 70553390..f705639f 100644 --- a/src/managers/BillingManager.js +++ b/src/managers/BillingManager.js @@ -58,9 +58,45 @@ class BillingManager extends BaseManager { async fetchCurrentSubscription() { // https://discord.com/api/v9/users/@me/billing/subscriptions const d = await this.client.api.users('@me').billing.subscriptions.get(); - this.currentSubscription = new Collection(d.map(s => [s.id, s])); + + const currentSubscription = d.map(subscription => { + return { + ...subscription, + /** + * Cancels the subscription + * @returns {Promise} + */ + cancel: async () => { + // https://discord.com/api/v9/users/@me/billing/subscriptions/{subscription.id}?location_stack=user%20settings&location_stack=subscription%20header&location_stack=premium%20subscription%20cancellation%20modal + return void await this.client.api.users('@me').billing.subscriptions(subscription.id).patch({ + data: { + payment_source_token: null, + gateway_checkout_context: null, + expected_invoice_price: { + amount: 0, + currency: subscription.currency + }, + expected_renewal_price: { + amount: 0, + currency: subscription.currency + }, + items: [] + }, + query: { + location_stack: [ + "user settings", + "subscription header", + "premium subscription cancellation modal" + ] + } + }); + } + }; + }); + + this.currentSubscription = new Collection(currentSubscription.map(s => [s.id, s])); return this.currentSubscription; } } -module.exports = BillingManager; +module.exports = BillingManager; \ No newline at end of file