-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 test
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
ksef_api "github.com/invopop/gobl.ksef/api" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type sendOpts struct { | ||
*rootOpts | ||
} | ||
|
||
func send(o *rootOpts) *sendOpts { | ||
return &sendOpts{rootOpts: o} | ||
} | ||
|
||
func (c *sendOpts) cmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "send [infile] [nip] [token] [env]", | ||
Short: "Send a GOBL JSON to the KSeF API", | ||
RunE: c.runE, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (c *sendOpts) runE(cmd *cobra.Command, args []string) error { | ||
// ctx := commandContext(cmd) | ||
token := inputToken(args) | ||
env := inputEnv(args) | ||
nip := inputNip(args) | ||
|
||
input, err := openInput(cmd, args) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
err = input.Close() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
}() | ||
|
||
data, err := io.ReadAll(input) | ||
if err != nil { | ||
return fmt.Errorf("reading input: %w", err) | ||
} | ||
|
||
_, err = ksef_api.SendInvoice(env, nip, token, data) | ||
if err != nil { | ||
return fmt.Errorf("sending invoices: %w", err) | ||
} | ||
return nil | ||
} |