Skip to content

Commit

Permalink
Merge pull request #195 from getlago/ftr-add-error-details-to-invoices
Browse files Browse the repository at this point in the history
feature(anrok): add error details to invoie response
  • Loading branch information
annvelents authored Sep 4, 2024
2 parents 7398ac1 + e2772f1 commit e50ff93
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type IntegrationType string

const (
IntegrationNetsuite IntegrationType = "netsuite"
IntegrationAnrok IntegrationType = "anrok"
IntegrationXero IntegrationType = "xero"
)

type CustomerParams struct {
Expand Down
38 changes: 35 additions & 3 deletions invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
const (
InvoiceStatusDraft InvoiceStatus = "draft"
InvoiceStatusFinalized InvoiceStatus = "finalized"
InvoiceStatusFailed InvoiceStatus = "failed"
)

const (
Expand Down Expand Up @@ -144,6 +145,12 @@ type InvoiceAppliedTax struct {
CreatedAt time.Time `json:"created_at,omitempty"`
}

type InvoiceErrorDetail struct {
LagoId uuid.UUID `json:"lago_id,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
Details string `json:"details,omitempty"`
}

type Invoice struct {
LagoID uuid.UUID `json:"lago_id,omitempty"`
SequentialID int `json:"sequential_id,omitempty"`
Expand Down Expand Up @@ -178,9 +185,10 @@ type Invoice struct {
Customer *Customer `json:"customer,omitempty"`
Subscriptions []Subscription `json:"subscriptions,omitempty"`

Fees []Fee `json:"fees,omitempty"`
Credits []InvoiceCredit `json:"credits,omitempty"`
AppliedTaxes []InvoiceAppliedTax `json:"applied_taxes,omitempty"`
Fees []Fee `json:"fees,omitempty"`
Credits []InvoiceCredit `json:"credits,omitempty"`
AppliedTaxes []InvoiceAppliedTax `json:"applied_taxes,omitempty"`
ErrorDetails []InvoiceErrorDetail `json:"error_details,omitempty"`
AppliedUsageThreshold []AppliedUsageThreshold `json:"applied_usage_threshold,omitempty"`
}

Expand Down Expand Up @@ -341,6 +349,30 @@ func (ir *InvoiceRequest) Refresh(ctx context.Context, invoiceID string) (*Invoi
return nil, nil
}

func (ir *InvoiceRequest) Retry(ctx context.Context, invoiceID string) (*Invoice, *Error) {
subPath := fmt.Sprintf("%s/%s/%s", "invoices", invoiceID, "retry")
clientRequest := &ClientRequest{
Path: subPath,
Result: &InvoiceResult{},
}

result, err := ir.client.Post(ctx, clientRequest)
if err != nil {
return nil, err
}

if result != nil {
invoiceResult, ok := result.(*InvoiceResult)
if !ok {
return nil, &ErrorTypeAssert
}

return invoiceResult.Invoice, nil
}

return nil, nil
}

func (ir *InvoiceRequest) Finalize(ctx context.Context, invoiceID string) (*Invoice, *Error) {
subPath := fmt.Sprintf("%s/%s/%s", "invoices", invoiceID, "finalize")
clientRequest := &ClientRequest{
Expand Down

0 comments on commit e50ff93

Please sign in to comment.