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
25 changes: 22 additions & 3 deletions party.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import (
"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/de"
"github.com/invopop/gobl/regimes/us"
"github.com/invopop/gobl/tax"
"github.com/stripe/stripe-go/v81"
)

// For more details on Customer Tax IDs in Stripe, see: https://docs.stripe.com/billing/customer/tax-ids

var orgIDKeys = []stripe.TaxIDType{"de_stn"}
// orgIDKeys lists the Stripe tax ID types that GOBL represents as party
// identities (org.Identity) rather than tax identities (tax.Identity). These
// are codes that don't belong to a VAT-like tax scheme, such as the German
// Steuernummer (de_stn) or the US Employer Identification Number (us_ein).
var orgIDKeys = []stripe.TaxIDType{stripe.TaxIDTypeDEStn, stripe.TaxIDTypeUSEIN}

// Lookup map for country code to Stripe tax ID type
var taxIDMapGOBLToStripe = map[l10n.Code]stripe.TaxIDType{
Expand Down Expand Up @@ -143,6 +148,13 @@ func ToTaxIDFromOrg(id *org.Identity) *stripe.TaxID {
Value: id.Code.String(),
}
}
switch id.Type {
case us.IdentityTypeEIN:
return &stripe.TaxID{
Type: stripe.TaxIDTypeUSEIN,
Value: id.Code.String(),
}
}
return nil
}

Expand Down Expand Up @@ -196,8 +208,15 @@ func FromTaxIDToOrg(taxID *stripe.TaxID) *org.Identity {
switch taxID.Type {
case stripe.TaxIDTypeDEStn:
oid = &org.Identity{
Key: de.IdentityKeyTaxNumber,
Code: cbc.Code(taxID.Value),
Country: l10n.DE.ISO(),
Key: de.IdentityKeyTaxNumber,
Code: cbc.Code(taxID.Value),
}
case stripe.TaxIDTypeUSEIN:
oid = &org.Identity{
Country: l10n.US.ISO(),
Type: us.IdentityTypeEIN,
Code: cbc.Code(taxID.Value),
}
}
oid.Normalize()
Expand Down
23 changes: 16 additions & 7 deletions party_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/invopop/gobl/l10n"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/regimes/de"
"github.com/invopop/gobl/regimes/us"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
stripe "github.com/stripe/stripe-go/v81"
Expand Down Expand Up @@ -169,7 +170,12 @@ func TestFromTaxIDToOrg(t *testing.T) {
{
"valid DE STN",
&stripe.TaxID{Type: "de_stn", Value: "123456789"},
&org.Identity{Key: de.IdentityKeyTaxNumber, Code: cbc.Code("123456789")},
&org.Identity{Country: l10n.DE.ISO(), Key: de.IdentityKeyTaxNumber, Code: cbc.Code("123456789")},
},
{
"valid US EIN",
&stripe.TaxID{Type: "us_ein", Value: "41-4637166"},
&org.Identity{Country: l10n.US.ISO(), Type: us.IdentityTypeEIN, Code: cbc.Code("41-4637166")},
},
Comment thread
pmenendz marked this conversation as resolved.
{
"invalid type",
Expand Down Expand Up @@ -294,8 +300,9 @@ func TestFromCustomer(t *testing.T) {
},
Identities: []*org.Identity{
{
Key: de.IdentityKeyTaxNumber,
Code: "123456789",
Country: l10n.DE.ISO(),
Key: de.IdentityKeyTaxNumber,
Code: "123456789",
},
},
},
Expand Down Expand Up @@ -579,8 +586,9 @@ func TestFromCustomerItalyTaxIDLogic(t *testing.T) {
},
Identities: []*org.Identity{
{
Key: de.IdentityKeyTaxNumber,
Code: "123456789",
Country: l10n.DE.ISO(),
Key: de.IdentityKeyTaxNumber,
Code: "123456789",
},
},
},
Expand Down Expand Up @@ -690,8 +698,9 @@ func TestNewSupplierFromAccount(t *testing.T) {
Name: "German Business",
Identities: []*org.Identity{
{
Key: de.IdentityKeyTaxNumber,
Code: "123456789",
Country: l10n.DE.ISO(),
Key: de.IdentityKeyTaxNumber,
Code: "123456789",
},
},
},
Expand Down
Loading