Skip to content

feat(multiple-payment-methods): add invoice custom sections to billing resources#328

Merged
aquinofb merged 3 commits intomainfrom
feat/invoice-custom-sections-billing-resources
Mar 18, 2026
Merged

feat(multiple-payment-methods): add invoice custom sections to billing resources#328
aquinofb merged 3 commits intomainfrom
feat/invoice-custom-sections-billing-resources

Conversation

@aquinofb
Copy link
Copy Markdown
Contributor

@aquinofb aquinofb commented Mar 17, 2026

Summary

The Lago backend now supports attaching invoice custom sections to additional billing resources beyond customer and billing entity. This PR updates the Go API client to expose those new fields on subscription, wallet, recurring transaction rule, wallet transaction, and one-off invoice.

On the request side, each resource now accepts an optional nested invoice_custom_section object containing invoice_custom_section_codes (an array of section code strings) and skip_invoice_custom_sections (a boolean flag). This nesting mirrors the backend's strong params structure, which is notably different from the customer resource, where these fields sit at the top level.

On the response side, each resource now deserializes an applied_invoice_custom_sections array. Each entry contains lago_id, invoice_custom_section_id, and created_at: the join-table representation returned by the backend's AppliedInvoiceCustomSectionSerializer, not the full InvoiceCustomSection object.

Two new shared types were introduced in invoice_custom_section.go: InvoiceCustomSectionInput for requests and AppliedInvoiceCustomSection for responses. This keeps the pattern consistent across all five resources without duplicating struct definitions.

The implementation was cross-verified against the backend controller strong params, serializer output, and the equivalent Python client PR (getlago/lago-python-client#382) to ensure the JSON field names and nesting structure match exactly.

How to test it locally

Pull the Go Docker image if you don't have Go installed:

docker pull golang:latest

Run the tests:

docker run --rm -v $(pwd):/app -w /app golang:latest go test ./...

To verify the request JSON shape against a local Lago instance, you can spin up an echo server and point the client at it:

# Terminal 1: start an echo server
docker run --rm -p 8080:80 mendhak/http-https-echo

# Terminal 2: run a small Go script that creates a subscription with custom sections
docker run --rm --network host -v $(pwd):/app -w /app golang:latest go run -<<'GOEOF'
package main

import (
    "context"
    "fmt"
    lago "github.com/getlago/lago-go-client"
)

func main() {
    client := lago.New().SetBaseURL("http://localhost:8080").SetApiKey("test")
    client.Subscription().Create(context.Background(), &lago.SubscriptionInput{
        ExternalCustomerID: "cust_1",
        PlanCode:           "premium",
        ExternalID:         "sub_1",
        Name:               "Test",
        BillingTime:        lago.Anniversary,
        InvoiceCustomSection: &lago.InvoiceCustomSectionInput{
            InvoiceCustomSectionCodes: []string{"section_1", "section_2"},
            SkipInvoiceCustomSections: true,
        },
    })
    fmt.Println("Check the echo server output for the request JSON")
}
GOEOF

The echo server will print the full request body. Verify that invoice_custom_section_codes and skip_invoice_custom_sections are nested under an invoice_custom_section key.

@cla-check-bot
Copy link
Copy Markdown

cla-check-bot Bot commented Mar 17, 2026

Welcome, @aquinofb!

Thanks for your first contribution!

Before we proceed with the review, please sign the Contributor License Agreement:

Sign the CLA

Once signed, this PR will be automatically updated.

@cla-check-bot
Copy link
Copy Markdown

cla-check-bot Bot commented Mar 17, 2026

Thanks, @aquinofb! 🎉

Your CLA has been signed and is now on file. We'll proceed with the review shortly.

@aquinofb aquinofb changed the title feat: add invoice custom sections to billing resources feat(multiple-payment-methods): add invoice custom sections to billing resources Mar 17, 2026
…g resources

Expose invoice custom section fields on subscription, wallet,
recurring transaction rule, wallet transaction, and one-off invoice
to match the backend API contract.
@aquinofb aquinofb force-pushed the feat/invoice-custom-sections-billing-resources branch from 8fa9208 to 261c713 Compare March 17, 2026 18:08
Comment thread wallet_test.go
Copy link
Copy Markdown
Contributor

@osmarluz osmarluz Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aquinofb not a blocker, but it would be good to update the customer_wallet_test.go to add the tests we have here, since they are shared by the customer_wallet.go endpoints too

Copy link
Copy Markdown
Contributor Author

@aquinofb aquinofb Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, Osmar. Brought customer_wallet_test.go to full parity with wallet_test.go in f9f9927. The mock fixtures now include payment_method and applied_invoice_custom_sections, the Get test asserts on those fields, and the new CreateWithPaymentMethod and UpdateWithPaymentMethod test cases cover the same scenarios as the wallet endpoint.

Add payment_method and applied_invoice_custom_sections to mock
fixtures and assertions. Add CreateWithPaymentMethod and
UpdateWithPaymentMethod test cases for the customer wallet endpoint.
Copy link
Copy Markdown
Contributor

@osmarluz osmarluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@aquinofb aquinofb merged commit 8ccb650 into main Mar 18, 2026
3 checks passed
@aquinofb aquinofb deleted the feat/invoice-custom-sections-billing-resources branch March 18, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants