Skip to content

fix: emit the mandatory NetworkID inside CardAccount - #119

Merged
alvarolivie merged 1 commit into
mainfrom
fix/card-account-network-id
Jul 29, 2026
Merged

fix: emit the mandatory NetworkID inside CardAccount#119
alvarolivie merged 1 commit into
mainfrom
fix/card-account-network-id

Conversation

@alvarolivie

Copy link
Copy Markdown
Collaborator

Problem

Any invoice with card payment instructions failed UBL schema validation:

[SAX] cvc-complex-type.2.4.b: The content of element 'cac:CardAccount' is not
complete. One of '{urn:...:CommonBasicComponents-2":NetworkID}' is expected.

CardAccountType in the UBL 2.1 schema declares cbc:NetworkID as
minOccurs="1" (see test/data/schema/common/UBL-CommonAggregateComponents-2.1.xsd),
but we only ever emitted cbc:PrimaryAccountNumberID and, optionally,
cbc:HolderName.

Fix

cbc:NetworkID has no EN 16931 business term and no counterpart in GOBL's
pay.Card, so there is nothing to map it from. Peppol BIS documents it as a
"syntax required element not related to a business term" with the example value
NA, which is what we now emit:

<cac:CardAccount>
  <cbc:PrimaryAccountNumberID>0312</cbc:PrimaryAccountNumberID>
  <cbc:NetworkID>NA</cbc:NetworkID>
</cac:CardAccount>

The struct field order already matched the XSD sequence, so no reordering was
needed. The parse direction keeps ignoring NetworkID, and a round trip
regenerates the placeholder.

Notes

  • Advances with a card are unaffected: they only map to cac:PrepaidPayment /
    LegalMonetaryTotal/PrepaidAmount, which have no card fields in UBL. Only
    instructions.card reaches cac:CardAccount.
  • A card with a holder but no last4 still emits an empty
    <cbc:PrimaryAccountNumberID/>. That is schema-valid and passes Peppol's
    BR-51 (a warning asserting length ≤ 10), so it was left as-is.

Testing

New subtest in TestNewPayment covering the struct and the serialized element
order. Full suite and golangci-lint pass.

🤖 Generated with Claude Code

The UBL 2.1 schema declares cbc:NetworkID as minOccurs="1" inside
CardAccountType, so invoices carrying card payment instructions were
rejected by XSD validation:

  cvc-complex-type.2.4.b: The content of element 'cac:CardAccount' is
  not complete. One of '{...:NetworkID}' is expected.

The element has no EN 16931 business term, and GOBL's pay.Card has no
counterpart to source it from, so we emit the "NA" placeholder that
Peppol BIS documents for this syntax-only element.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 29, 2026 11:42
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.31%. Comparing base (a8df7c9) to head (e5cb2ec).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #119      +/-   ##
==========================================
+ Coverage   81.16%   81.31%   +0.15%     
==========================================
  Files          28       28              
  Lines        2155     2157       +2     
==========================================
+ Hits         1749     1754       +5     
+ Misses        268      265       -3     
  Partials      138      138              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alvarolivie
alvarolivie merged commit d8e80ac into main Jul 29, 2026
3 checks passed
@alvarolivie
alvarolivie deleted the fix/card-account-network-id branch July 29, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes UBL 2.1 schema validation failures for invoices that include card payment instructions by ensuring cac:CardAccount always emits the mandatory cbc:NetworkID element.

Changes:

  • Emit cbc:NetworkID inside cac:CardAccount with a placeholder value (NA) when card instructions are present.
  • Add a regression test to verify NetworkID is set and that the serialized XML places it after PrimaryAccountNumberID.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
payment.go Ensures CardAccount includes a mandatory NetworkID value when emitting card payment instructions.
payment_test.go Adds coverage asserting NetworkID is present and serialized in the expected element order.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread payment_test.go
Comment on lines +96 to +98
data, err := ubl.Bytes(doc)
require.NoError(t, err)
assert.Contains(t, string(data), "<cac:CardAccount>\n <cbc:PrimaryAccountNumberID>0312</cbc:PrimaryAccountNumberID>\n <cbc:NetworkID>NA</cbc:NetworkID>\n </cac:CardAccount>")
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