Skip to content

Commit

Permalink
Add one time purchase SKUs (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian authored Apr 24, 2024
1 parent 3dacb4b commit 8a19ae0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
10 changes: 9 additions & 1 deletion discord/entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ type Entitlement struct {
StartsAt *time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at"`
GuildID *snowflake.ID `json:"guild_id"`
Consumed *bool `json:"consumed"`
}

type EntitlementType int

const (
EntitlementTypeApplicationSubscription EntitlementType = 8
EntitlementTypePurchase EntitlementType = iota + 1
EntitlementTypePremiumSubscription
EntitlementTypeDeveloperGift
EntitlementTypeTestModePurchase
EntitlementTypeFreePurchase
EntitlementTypeUserGift
EntitlementTypePremiumPurchase
EntitlementTypeApplicationSubscription
)

type TestEntitlementCreate struct {
Expand Down
5 changes: 4 additions & 1 deletion discord/sku.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ type SKU struct {
type SKUType int

const (
SKUTypeSubscription SKUType = iota + 5
SKUTypeDurable SKUType = iota + 2
SKUTypeConsumable
_
SKUTypeSubscription
SKUTypeSubscriptionGroup
)

Expand Down
5 changes: 5 additions & 0 deletions rest/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Applications interface {
GetEntitlements(applicationID snowflake.ID, userID snowflake.ID, guildID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, excludeEnded bool, skuIDs []snowflake.ID, opts ...RequestOpt) ([]discord.Entitlement, error)
CreateTestEntitlement(applicationID snowflake.ID, entitlementCreate discord.TestEntitlementCreate, opts ...RequestOpt) (*discord.Entitlement, error)
DeleteTestEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error
ConsumeEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error

GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.SKU, error)
}
Expand Down Expand Up @@ -209,6 +210,10 @@ func (s *applicationsImpl) DeleteTestEntitlement(applicationID snowflake.ID, ent
return s.client.Do(DeleteTestEntitlement.Compile(nil, applicationID, entitlementID), nil, nil, opts...)
}

func (s *applicationsImpl) ConsumeEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error {
return s.client.Do(ConsumeEntitlement.Compile(nil, applicationID, entitlementID), nil, nil, opts...)
}

func (s *applicationsImpl) GetSKUs(applicationID snowflake.ID, opts ...RequestOpt) (skus []discord.SKU, err error) {
err = s.client.Do(GetSKUs.Compile(nil, applicationID), nil, &skus, opts...)
return
Expand Down
1 change: 1 addition & 0 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ var (
GetEntitlements = NewEndpoint(http.MethodGet, "/applications/{application.id}/entitlements")
CreateTestEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements")
DeleteTestEntitlement = NewEndpoint(http.MethodDelete, "/applications/{application.id}/entitlements/{entitlement.id}")
ConsumeEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements/{entitlement.id}/consume")

GetSKUs = NewEndpoint(http.MethodGet, "/applications/{application.id}/skus")
)
Expand Down

0 comments on commit 8a19ae0

Please sign in to comment.