-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscription_notes_controller.go
188 lines (169 loc) · 7.25 KB
/
subscription_notes_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
Package advancedbilling
This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package advancedbilling
import (
"context"
"fmt"
"github.com/apimatic/go-core-runtime/utilities"
"github.com/maxio-com/ab-golang-sdk/models"
"net/http"
)
// SubscriptionNotesController represents a controller struct.
type SubscriptionNotesController struct {
baseController
}
// NewSubscriptionNotesController creates a new instance of SubscriptionNotesController.
// It takes a baseController as a parameter and returns a pointer to the SubscriptionNotesController.
func NewSubscriptionNotesController(baseController baseController) *SubscriptionNotesController {
subscriptionNotesController := SubscriptionNotesController{baseController: baseController}
return &subscriptionNotesController
}
// CreateSubscriptionNote takes context, subscriptionId, body as parameters and
// returns an models.ApiResponse with models.SubscriptionNoteResponse data and
// an error if there was an issue with the request or response.
// Use the following method to create a note for a subscription.
// ## How to Use Subscription Notes
// Notes allow you to record information about a particular Subscription in a free text format.
// If you have structured data such as birth date, color, etc., consider using Metadata instead.
// Full documentation on how to use Notes in the Advanced Billing UI can be located [here](https://maxio.zendesk.com/hc/en-us/articles/24251712214413-Subscription-Summary-Overview).
func (s *SubscriptionNotesController) CreateSubscriptionNote(
ctx context.Context,
subscriptionId int,
body *models.UpdateSubscriptionNoteRequest) (
models.ApiResponse[models.SubscriptionNoteResponse],
error) {
req := s.prepareRequest(
ctx,
"POST",
fmt.Sprintf("/subscriptions/%v/notes.json", subscriptionId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.SubscriptionNoteResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.SubscriptionNoteResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// ListSubscriptionNotesInput represents the input of the ListSubscriptionNotes endpoint.
type ListSubscriptionNotesInput struct {
// The Chargify id of the subscription
SubscriptionId int
// Result records are organized in pages. By default, the first page of results is displayed. The page parameter specifies a page number of results to fetch. You can start navigating through the pages to consume the results. You do this by passing in a page parameter. Retrieve the next page by adding ?page=2 to the query string. If there are no results to return, then an empty result set will be returned.
// Use in query `page=1`.
Page *int
// This parameter indicates how many records to fetch in each request. Default value is 20. The maximum allowed values is 200; any per_page value over 200 will be changed to 200.
// Use in query `per_page=200`.
PerPage *int
}
// ListSubscriptionNotes takes context, subscriptionId, page, perPage as parameters and
// returns an models.ApiResponse with []models.SubscriptionNoteResponse data and
// an error if there was an issue with the request or response.
// Use this method to retrieve a list of Notes associated with a Subscription. The response will be an array of Notes.
func (s *SubscriptionNotesController) ListSubscriptionNotes(
ctx context.Context,
input ListSubscriptionNotesInput) (
models.ApiResponse[[]models.SubscriptionNoteResponse],
error) {
req := s.prepareRequest(
ctx,
"GET",
fmt.Sprintf("/subscriptions/%v/notes.json", input.SubscriptionId),
)
req.Authenticate(NewAuth("BasicAuth"))
if input.Page != nil {
req.QueryParam("page", *input.Page)
}
if input.PerPage != nil {
req.QueryParam("per_page", *input.PerPage)
}
var result []models.SubscriptionNoteResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[[]models.SubscriptionNoteResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// ReadSubscriptionNote takes context, subscriptionId, noteId as parameters and
// returns an models.ApiResponse with models.SubscriptionNoteResponse data and
// an error if there was an issue with the request or response.
// Once you have obtained the ID of the note you wish to read, use this method to show a particular note attached to a subscription.
func (s *SubscriptionNotesController) ReadSubscriptionNote(
ctx context.Context,
subscriptionId int,
noteId int) (
models.ApiResponse[models.SubscriptionNoteResponse],
error) {
req := s.prepareRequest(
ctx,
"GET",
fmt.Sprintf("/subscriptions/%v/notes/%v.json", subscriptionId, noteId),
)
req.Authenticate(NewAuth("BasicAuth"))
var result models.SubscriptionNoteResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.SubscriptionNoteResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// UpdateSubscriptionNote takes context, subscriptionId, noteId, body as parameters and
// returns an models.ApiResponse with models.SubscriptionNoteResponse data and
// an error if there was an issue with the request or response.
// Use the following method to update a note for a Subscription.
func (s *SubscriptionNotesController) UpdateSubscriptionNote(
ctx context.Context,
subscriptionId int,
noteId int,
body *models.UpdateSubscriptionNoteRequest) (
models.ApiResponse[models.SubscriptionNoteResponse],
error) {
req := s.prepareRequest(
ctx,
"PUT",
fmt.Sprintf("/subscriptions/%v/notes/%v.json", subscriptionId, noteId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.SubscriptionNoteResponse
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.SubscriptionNoteResponse](decoder)
return models.NewApiResponse(result, resp), err
}
// DeleteSubscriptionNote takes context, subscriptionId, noteId as parameters and
// returns an *Response and
// an error if there was an issue with the request or response.
// Use the following method to delete a note for a Subscription.
func (s *SubscriptionNotesController) DeleteSubscriptionNote(
ctx context.Context,
subscriptionId int,
noteId int) (
*http.Response,
error) {
req := s.prepareRequest(
ctx,
"DELETE",
fmt.Sprintf("/subscriptions/%v/notes/%v.json", subscriptionId, noteId),
)
req.Authenticate(NewAuth("BasicAuth"))
httpCtx, err := req.Call()
if err != nil {
return httpCtx.Response, err
}
return httpCtx.Response, err
}