github.com/stripe/stripe-go/v76@v76.25.0/subscriptionschedule/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package subscriptionschedule provides the /subscription_schedules APIs 8 package subscriptionschedule 9 10 import ( 11 "net/http" 12 13 stripe "github.com/stripe/stripe-go/v76" 14 "github.com/stripe/stripe-go/v76/form" 15 ) 16 17 // Client is used to invoke /subscription_schedules APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new subscription schedule. 24 func New(params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new subscription schedule. 29 func (c Client) New(params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) { 30 subscriptionschedule := &stripe.SubscriptionSchedule{} 31 err := c.B.Call( 32 http.MethodPost, 33 "/v1/subscription_schedules", 34 c.Key, 35 params, 36 subscriptionschedule, 37 ) 38 return subscriptionschedule, err 39 } 40 41 // Get returns the details of a subscription schedule. 42 func Get(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) { 43 return getC().Get(id, params) 44 } 45 46 // Get returns the details of a subscription schedule. 47 func (c Client) Get(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) { 48 path := stripe.FormatURLPath("/v1/subscription_schedules/%s", id) 49 subscriptionschedule := &stripe.SubscriptionSchedule{} 50 err := c.B.Call(http.MethodGet, path, c.Key, params, subscriptionschedule) 51 return subscriptionschedule, err 52 } 53 54 // Update updates a subscription schedule's properties. 55 func Update(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) { 56 return getC().Update(id, params) 57 } 58 59 // Update updates a subscription schedule's properties. 60 func (c Client) Update(id string, params *stripe.SubscriptionScheduleParams) (*stripe.SubscriptionSchedule, error) { 61 path := stripe.FormatURLPath("/v1/subscription_schedules/%s", id) 62 subscriptionschedule := &stripe.SubscriptionSchedule{} 63 err := c.B.Call(http.MethodPost, path, c.Key, params, subscriptionschedule) 64 return subscriptionschedule, err 65 } 66 67 // Cancel is the method for the `POST /v1/subscription_schedules/{schedule}/cancel` API. 68 func Cancel(id string, params *stripe.SubscriptionScheduleCancelParams) (*stripe.SubscriptionSchedule, error) { 69 return getC().Cancel(id, params) 70 } 71 72 // Cancel is the method for the `POST /v1/subscription_schedules/{schedule}/cancel` API. 73 func (c Client) Cancel(id string, params *stripe.SubscriptionScheduleCancelParams) (*stripe.SubscriptionSchedule, error) { 74 path := stripe.FormatURLPath("/v1/subscription_schedules/%s/cancel", id) 75 subscriptionschedule := &stripe.SubscriptionSchedule{} 76 err := c.B.Call(http.MethodPost, path, c.Key, params, subscriptionschedule) 77 return subscriptionschedule, err 78 } 79 80 // Release is the method for the `POST /v1/subscription_schedules/{schedule}/release` API. 81 func Release(id string, params *stripe.SubscriptionScheduleReleaseParams) (*stripe.SubscriptionSchedule, error) { 82 return getC().Release(id, params) 83 } 84 85 // Release is the method for the `POST /v1/subscription_schedules/{schedule}/release` API. 86 func (c Client) Release(id string, params *stripe.SubscriptionScheduleReleaseParams) (*stripe.SubscriptionSchedule, error) { 87 path := stripe.FormatURLPath("/v1/subscription_schedules/%s/release", id) 88 subscriptionschedule := &stripe.SubscriptionSchedule{} 89 err := c.B.Call(http.MethodPost, path, c.Key, params, subscriptionschedule) 90 return subscriptionschedule, err 91 } 92 93 // List returns a list of subscription schedules. 94 func List(params *stripe.SubscriptionScheduleListParams) *Iter { 95 return getC().List(params) 96 } 97 98 // List returns a list of subscription schedules. 99 func (c Client) List(listParams *stripe.SubscriptionScheduleListParams) *Iter { 100 return &Iter{ 101 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 102 list := &stripe.SubscriptionScheduleList{} 103 err := c.B.CallRaw(http.MethodGet, "/v1/subscription_schedules", c.Key, b, p, list) 104 105 ret := make([]interface{}, len(list.Data)) 106 for i, v := range list.Data { 107 ret[i] = v 108 } 109 110 return ret, list, err 111 }), 112 } 113 } 114 115 // Iter is an iterator for subscription schedules. 116 type Iter struct { 117 *stripe.Iter 118 } 119 120 // SubscriptionSchedule returns the subscription schedule which the iterator is currently pointing to. 121 func (i *Iter) SubscriptionSchedule() *stripe.SubscriptionSchedule { 122 return i.Current().(*stripe.SubscriptionSchedule) 123 } 124 125 // SubscriptionScheduleList returns the current list object which the iterator is 126 // currently using. List objects will change as new API calls are made to 127 // continue pagination. 128 func (i *Iter) SubscriptionScheduleList() *stripe.SubscriptionScheduleList { 129 return i.List().(*stripe.SubscriptionScheduleList) 130 } 131 132 func getC() Client { 133 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 134 }