forked from jfcote87/esign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
billing.go
404 lines (353 loc) · 12.7 KB
/
billing.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// Copyright 2019 James Cote
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by gen-esign; DO NOT EDIT.
// Package billing implements the DocuSign SDK
// category Billing.
//
// Use the Billing category to manage the following billing related tasks:
//
// * Retrieve and update billing plan information.
// * Retrieve invoices.
// * Retrieve and update payment information.
//
// Service Api documentation may be found at:
// https://developers.docusign.com/esign-rest-api/v2/reference/Billing
// Usage example:
//
// import (
// "github.com/thaitanloi365/esign"
// "github.com/thaitanloi365/esign/v2/billing"
// "github.com/thaitanloi365/esign/v2/model"
// )
// ...
// billingService := billing.New(esignCredential)
package billing // import "github.com/thaitanloi365/esign/v2/billing"
import (
"context"
"net/url"
"strings"
"time"
"github.com/thaitanloi365/esign"
"github.com/thaitanloi365/esign/v2/model"
)
// Service implements DocuSign Billing Category API operations
type Service struct {
credential esign.Credential
}
// New initializes a billing service using cred to authorize ops.
func New(cred esign.Credential) *Service {
return &Service{credential: cred}
}
// PlansGet get the billing plan details.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/billingplans/get
//
// SDK Method Billing::getBillingPlan
func (s *Service) PlansGet(billingPlanID string) *PlansGetOp {
return &PlansGetOp{
Credential: s.credential,
Method: "GET",
Path: strings.Join([]string{"", "v2", "billing_plans", billingPlanID}, "/"),
QueryOpts: make(url.Values),
}
}
// PlansGetOp implements DocuSign API SDK Billing::getBillingPlan
type PlansGetOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PlansGetOp) Do(ctx context.Context) (*model.BillingPlanResponse, error) {
var res *model.BillingPlanResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PlansGetAccountPlan get Account Billing Plan
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/billingplans/getaccountplan
//
// SDK Method Billing::getPlan
func (s *Service) PlansGetAccountPlan() *PlansGetAccountPlanOp {
return &PlansGetAccountPlanOp{
Credential: s.credential,
Method: "GET",
Path: "billing_plan",
QueryOpts: make(url.Values),
}
}
// PlansGetAccountPlanOp implements DocuSign API SDK Billing::getPlan
type PlansGetAccountPlanOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PlansGetAccountPlanOp) Do(ctx context.Context) (*model.AccountBillingPlanResponse, error) {
var res *model.AccountBillingPlanResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// IncludeCreditCardInformation when set to **true**, payment information including credit card information will show in the return.
func (op *PlansGetAccountPlanOp) IncludeCreditCardInformation() *PlansGetAccountPlanOp {
if op != nil {
op.QueryOpts.Set("include_credit_card_information", "true")
}
return op
}
// IncludeMetadata when set to **true**, the `canUpgrade` and `renewalStatus` properities are included the response and an array of `supportedCountries` property is added to the `billingAddress` information.
func (op *PlansGetAccountPlanOp) IncludeMetadata() *PlansGetAccountPlanOp {
if op != nil {
op.QueryOpts.Set("include_metadata", "true")
}
return op
}
// IncludeSuccessorPlans when set to **true**, excludes successor information from the response.
func (op *PlansGetAccountPlanOp) IncludeSuccessorPlans() *PlansGetAccountPlanOp {
if op != nil {
op.QueryOpts.Set("include_successor_plans", "true")
}
return op
}
// PlansGetCreditCard get metadata for a given credit card.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/billingplans/getcreditcard
//
// SDK Method Billing::getCreditCardInfo
func (s *Service) PlansGetCreditCard() *PlansGetCreditCardOp {
return &PlansGetCreditCardOp{
Credential: s.credential,
Method: "GET",
Path: "billing_plan/credit_card",
QueryOpts: make(url.Values),
}
}
// PlansGetCreditCardOp implements DocuSign API SDK Billing::getCreditCardInfo
type PlansGetCreditCardOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PlansGetCreditCardOp) Do(ctx context.Context) (*model.CreditCardInformation, error) {
var res *model.CreditCardInformation
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PlansList gets the list of available billing plans.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/billingplans/list
//
// SDK Method Billing::listBillingPlans
func (s *Service) PlansList() *PlansListOp {
return &PlansListOp{
Credential: s.credential,
Method: "GET",
Path: "/v2/billing_plans",
QueryOpts: make(url.Values),
}
}
// PlansListOp implements DocuSign API SDK Billing::listBillingPlans
type PlansListOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PlansListOp) Do(ctx context.Context) (*model.BillingPlansResponse, error) {
var res *model.BillingPlansResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PlansPurchaseEnvelopes reserverd: Purchase additional envelopes.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/billingplans/purchaseenvelopes
//
// SDK Method Billing::purchaseEnvelopes
func (s *Service) PlansPurchaseEnvelopes(purchasedEnvelopesInformation *model.PurchasedEnvelopesInformation) *PlansPurchaseEnvelopesOp {
return &PlansPurchaseEnvelopesOp{
Credential: s.credential,
Method: "PUT",
Path: "billing_plan/purchased_envelopes",
Payload: purchasedEnvelopesInformation,
QueryOpts: make(url.Values),
}
}
// PlansPurchaseEnvelopesOp implements DocuSign API SDK Billing::purchaseEnvelopes
type PlansPurchaseEnvelopesOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PlansPurchaseEnvelopesOp) Do(ctx context.Context) error {
return ((*esign.Op)(op)).Do(ctx, nil)
}
// PlansUpdate updates the account billing plan.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/billingplans/update
//
// SDK Method Billing::updatePlan
func (s *Service) PlansUpdate(billingPlanInformation *model.BillingPlanInformation) *PlansUpdateOp {
return &PlansUpdateOp{
Credential: s.credential,
Method: "PUT",
Path: "billing_plan",
Payload: billingPlanInformation,
QueryOpts: make(url.Values),
}
}
// PlansUpdateOp implements DocuSign API SDK Billing::updatePlan
type PlansUpdateOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PlansUpdateOp) Do(ctx context.Context) (*model.BillingPlanUpdateResponse, error) {
var res *model.BillingPlanUpdateResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PreviewBillingPlan when set to **true**, updates the account using a preview billing plan.
func (op *PlansUpdateOp) PreviewBillingPlan() *PlansUpdateOp {
if op != nil {
op.QueryOpts.Set("preview_billing_plan", "true")
}
return op
}
// InvoicesGet retrieves a billing invoice.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/invoices/get
//
// SDK Method Billing::getInvoice
func (s *Service) InvoicesGet(invoiceID string) *InvoicesGetOp {
return &InvoicesGetOp{
Credential: s.credential,
Method: "GET",
Path: strings.Join([]string{"billing_invoices", invoiceID}, "/"),
QueryOpts: make(url.Values),
}
}
// InvoicesGetOp implements DocuSign API SDK Billing::getInvoice
type InvoicesGetOp esign.Op
// Do executes the op. A nil context will return error.
func (op *InvoicesGetOp) Do(ctx context.Context) (*model.BillingInvoice, error) {
var res *model.BillingInvoice
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PDF returns a pdf version of the invoice by setting
// the Accept header to application/pdf
//
// **not included in swagger definition
func (op *InvoicesGetOp) PDF(ctx context.Context) (*esign.Download, error) {
var res *esign.Download
if op == nil {
return nil, esign.ErrNilOp
}
newOp := esign.Op(*op)
newOp.Accept = "application/pdf"
return res, (&newOp).Do(ctx, &res)
}
// InvoicesList get a List of Billing Invoices
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/invoices/list
//
// SDK Method Billing::listInvoices
func (s *Service) InvoicesList() *InvoicesListOp {
return &InvoicesListOp{
Credential: s.credential,
Method: "GET",
Path: "billing_invoices",
QueryOpts: make(url.Values),
}
}
// InvoicesListOp implements DocuSign API SDK Billing::listInvoices
type InvoicesListOp esign.Op
// Do executes the op. A nil context will return error.
func (op *InvoicesListOp) Do(ctx context.Context) (*model.BillingInvoicesResponse, error) {
var res *model.BillingInvoicesResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// FromDate specifies the date/time of the earliest invoice in the account to retrieve.
func (op *InvoicesListOp) FromDate(val time.Time) *InvoicesListOp {
if op != nil {
op.QueryOpts.Set("from_date", val.Format(time.RFC3339))
}
return op
}
// ToDate specifies the date/time of the latest invoice in the account to retrieve.
func (op *InvoicesListOp) ToDate(val time.Time) *InvoicesListOp {
if op != nil {
op.QueryOpts.Set("to_date", val.Format(time.RFC3339))
}
return op
}
// InvoicesListPastDue get a list of past due invoices.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/invoices/listpastdue
//
// SDK Method Billing::listInvoicesPastDue
func (s *Service) InvoicesListPastDue() *InvoicesListPastDueOp {
return &InvoicesListPastDueOp{
Credential: s.credential,
Method: "GET",
Path: "billing_invoices_past_due",
QueryOpts: make(url.Values),
}
}
// InvoicesListPastDueOp implements DocuSign API SDK Billing::listInvoicesPastDue
type InvoicesListPastDueOp esign.Op
// Do executes the op. A nil context will return error.
func (op *InvoicesListPastDueOp) Do(ctx context.Context) (*model.BillingInvoicesSummary, error) {
var res *model.BillingInvoicesSummary
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PaymentsCreate posts a payment to a past due invoice.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/payments/create
//
// SDK Method Billing::makePayment
func (s *Service) PaymentsCreate(billingPaymentRequest *model.BillingPaymentRequest) *PaymentsCreateOp {
return &PaymentsCreateOp{
Credential: s.credential,
Method: "POST",
Path: "billing_payments",
Payload: billingPaymentRequest,
QueryOpts: make(url.Values),
}
}
// PaymentsCreateOp implements DocuSign API SDK Billing::makePayment
type PaymentsCreateOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PaymentsCreateOp) Do(ctx context.Context) (*model.BillingPaymentResponse, error) {
var res *model.BillingPaymentResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PaymentsGet gets billing payment information for a specific payment.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/payments/get
//
// SDK Method Billing::getPayment
func (s *Service) PaymentsGet(paymentID string) *PaymentsGetOp {
return &PaymentsGetOp{
Credential: s.credential,
Method: "GET",
Path: strings.Join([]string{"billing_payments", paymentID}, "/"),
QueryOpts: make(url.Values),
}
}
// PaymentsGetOp implements DocuSign API SDK Billing::getPayment
type PaymentsGetOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PaymentsGetOp) Do(ctx context.Context) (*model.BillingPaymentItem, error) {
var res *model.BillingPaymentItem
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// PaymentsList gets payment information for one or more payments.
//
// https://developers.docusign.com/esign-rest-api/v2/reference/billing/payments/list
//
// SDK Method Billing::listPayments
func (s *Service) PaymentsList() *PaymentsListOp {
return &PaymentsListOp{
Credential: s.credential,
Method: "GET",
Path: "billing_payments",
QueryOpts: make(url.Values),
}
}
// PaymentsListOp implements DocuSign API SDK Billing::listPayments
type PaymentsListOp esign.Op
// Do executes the op. A nil context will return error.
func (op *PaymentsListOp) Do(ctx context.Context) (*model.BillingPaymentsResponse, error) {
var res *model.BillingPaymentsResponse
return res, ((*esign.Op)(op)).Do(ctx, &res)
}
// FromDate specifies the date/time of the earliest payment in the account to retrieve.
func (op *PaymentsListOp) FromDate(val time.Time) *PaymentsListOp {
if op != nil {
op.QueryOpts.Set("from_date", val.Format(time.RFC3339))
}
return op
}
// ToDate specifies the date/time of the latest payment in the account to retrieve.
func (op *PaymentsListOp) ToDate(val time.Time) *PaymentsListOp {
if op != nil {
op.QueryOpts.Set("to_date", val.Format(time.RFC3339))
}
return op
}