Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication with SdI - sending invoice #28

Merged

Conversation

torrocus
Copy link
Collaborator

@torrocus torrocus commented May 24, 2024

Pull Request Summary

We have implemented functionalities for sending invoices to SdI.

We've also introduced context, following the pattern established in other packages.

Furthermore, we've standardized CA (public) certificates, consolidating them into a single file. We have overcome authentication problems (on the client side).

Feedback

We have removed the server-related part from this PR to complete the process of sending invoices to SdI as one whole.

Below are some logs from the console commands.

$ go run ./cmd/gobl.fatturapa help
Usage:
  gobl.fatturapa [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  convert     Convert a GOBL JSON into a FatturaPA XML
  help        Help about any command
  server      Server for communication with SdI in selected environment
  transmit    Transmit a FatturaPA XML file to SdI in selected environment
  version     

Flags:
  -h, --help   help for gobl.fatturapa

Use "gobl.fatturapa [command] --help" for more information about a command.

Transmit

$ go run ./cmd/gobl.fatturapa help transmit
Transmit a FatturaPA XML file to SdI in selected environment

Usage:
  gobl.fatturapa transmit [file] [environment] [flags]

Flags:
      --ca-cert string   Path to a file containing the CA certificate
      --cert string      Path to a file containing the SDI PEM certificate
      --env string       Environment for running command (default "test")
  -h, --help             help for transmit
      --key string       Path to a file containing the sender PEM RSA private key
      --verbose          Logs all requests into the console
$ go run ./cmd/gobl.fatturapa transmit --ca-cert ./ca-all.pem --cert ./SDI-B85905495.pem --key ./key_client.key IT01234567890_FPA01.xml 
Invoice sent to SdI.
Here is the response: {29218192 2024-05-31T13:54:56.491+02:00 <nil>}

Co-authored-by: @noplisu
Co-authored-by: @torrocus

@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch from d8c825c to f5fdd13 Compare May 24, 2024 11:22
@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch from f5fdd13 to 72d0756 Compare May 24, 2024 11:59
@torrocus torrocus marked this pull request as ready for review May 24, 2024 12:06
@torrocus torrocus requested a review from samlown May 24, 2024 12:22
Copy link
Contributor

@samlown samlown left a comment

Choose a reason for hiding this comment

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

In general the code looks good! But I understand that its still not working, which is frustrating :-(

sdi/server.go Outdated Show resolved Hide resolved
sdi/transport.go Outdated Show resolved Hide resolved
sdi/transport.go Outdated Show resolved Hide resolved
sdi/transport.go Outdated Show resolved Hide resolved
test/data/invoice-hotel-private.json Outdated Show resolved Hide resolved
@torrocus torrocus marked this pull request as draft May 24, 2024 15:08
@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch 2 times, most recently from 314f43e to 5d576ea Compare May 28, 2024 15:30
@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch 3 times, most recently from bbe0525 to b701920 Compare May 31, 2024 11:39
torrocus and others added 14 commits May 31, 2024 13:42
Ignore files that should be kept private such as:
- Certificate Signing Request files
- Private RSA key files
- p7m files

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
We found the following information on an Italian blog: [1]

> Tuttavia è possibile che nel wsdl troverai
> “http://servizi.fatturapa.it/ricevi_file”,
> per passare in produzione ricordati di modificare
> l’endpoint in “https://servizi.fatturapa.it/ricevi_file”

In translate:

> However, it is possible that in the wsdl you will find
> "http://servizi.fatturapa.it/ricevi_file",
> to go into production remember to change
> the endpoint to "https://servizi.fatturapa.it/ricevi_file"

That's why we changed http to https.

[1]: https://massimomorchio.medium.com/fattura-elettronica-accreditamento-canale-sdicoop-ef6afb65cacb

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
The provided WSDL files have an endpoint used in production.
Most SOAP-enabled packages don't have the ability to change this endpoint,
so we have prepared separate files for communication with the test server.

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
On the Exchange System documentation page, [1]
we found the public keys of the client certificate
of the SDICoop Transmission and SDICoop Reception Service.

[1]: https://www.fatturapa.gov.it/en/norme-e-regole/DocumentazioneSDI/

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
The CA certificates provided were in different formats,
and some of them had no headers.
I added headers and transformed them all to PEM format. [1]

```console
openssl x509 -inform DER - w INPUT.cer -out OUTPUT.pem
```

[1]: https://www.openssl.org/docs/man1.1.1/man1/x509.html

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
We initially intended to utilize SOAP packages,
however, we encountered multiple obstacles.
The available packages were outdated
and unable to handle TLS authentication properly.
Additionally, we discovered that the SOAP server responded
with multipart data, complicating the integration further.

Consequently, we made the decision to switch to Resty
and build SOAP requests from scratch to overcome these challenges.

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Since we want to run the code in different environments
(development, test, production), it is a good practice to set separate
variables for each environment.

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch from b701920 to 290aa72 Compare May 31, 2024 11:52
@torrocus torrocus marked this pull request as ready for review May 31, 2024 11:53
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Since we receive certificates as data within the context,
the functions in the cert pool file are no longer needed.

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch 2 times, most recently from 6d35fe0 to abb776e Compare May 31, 2024 12:14
@torrocus torrocus changed the title Prepare communication with SdI Communication with SdI - sending invoice May 31, 2024
@torrocus torrocus requested a review from samlown May 31, 2024 12:16
Copy link
Contributor

@samlown samlown left a comment

Choose a reason for hiding this comment

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

Looks good! Nice one! Just a few potential considerations with the public method names to consider.

sdi/helper.go Outdated Show resolved Hide resolved
sdi/helper.go Outdated Show resolved Hide resolved
sdi/helper.go Outdated Show resolved Hide resolved
}

// SoapRequestToSendInvoice prepares the request content for SOAP to send an invoice
func SoapRequestToSendInvoice(fileName string, fileBody []byte) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

public?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this case I have a bit of a dilemma. I know this function doesn't have to be public, but I like that it only does one thing and I can easily test it.
Any ideas?

@torrocus torrocus requested a review from samlown June 3, 2024 09:57
torrocus and others added 4 commits June 3, 2024 12:52
These functions can be useful both on the server and client side,
in the code and perhaps also in tests.

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
This command is intended to demonstrate sending an invoice to SdI.

Added CA cert and verbose flags for better control from the command line.
The verbose flag provides more detailed debugging information about
the package's execution.
The ca-cert flag accepts a path to the CA Certificate.

Example usage of the command:

```console
$ go run ./cmd/gobl.fatturapa transmit --ca-cert ./ca-all.pem --cert ./SDI-B85905495.pem --key ./key_client.key --verbose invoice.xml
```

Additionally, separated responsibilities and added flexibility
in certificate storage.
The CLI handles the loading of the certificate path,
while the SdI package uses the loaded key.

Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
Co-authored-by: Alex Malaszkiewicz <[email protected]>
Co-authored-by: Grzeg Lisowski <[email protected]>
@torrocus torrocus force-pushed the al-gl-prepare-communication-with-sdi branch from d62dd80 to f017b89 Compare June 3, 2024 10:53
@torrocus torrocus merged commit 849ea1b into invopop:sdi Jun 3, 2024
1 check passed
@torrocus torrocus deleted the al-gl-prepare-communication-with-sdi branch June 3, 2024 10:54
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.

2 participants