-
Notifications
You must be signed in to change notification settings - Fork 1
/
advance_invoice_controller.go
129 lines (116 loc) · 5.62 KB
/
advance_invoice_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
/*
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/https"
"github.com/apimatic/go-core-runtime/utilities"
"github.com/maxio-com/ab-golang-sdk/errors"
"github.com/maxio-com/ab-golang-sdk/models"
)
// AdvanceInvoiceController represents a controller struct.
type AdvanceInvoiceController struct {
baseController
}
// NewAdvanceInvoiceController creates a new instance of AdvanceInvoiceController.
// It takes a baseController as a parameter and returns a pointer to the AdvanceInvoiceController.
func NewAdvanceInvoiceController(baseController baseController) *AdvanceInvoiceController {
advanceInvoiceController := AdvanceInvoiceController{baseController: baseController}
return &advanceInvoiceController
}
// IssueAdvanceInvoice takes context, subscriptionId, body as parameters and
// returns an models.ApiResponse with models.Invoice data and
// an error if there was an issue with the request or response.
// Generate an invoice in advance for a subscription's next renewal date. [Please see our docs](https://maxio.zendesk.com/hc/en-us/articles/24252026404749-Issue-Invoice-In-Advance) for more information on advance invoices, including eligibility on generating one; for the most part, they function like any other invoice, except they are issued early and have special behavior upon being voided.
// A subscription may only have one advance invoice per billing period. Attempting to issue an advance invoice when one already exists will return an error.
// That said, regeneration of the invoice may be forced with the params `force: true`, which will void an advance invoice if one exists and generate a new one. If no advance invoice exists, a new one will be generated.
// We recommend using either the create or preview endpoints for proforma invoices to preview this advance invoice before using this endpoint to generate it.
func (a *AdvanceInvoiceController) IssueAdvanceInvoice(
ctx context.Context,
subscriptionId int,
body *models.IssueAdvanceInvoiceRequest) (
models.ApiResponse[models.Invoice],
error) {
req := a.prepareRequest(
ctx,
"POST",
fmt.Sprintf("/subscriptions/%v/advance_invoice/issue.json", subscriptionId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"422": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'.", Unmarshaller: errors.NewErrorListResponse},
})
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.Invoice
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.Invoice](decoder)
return models.NewApiResponse(result, resp), err
}
// ReadAdvanceInvoice takes context, subscriptionId as parameters and
// returns an models.ApiResponse with models.Invoice data and
// an error if there was an issue with the request or response.
// Once an advance invoice has been generated for a subscription's upcoming renewal, it can be viewed through this endpoint. There can only be one advance invoice per subscription per billing cycle.
func (a *AdvanceInvoiceController) ReadAdvanceInvoice(
ctx context.Context,
subscriptionId int) (
models.ApiResponse[models.Invoice],
error) {
req := a.prepareRequest(
ctx,
"GET",
fmt.Sprintf("/subscriptions/%v/advance_invoice.json", subscriptionId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
})
var result models.Invoice
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.Invoice](decoder)
return models.NewApiResponse(result, resp), err
}
// VoidAdvanceInvoice takes context, subscriptionId, body as parameters and
// returns an models.ApiResponse with models.Invoice data and
// an error if there was an issue with the request or response.
// Void a subscription's existing advance invoice. Once voided, it can later be regenerated if desired.
// A `reason` is required in order to void, and the invoice must have an open status. Voiding will cause any prepayments and credits that were applied to the invoice to be returned to the subscription. For a full overview of the impact of voiding, please [see our help docs]($m/Invoice).
func (a *AdvanceInvoiceController) VoidAdvanceInvoice(
ctx context.Context,
subscriptionId int,
body *models.VoidInvoiceRequest) (
models.ApiResponse[models.Invoice],
error) {
req := a.prepareRequest(
ctx,
"POST",
fmt.Sprintf("/subscriptions/%v/advance_invoice/void.json", subscriptionId),
)
req.Authenticate(NewAuth("BasicAuth"))
req.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
})
req.Header("Content-Type", "application/json")
if body != nil {
req.Json(body)
}
var result models.Invoice
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.Invoice](decoder)
return models.NewApiResponse(result, resp), err
}