Skip to content

test(payment-term): Cover structured payment_term requests - #106

Draft
annvelents wants to merge 1 commit into
mainfrom
feat/payment-terms
Draft

annvelents wants to merge 1 commit into
mainfrom
feat/payment-terms

Conversation

@annvelents

@annvelents annvelents commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

The client types are generated from the published OpenAPI spec (deno task build), so PaymentTermObject and payment_term on requests and responses arrive once the lago-openapi PR below is published. This PR adds the tests.

tests/payment_term.test.ts:

  • a customer with only net_payment_term sends no payment_term key; payment_term: undefined sends no key; an explicit null is sent as null;
  • a subscription update without payment_term sends no key;
  • request bodies with payment_term for customer, subscription create/update, billing entity create and invoice preview (top-level);
  • payment_term and a null net_payment_term parsed on the customer response.

Depends on the lago-openapi PR being published: until then the generated types don't have PaymentTermObject and this file doesn't type-check. Wallet and one-off invoice tests follow in a separate PR once getlago/lago-api#6579 and #6580 and their spec PR land.

Checked locally against the regenerated spec: deno check, deno fmt --check and deno lint on the new file pass.

Related

annvelents added a commit to getlago/lago-openapi that referenced this pull request Nov 10, 2026
Documents Lago's structured payment terms for everything already merged
on lago-api `main` (#6201 customers and billing entities, #6195
invoices, #6234 subscriptions and invoice preview).

- New `PaymentTermObject`: `term_type` (`due_on_receipt`, `net`,
`end_of_month`, `net_end_of_month`, `days_end_of_month`,
`day_of_month`), `days` 0..365, `day_of_month` 1..31, `month_offset`
0..12 (default 1), with the per-type rules and the
`error_details.payment_term` codes (`invalid_format`,
`invalid_term_type`, `unexpected_fields`, `invalid_days`,
`invalid_day_of_month`, `invalid_month_offset`).
- `payment_term` on: customer create and object; billing entity create,
update and object; organization object (read-only — the default billing
entity's term; `PUT /organizations` takes only `net_payment_term`);
subscription create, update and object; invoice object; invoice preview
(top-level).
- Invoice preview: term resolution and the 422
`subscription_payment_terms_do_not_match`.
- `net_payment_term` marked deprecated (`deprecated: true`,
"**Deprecated.** Use `payment_term` instead.") on every input and
response; on `PUT /organizations` it points to `payment_term` on the
billing entity endpoints. Described as the legacy alias, nullable on
billing entity, organization and invoice responses, with how it
interacts with `payment_term`:
  1. A non-null `payment_term` always wins.
2. `payment_term: null` with a non-null `net_payment_term`: the null is
ignored and the term is `net N`.
3. `payment_term: null` with `net_payment_term` absent or null: clears
both.
  4. Only `net_payment_term` sent, equal to the stored value: no change.
5. Only `net_payment_term` sent, different value: the term is
re-derived.

Rules 2 and 4 depend on the lago-api PR below; merge this after it.

Not included: one-off invoice and wallet `payment_term` (lago-api #6579,
#6580, still open) — a follow-up PR once those merge. No v2 changes (the
v2 endpoints don't expose payment terms).

Overlap: #704 and #710 edit `net_payment_term` in the same three input
schemas. No `src/` conflict; the bundled `openapi.yaml` will need `npm
run build` after whichever merges second. Their `net_payment_term`
wording should then be aligned to the legacy-alias description.

`npm run test`: build OK, redocly and spectral warning counts identical
to `main`, none on payment terms.

## Related
- lago-api, keep the structured term on legacy nulls:
getlago/lago-api#7097
- lago-openapi, payment terms: #716
- SDKs: Ruby getlago/lago-ruby-client#386 · Python
getlago/lago-python-client#438 · Go getlago/lago-go-client#374 · JS
getlago/lago-javascript-client#106 · Rust getlago/lago-rust-client#67

---------

Co-authored-by: annvelents <anna@getlago.com>
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.

1 participant