fix: emit the mandatory NetworkID inside CardAccount - #119
Merged
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
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:NetworkIDinsidecac:CardAccountwith a placeholder value (NA) when card instructions are present. - Add a regression test to verify
NetworkIDis set and that the serialized XML places it afterPrimaryAccountNumberID.
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 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>") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Any invoice with card payment instructions failed UBL schema validation:
CardAccountTypein the UBL 2.1 schema declarescbc:NetworkIDasminOccurs="1"(seetest/data/schema/common/UBL-CommonAggregateComponents-2.1.xsd),but we only ever emitted
cbc:PrimaryAccountNumberIDand, optionally,cbc:HolderName.Fix
cbc:NetworkIDhas no EN 16931 business term and no counterpart in GOBL'spay.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:The struct field order already matched the XSD sequence, so no reordering was
needed. The parse direction keeps ignoring
NetworkID, and a round tripregenerates the placeholder.
Notes
cardare unaffected: they only map tocac:PrepaidPayment/LegalMonetaryTotal/PrepaidAmount, which have no card fields in UBL. Onlyinstructions.cardreachescac:CardAccount.holderbut nolast4still emits an empty<cbc:PrimaryAccountNumberID/>. That is schema-valid and passes Peppol'sBR-51 (a warning asserting length ≤ 10), so it was left as-is.
Testing
New subtest in
TestNewPaymentcovering the struct and the serialized elementorder. Full suite and
golangci-lintpass.🤖 Generated with Claude Code