Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type PrepaidPayment struct {
}

const sepaSchemeID = "SEPA"
const cardNetworkNotApplicable = "NA"

func (ui *Invoice) addPayment(inv *bill.Invoice, ctx Context) error {
if inv == nil || inv.Payment == nil {
Expand Down Expand Up @@ -175,8 +176,10 @@ func (ui *Invoice) addPaymentInstructions(inv *bill.Invoice, ctx Context) error
}
}
if instr.Card != nil {
network := cardNetworkNotApplicable
ui.PaymentMeans[0].CardAccount = &CardAccount{
PrimaryAccountNumberID: &instr.Card.Last4,
NetworkID: &network,
}
if instr.Card.Holder != "" {
ui.PaymentMeans[0].CardAccount.HolderName = &instr.Card.Holder
Expand Down
27 changes: 27 additions & 0 deletions payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ func TestNewPayment(t *testing.T) {
assert.Equal(t, "MANDATE-123", doc.PaymentMeans[0].PaymentMandate.ID.Value)
})

t.Run("card payment includes the network ID required by the schema", func(t *testing.T) {
env := loadTestEnvelope(t, "invoice-minimal.json")

inv, ok := env.Extract().(*bill.Invoice)
require.True(t, ok)

inv.Payment.Instructions.CreditTransfer = nil
inv.Payment.Instructions.Card = &pay.Card{Last4: "0312"}

doc, err := ubl.ConvertInvoice(env)
require.NoError(t, err)
require.NotEmpty(t, doc.PaymentMeans)

card := doc.PaymentMeans[0].CardAccount
require.NotNil(t, card)
require.NotNil(t, card.PrimaryAccountNumberID)
assert.Equal(t, "0312", *card.PrimaryAccountNumberID)
// cbc:NetworkID is mandatory in UBL, but has no EN 16931 business term.
require.NotNil(t, card.NetworkID)
assert.Equal(t, "NA", *card.NetworkID)
assert.Nil(t, card.HolderName)

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>")
Comment on lines +96 to +98
})

t.Run("document type extension", func(t *testing.T) {
env := loadTestEnvelope(t, "invoice-minimal.json")

Expand Down
Loading