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

Add api communication #11

Merged
merged 4 commits into from
Mar 20, 2024
Merged

Add api communication #11

merged 4 commits into from
Mar 20, 2024

Conversation

noplisu
Copy link
Collaborator

@noplisu noplisu commented Feb 2, 2024

Pull Request Summary

We want to be able to post invoices into the KSeF API and get back the UPO that proves that the invoice has been accepted by the system.

The first step is communicating with the API to get the interactive session. To get the interactive session we need to have the context in which we send the requests this context is the tax id of the company. Next we need a valid token from KSeF it can be generated from https://ksef.mf.gov.pl/web for production or from https://ksef-test.mf.gov.pl/web for test. The last thing is the public key provided from https://ksef.mf.gov.pl/ and https://ksef-test.mf.gov.pl/.

The UPO files are generated after the interactive session is terminated. To get the files we first need to terminate the session then after it finishes generating the UPO files we can get them from the session status request.

The process is getting the authorization challenge, initializing the interactive session, posting the invoice using the session, waiting for the invoice to process by checking the status. When it is finished we terminate the session wait for the process to finish by checking the status and save the UPO.

An example of using the CLI to post an invoice would look like:

go run ./cmd/gobl.ksef send ./test/data/out/invoice-pl-pl.xml 1234567788 624A48824F01935DADE66C83D4874C0EF7AF0529CB5F0F412E6932F189D3864A test

Changes

We add a CLI command for posting the invoice into the KSeF API.
We add handling for requests:

  • Getting the authorization challenge
  • Initializing token session
  • Terminating the session
  • Checking the session status
  • Posting the invoice
  • Checking the invoice status

The process of sending a invoice works like presented on this graph:
image

samlown
samlown previously requested changes Feb 3, 2024
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.

A few comments there. I'd suggest having a look at some of the other repos for examples on best practices with Go. Otherwise though, this is looking great! Looks like the KSeF API is pretty complex!

api/ksef.go Outdated Show resolved Hide resolved
api/ksef.go Outdated Show resolved Hide resolved
api/session.go Outdated Show resolved Hide resolved
We want to be able to post invoices into the KSeF API and get back
the UPO that proves that the invoice has been accepted by the system.

The first step is communicating with the API to get the interactive
session. To get the interactive session we need to have the context
in which we send the requests this context is the tax id of the company.
Next we need a valid token from ksef it can be generated from
ksef.mf.gov.pl/web for production or from ksef-test.mf.gov.pl/web for
test. The last thing is the public key provided from https://ksef.mf.gov.pl/ and
https://ksef-test.mf.gov.pl/.

To get the session token we first need to get the authorization challenge for
our context. Then we use the context, token and authorization challenge to
create a interactive session and get the session token used in other requests.
We want to be able to post invoices into the KSeF API and get back
the UPO that proves that the invoice has been accepted by the system.

Here we prepare the request that posts the invoice to KSeF backend.
We also prepare a request that checks the invoice status.

With those requests we can post the invoice and check if it finished
processing.
We want to be able to post invoices into the KSeF API and get back
the UPO that proves that the invoice has been accepted by the system.

The UPO files are generated after the interactive session is terminated.
To get the files we first need to terminate the session then after it
finishes generating the UPO files we can get them from the session status request.

Here we the session termination and status requests used in the process.
@noplisu noplisu changed the title [WIP] Add api communication Add api communication Feb 7, 2024
@noplisu noplisu force-pushed the gl-rl-add-api-communication branch 3 times, most recently from a5d76a0 to 786be84 Compare February 8, 2024 12:19
We want to be able to post invoices into the KSeF API and get back
the UPO that proves that the invoice has been accepted by the system.

Here we get the parameters from the CLI and use the requests we prepared
to post the invoice and save the UPO. The example command would look like

go run ./cmd/gobl.ksef send ./test/data/out/invoice-pl-pl.xml 1234567788 624A48824F01935DADE66C83D4874C0EF7AF0529CB5F0F412E6932F189D3864A ./api/keys/test.pem
api/client.go Show resolved Hide resolved
@noplisu noplisu mentioned this pull request Mar 15, 2024
@noplisu noplisu requested a review from torrocus March 15, 2024 15:54
Copy link
Collaborator

@torrocus torrocus left a comment

Choose a reason for hiding this comment

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

LGTM

@noplisu noplisu dismissed samlown’s stale review March 20, 2024 15:50

torrocus reviewed the changes

@noplisu noplisu merged commit 63585de into main Mar 20, 2024
2 checks passed
@noplisu noplisu deleted the gl-rl-add-api-communication branch March 20, 2024 15:50
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.

3 participants