Skip to content

Commit

Permalink
Validating published artifacts (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazimierzm-iRonin authored Jan 29, 2024
1 parent e349a9c commit 6053676
Show file tree
Hide file tree
Showing 996 changed files with 66,265 additions and 63,709 deletions.
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

0 comments on commit 6053676

Please sign in to comment.