@@ -3578,3 +3578,137 @@ func (s *Session) PollExpire(channelID, messageID string) (msg *Message, err err
3578
3578
err = unmarshal (body , & msg )
3579
3579
return
3580
3580
}
3581
+
3582
+ // ----------------------------------------------------------------------
3583
+ // Functions specific to monetization
3584
+ // ----------------------------------------------------------------------
3585
+
3586
+ // SKUs returns all SKUs for a given application.
3587
+ // appID : The ID of the application.
3588
+ func (s * Session ) SKUs (appID string ) (skus []* SKU , err error ) {
3589
+ endpoint := EndpointApplicationSKUs (appID )
3590
+
3591
+ body , err := s .RequestWithBucketID ("GET" , endpoint , nil , endpoint )
3592
+ if err != nil {
3593
+ return
3594
+ }
3595
+
3596
+ err = unmarshal (body , & skus )
3597
+ return
3598
+ }
3599
+
3600
+ // Entitlements returns all Entitlements for a given app, active and expired.
3601
+ // appID : The ID of the application.
3602
+ // filterOptions : Optional filter options; otherwise set it to nil.
3603
+ func (s * Session ) Entitlements (appID string , filterOptions * EntitlementFilterOptions , options ... RequestOption ) (entitlements []* Entitlement , err error ) {
3604
+ endpoint := EndpointEntitlements (appID )
3605
+
3606
+ queryParams := url.Values {}
3607
+ if filterOptions != nil {
3608
+ if filterOptions .UserID != "" {
3609
+ queryParams .Set ("user_id" , filterOptions .UserID )
3610
+ }
3611
+ if filterOptions .SkuIDs != nil && len (filterOptions .SkuIDs ) > 0 {
3612
+ queryParams .Set ("sku_ids" , strings .Join (filterOptions .SkuIDs , "," ))
3613
+ }
3614
+ if filterOptions .Before != nil {
3615
+ queryParams .Set ("before" , filterOptions .Before .Format (time .RFC3339 ))
3616
+ }
3617
+ if filterOptions .After != nil {
3618
+ queryParams .Set ("after" , filterOptions .After .Format (time .RFC3339 ))
3619
+ }
3620
+ if filterOptions .Limit > 0 {
3621
+ queryParams .Set ("limit" , strconv .Itoa (filterOptions .Limit ))
3622
+ }
3623
+ if filterOptions .GuildID != "" {
3624
+ queryParams .Set ("guild_id" , filterOptions .GuildID )
3625
+ }
3626
+ if filterOptions .ExcludeEnded {
3627
+ queryParams .Set ("exclude_ended" , "true" )
3628
+ }
3629
+ }
3630
+
3631
+ body , err := s .RequestWithBucketID ("GET" , endpoint + "?" + queryParams .Encode (), nil , endpoint , options ... )
3632
+ if err != nil {
3633
+ return
3634
+ }
3635
+
3636
+ err = unmarshal (body , & entitlements )
3637
+ return
3638
+ }
3639
+
3640
+ // EntitlementConsume marks a given One-Time Purchase for the user as consumed.
3641
+ func (s * Session ) EntitlementConsume (appID , entitlementID string , options ... RequestOption ) (err error ) {
3642
+ _ , err = s .RequestWithBucketID ("POST" , EndpointEntitlementConsume (appID , entitlementID ), nil , EndpointEntitlementConsume (appID , "" ), options ... )
3643
+ return
3644
+ }
3645
+
3646
+ // EntitlementTestCreate creates a test entitlement to a given SKU for a given guild or user.
3647
+ // Discord will act as though that user or guild has entitlement to your premium offering.
3648
+ func (s * Session ) EntitlementTestCreate (appID string , data * EntitlementTest , options ... RequestOption ) (err error ) {
3649
+ endpoint := EndpointEntitlements (appID )
3650
+
3651
+ _ , err = s .RequestWithBucketID ("POST" , endpoint , data , endpoint , options ... )
3652
+ return
3653
+ }
3654
+
3655
+ // EntitlementTestDelete deletes a currently-active test entitlement. Discord will act as though
3656
+ // that user or guild no longer has entitlement to your premium offering.
3657
+ func (s * Session ) EntitlementTestDelete (appID , entitlementID string , options ... RequestOption ) (err error ) {
3658
+ _ , err = s .RequestWithBucketID ("DELETE" , EndpointEntitlement (appID , entitlementID ), nil , EndpointEntitlement (appID , "" ), options ... )
3659
+ return
3660
+ }
3661
+
3662
+ // Subscriptions returns all subscriptions containing the SKU.
3663
+ // skuID : The ID of the SKU.
3664
+ // userID : User ID for which to return subscriptions. Required except for OAuth queries.
3665
+ // before : Optional timestamp to retrieve subscriptions before this time.
3666
+ // after : Optional timestamp to retrieve subscriptions after this time.
3667
+ // limit : Optional maximum number of subscriptions to return (1-100, default 50).
3668
+ func (s * Session ) Subscriptions (skuID string , userID string , before , after * time.Time , limit int , options ... RequestOption ) (subscriptions []* Subscription , err error ) {
3669
+ endpoint := EndpointSubscriptions (skuID )
3670
+
3671
+ queryParams := url.Values {}
3672
+ if before != nil {
3673
+ queryParams .Set ("before" , before .Format (time .RFC3339 ))
3674
+ }
3675
+ if after != nil {
3676
+ queryParams .Set ("after" , after .Format (time .RFC3339 ))
3677
+ }
3678
+ if userID != "" {
3679
+ queryParams .Set ("user_id" , userID )
3680
+ }
3681
+ if limit > 0 {
3682
+ queryParams .Set ("limit" , strconv .Itoa (limit ))
3683
+ }
3684
+
3685
+ body , err := s .RequestWithBucketID ("GET" , endpoint + "?" + queryParams .Encode (), nil , endpoint , options ... )
3686
+ if err != nil {
3687
+ return
3688
+ }
3689
+
3690
+ err = unmarshal (body , & subscriptions )
3691
+ return
3692
+ }
3693
+
3694
+ // Subscription returns a subscription by its SKU and subscription ID.
3695
+ // skuID : The ID of the SKU.
3696
+ // subscriptionID : The ID of the subscription.
3697
+ // userID : User ID for which to return the subscription. Required except for OAuth queries.
3698
+ func (s * Session ) Subscription (skuID , subscriptionID , userID string , options ... RequestOption ) (subscription * Subscription , err error ) {
3699
+ endpoint := EndpointSubscription (skuID , subscriptionID )
3700
+
3701
+ queryParams := url.Values {}
3702
+ if userID != "" {
3703
+ // Unlike stated in the documentation, the user_id parameter is required here.
3704
+ queryParams .Set ("user_id" , userID )
3705
+ }
3706
+
3707
+ body , err := s .RequestWithBucketID ("GET" , endpoint + "?" + queryParams .Encode (), nil , endpoint , options ... )
3708
+ if err != nil {
3709
+ return
3710
+ }
3711
+
3712
+ err = unmarshal (body , & subscription )
3713
+ return
3714
+ }
0 commit comments