Skip to content

Commit

Permalink
feat: add subscriptions
Browse files Browse the repository at this point in the history
Co-authored-by: TÆMBØ <TAEMBO@users.noreply.github.com>
  • Loading branch information
sdanialraza and TAEMBO committed Aug 28, 2024
1 parent 58848be commit 247367a
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 2 deletions.
7 changes: 6 additions & 1 deletion deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ export enum GatewayDispatchEvents {
EntitlementCreate = 'ENTITLEMENT_CREATE',
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
EntitlementDelete = 'ENTITLEMENT_DELETE',
SubscriptionCreate = 'SUBSCRIPTION_CREATE',
SubscriptionUpdate = 'SUBSCRIPTION_UPDATE',
SubscriptionDelete = 'SUBSCRIPTION_DELETE',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -709,7 +712,9 @@ export type GatewayEntitlementModifyDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
*/
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;
export type GatewayEntitlementCreateDispatchData = Omit<GatewayEntitlementModifyDispatchData, 'ends_at'> & {
ends_at: GatewayEntitlementModifyDispatchData['ends_at'] | null;
};

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
Expand Down
63 changes: 63 additions & 0 deletions deno/payloads/v10/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export enum SKUFlags {
UserSubscription = 1 << 8,
}

/**
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
*/
export enum SKUType {
/**
* Durable one-time purchase
Expand All @@ -153,3 +156,63 @@ export enum SKUType {
*/
SubscriptionGroup = 6,
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-object
*/
export interface APISubscription {
/**
* ID of the subscription
*/
id: Snowflake;
/**
* ID of the user who is subscribed
*/
user_id: Snowflake;
/**
* List of SKUs subscribed to
*/
sku_ids: Snowflake[];
/**
* List of entitlements granted for this subscription
*/
entitlement_ids: Snowflake[];
/**
* Start of the current subscription period
*/
current_period_start: string;
/**
* End of the current subscription period
*/
current_period_end: string;
/**
* Current status of the subscription
*/
status: SubscriptionStatus;
/**
* When the subscription was canceled
*/
canceled_at: string | null;
/**
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
*/
country?: string;
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
*/
export enum SubscriptionStatus {
/**
* Subscription is active and scheduled to renew.
*/
Active = 1,
/**
* Subscription is active but will not renew.
*/
Ending,
/**
* Subscription is inactive and not being charged.
*/
Inactive,
}
63 changes: 63 additions & 0 deletions deno/payloads/v9/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export enum SKUFlags {
UserSubscription = 1 << 8,
}

/**
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
*/
export enum SKUType {
/**
* Durable one-time purchase
Expand All @@ -153,3 +156,63 @@ export enum SKUType {
*/
SubscriptionGroup = 6,
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-object
*/
export interface APISubscription {
/**
* ID of the subscription
*/
id: Snowflake;
/**
* ID of the user who is subscribed
*/
user_id: Snowflake;
/**
* List of SKUs subscribed to
*/
sku_ids: Snowflake[];
/**
* List of entitlements granted for this subscription
*/
entitlement_ids: Snowflake[];
/**
* Start of the current subscription period
*/
current_period_start: string;
/**
* End of the current subscription period
*/
current_period_end: string;
/**
* Current status of the subscription
*/
status: SubscriptionStatus;
/**
* When the subscription was canceled
*/
canceled_at: string | null;
/**
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
*/
country?: string;
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
*/
export enum SubscriptionStatus {
/**
* Subscription is active and scheduled to renew.
*/
Active = 1,
/**
* Subscription is active but will not renew.
*/
Ending,
/**
* Subscription is inactive and not being charged.
*/
Inactive,
}
16 changes: 16 additions & 0 deletions deno/rest/v10/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,22 @@ export const Routes = {
applicationEmoji(applicationId: Snowflake, emojiId: Snowflake) {
return `/applications/${applicationId}/emojis/${emojiId}` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions`
*/
skuSubscriptions(skuId: Snowflake) {
return `/skus/${skuId}/subscriptions` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions/${subscription.id}`
*/
skuSubscription(skuId: Snowflake, subscriptionId: Snowflake) {
return `/skus/${skuId}/subscriptions/${subscriptionId}` as const;
},
};

export const StickerPackApplicationId = '710982414301790216';
Expand Down
16 changes: 16 additions & 0 deletions deno/rest/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,22 @@ export const Routes = {
applicationEmoji(applicationId: Snowflake, emojiId: Snowflake) {
return `/applications/${applicationId}/emojis/${emojiId}` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions`
*/
skuSubscriptions(skuId: Snowflake) {
return `/skus/${skuId}/subscriptions` as const;
},

/**
* Route for:
* - GET `/skus/{sku.id}/subscriptions/${subscription.id}`
*/
skuSubscription(skuId: Snowflake, subscriptionId: Snowflake) {
return `/skus/${skuId}/subscriptions/${subscriptionId}` as const;
},
};

export const StickerPackApplicationId = '710982414301790216';
Expand Down
7 changes: 6 additions & 1 deletion gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ export enum GatewayDispatchEvents {
EntitlementCreate = 'ENTITLEMENT_CREATE',
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
EntitlementDelete = 'ENTITLEMENT_DELETE',
SubscriptionCreate = 'SUBSCRIPTION_CREATE',
SubscriptionUpdate = 'SUBSCRIPTION_UPDATE',
SubscriptionDelete = 'SUBSCRIPTION_DELETE',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -709,7 +712,9 @@ export type GatewayEntitlementModifyDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
*/
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;
export type GatewayEntitlementCreateDispatchData = Omit<GatewayEntitlementModifyDispatchData, 'ends_at'> & {
ends_at: GatewayEntitlementModifyDispatchData['ends_at'] | null;
};

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
Expand Down
63 changes: 63 additions & 0 deletions payloads/v10/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export enum SKUFlags {
UserSubscription = 1 << 8,
}

/**
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
*/
export enum SKUType {
/**
* Durable one-time purchase
Expand All @@ -153,3 +156,63 @@ export enum SKUType {
*/
SubscriptionGroup = 6,
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-object
*/
export interface APISubscription {
/**
* ID of the subscription
*/
id: Snowflake;
/**
* ID of the user who is subscribed
*/
user_id: Snowflake;
/**
* List of SKUs subscribed to
*/
sku_ids: Snowflake[];
/**
* List of entitlements granted for this subscription
*/
entitlement_ids: Snowflake[];
/**
* Start of the current subscription period
*/
current_period_start: string;
/**
* End of the current subscription period
*/
current_period_end: string;
/**
* Current status of the subscription
*/
status: SubscriptionStatus;
/**
* When the subscription was canceled
*/
canceled_at: string | null;
/**
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
*/
country?: string;
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
*/
export enum SubscriptionStatus {
/**
* Subscription is active and scheduled to renew.
*/
Active = 1,
/**
* Subscription is active but will not renew.
*/
Ending,
/**
* Subscription is inactive and not being charged.
*/
Inactive,
}
63 changes: 63 additions & 0 deletions payloads/v9/monetization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export enum SKUFlags {
UserSubscription = 1 << 8,
}

/**
* https://discord.com/developers/docs/resources/sku#sku-object-sku-types
*/
export enum SKUType {
/**
* Durable one-time purchase
Expand All @@ -153,3 +156,63 @@ export enum SKUType {
*/
SubscriptionGroup = 6,
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-object
*/
export interface APISubscription {
/**
* ID of the subscription
*/
id: Snowflake;
/**
* ID of the user who is subscribed
*/
user_id: Snowflake;
/**
* List of SKUs subscribed to
*/
sku_ids: Snowflake[];
/**
* List of entitlements granted for this subscription
*/
entitlement_ids: Snowflake[];
/**
* Start of the current subscription period
*/
current_period_start: string;
/**
* End of the current subscription period
*/
current_period_end: string;
/**
* Current status of the subscription
*/
status: SubscriptionStatus;
/**
* When the subscription was canceled
*/
canceled_at: string | null;
/**
* ISO3166-1 alpha-2 country code of the payment source used to purchase the subscription. Missing unless queried with a private OAuth scope.
*/
country?: string;
}

/**
* https://discord.com/developers/docs/resources/subscription#subscription-statuses
*/
export enum SubscriptionStatus {
/**
* Subscription is active and scheduled to renew.
*/
Active = 1,
/**
* Subscription is active but will not renew.
*/
Ending,
/**
* Subscription is inactive and not being charged.
*/
Inactive,
}
Loading

0 comments on commit 247367a

Please sign in to comment.