Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validating published artifacts #11

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
546 changes: 273 additions & 273 deletions README.md

Large diffs are not rendered by default.

250 changes: 125 additions & 125 deletions advance_invoice_controller.go
Original file line number Diff line number Diff line change
@@ -1,149 +1,149 @@
package advancedbilling

import (
"context"
"fmt"
"github.com/apimatic/go-core-runtime/utilities"
"github.com/maxio-com/ab-golang-sdk/errors"
"github.com/maxio-com/ab-golang-sdk/models"
"context"
"fmt"
"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
baseController
}

// NewAdvanceInvoiceController creates a new instance of AdvanceInvoiceController.
// 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
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](reference/Chargify-API.v1.yaml/components/schemas/Invoice) 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.
// 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](reference/Chargify-API.v1.yaml/components/schemas/Invoice) 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(true)
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
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.Invoice](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}
if resp.StatusCode == 404 {
err = errors.NewApiError(404, "Not Found")
}
if resp.StatusCode == 422 {
err = errors.NewErrorListResponse(422, "Unprocessable Entity (WebDAV)")
}
return models.NewApiResponse(result, resp), err
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(true)
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
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}

result, err = utilities.DecodeResults[models.Invoice](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}

if resp.StatusCode == 404 {
err = errors.NewApiError(404, "Not Found")
}
if resp.StatusCode == 422 {
err = errors.NewErrorListResponse(422, "Unprocessable Entity (WebDAV)")
}
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.
// 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(true)
var result models.Invoice
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.Invoice](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}
if resp.StatusCode == 404 {
err = errors.NewApiError(404, "Not Found")
}
return models.NewApiResponse(result, resp), err
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(true)

var result models.Invoice
decoder, resp, err := req.CallAsJson()
if err != nil {
return models.NewApiResponse(result, resp), err
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}

result, err = utilities.DecodeResults[models.Invoice](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}

if resp.StatusCode == 404 {
err = errors.NewApiError(404, "Not Found")
}
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.
// 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](reference/Chargify-API.v1.yaml/components/schemas/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(true)
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
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}
result, err = utilities.DecodeResults[models.Invoice](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}
if resp.StatusCode == 404 {
err = errors.NewApiError(404, "Not Found")
}
return models.NewApiResponse(result, resp), err
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(true)
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
}
err = validateResponse(*resp)
if err != nil {
return models.NewApiResponse(result, resp), err
}

result, err = utilities.DecodeResults[models.Invoice](decoder)
if err != nil {
return models.NewApiResponse(result, resp), err
}

if resp.StatusCode == 404 {
err = errors.NewApiError(404, "Not Found")
}
return models.NewApiResponse(result, resp), err
}
Loading
Loading