Skip to content

Commit

Permalink
[#176261561] extensions for aggregated and aggregator, billing
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnedMarshal committed Jan 4, 2021
1 parent 170c13f commit 6820953
Showing 1 changed file with 136 additions and 28 deletions.
164 changes: 136 additions & 28 deletions src/utils/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
getSpidStrategyOption,
IServiceProviderConfig,
ISpidStrategyOptions,
LightAggregatorExtension,
StrictResponseValidationOptions
} from "./middleware";

Expand Down Expand Up @@ -394,37 +395,144 @@ const getSpidContactPersonMetadata = (
serviceProviderConfig: IServiceProviderConfig
) => {
return serviceProviderConfig.contacts
? serviceProviderConfig.contacts.map(item => {
const contact = {
$: {
contactType: item.contactType
},
Company: item.company,
EmailAddress: item.email,
...(item.phone ? { TelephoneNumber: item.phone } : {})
};
if (item.contactType === ContactType.OTHER) {
return {
...contact,
? serviceProviderConfig.contacts
.map(item => {
const contact = {
$: {
...contact.$,
"spid:entityType": item.entityType
contactType: item.contactType
},
Extensions: {
...(item.extensions.IPACode
? { "spid:IPACode": item.extensions.IPACode }
: {}),
...(item.extensions.VATNumber
? { "spid:VATNumber": item.extensions.VATNumber }
: {}),
...(item.extensions?.FiscalCode
? { "spid:FiscalCode": item.extensions.FiscalCode }
: {})
}
Company: item.company,
EmailAddress: item.email,
...(item.phone ? { TelephoneNumber: item.phone } : {})
};
}
return contact;
})
if (item.contactType === ContactType.OTHER) {
return {
...contact,
$: {
...contact.$,
"spid:entityType": item.entityType
},
Extensions: {
...(item.extensions.IPACode
? { "spid:IPACode": item.extensions.IPACode }
: {}),
...(item.extensions.VATNumber
? { "spid:VATNumber": item.extensions.VATNumber }
: {}),
...(item.extensions?.FiscalCode
? { "spid:FiscalCode": item.extensions.FiscalCode }
: {}),
...(item.entityType === EntityType.AGGREGATOR
? { [`spid:${item.extensions.aggregatorType}`]: {} }
: {}),
...(item.entityType === EntityType.AGGREGATOR &&
LightAggregatorExtension.is(item.extensions)
? {
"spid:KeyDescriptor": {
$: {
use: "spid:validation"
},
"ds:KeyInfo": {
"ds:X509Data": {
"ds:X509Certificate": cleanCert(
item.extensions.aggregatorCert
)
}
}
}
}
: {}),
...(item.entityType === EntityType.AGGREGATED
? { [`spid:${item.extensions.aggregatedType}`]: {} }
: {})
}
};
}
if (item.contactType === ContactType.BILLING) {
return {
...contact,
Extensions: {
$: {
"xmlns:fpa": "https://spid.gov.it/invoicing-extensions"
},
"fpa:CessionarioCommittente": {
"fpa:DatiAnagrafici": {
...(item.billing.CessionarioCommittente.idPaese
? {
"fpa:IdFiscaleIVA": {
"fpa:IdCodice":
item.billing.CessionarioCommittente.idCodice,
"fpa:IdPaese":
item.billing.CessionarioCommittente.idPaese
}
}
: {}),
...(item.billing.CessionarioCommittente.fiscalCode
? {
"fpa:CodiceFiscale":
item.billing.CessionarioCommittente.fiscalCode
}
: {}),
"fpa:Anagrafica": {
...(item.billing.CessionarioCommittente.denominazione
? {
"fpa:Denominazione":
item.billing.CessionarioCommittente.denominazione
}
: {}),
...(item.billing.CessionarioCommittente.name
? {
"fpa:Nome": item.billing.CessionarioCommittente.name
}
: {}),
...(item.billing.CessionarioCommittente.surname
? {
"fpa:Cognome":
item.billing.CessionarioCommittente.surname
}
: {}),
...(item.billing.CessionarioCommittente.title
? {
"fpa:Titolo":
item.billing.CessionarioCommittente.title
}
: {}),
...(item.billing.CessionarioCommittente.CodiceEORI
? {
"fpa:CodiceEORI":
item.billing.CessionarioCommittente.CodiceEORI
}
: {})
}
},
"fpa:Sede": {
"fpa:CAP": item.billing.CessionarioCommittente.Sede.cap,
"fpa:Comune": item.billing.CessionarioCommittente.Sede.city,
"fpa:Indirizzo":
item.billing.CessionarioCommittente.Sede.address,
"fpa:Nazione":
item.billing.CessionarioCommittente.Sede.country,
...(item.billing.CessionarioCommittente.Sede.number
? {
"fpa:NumeroCivico":
item.billing.CessionarioCommittente.Sede.number
}
: {}),
...(item.billing.CessionarioCommittente.Sede.state
? {
"fpa:Provincia":
item.billing.CessionarioCommittente.Sede.state
}
: {})
}
}
}
};
}
return contact;
})
// Contacts array is limited to 3 elements
.slice(0, 3)
: {};
};

Expand Down

0 comments on commit 6820953

Please sign in to comment.