feat(payments): report income to «Мой налог»
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Failing after 24s
CI / ui (pull_request) Successful in 1m17s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Failing after 0s
CI / deploy (pull_request) Has been skipped
CI / changes (pull_request) Successful in 3s
CI / unit (pull_request) Successful in 11s
CI / integration (pull_request) Failing after 24s
CI / ui (pull_request) Successful in 1m17s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Failing after 0s
CI / deploy (pull_request) Has been skipped
The direct rail runs on НПД, where the provider neither files with the tax service nor issues a receipt — so nobody was doing it. This registers each rouble purchase, annuls its receipt on a refund, and hands the buyer the receipt by email. Two properties of the (unofficial) lknpd API shape the design. Registering an income takes no idempotency key, so an error does not mean nothing happened: the service name is frozen before the call and carries a marker from the tail of the order id, and after a failure the taxpayer's income list is searched for that exact name. Found means filed; not found halts the queue for a human, because declaring an income twice is as wrong as not declaring it. And faults are classified rather than logged: a token is renewed silently, a throttle backs off, an outage retries, but three unfixable rejections take the rail out of service — a changed format must not become thousands of requests overnight. The console button and the worker share one RunBatch. Automatic mode is armed from the console, not from configuration, so the operator can watch a run go through by hand first. A daily watchdog runs whether or not it is armed, since the case it exists for is the export being off. An idle queue issues no call at all — not even an authentication. No payment path changed: the purchase letter rides the existing payment-event outbox on its own cursor, the receipt and annulment letters ride the export row. Decisions D53-D60.
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
||||
"scrabble/backend/internal/account"
|
||||
"scrabble/backend/internal/game"
|
||||
"scrabble/backend/internal/lobby"
|
||||
"scrabble/backend/internal/mynalog"
|
||||
"scrabble/backend/internal/mynalogsync"
|
||||
"scrabble/backend/internal/postgres"
|
||||
"scrabble/backend/internal/ratewatch"
|
||||
"scrabble/backend/internal/robokassa"
|
||||
@@ -79,6 +81,10 @@ type Config struct {
|
||||
// resolves to YooKassa. Kept wired so restoring Robokassa is a credentials change, not a code
|
||||
// change — see backend/internal/robokassa/README.md.
|
||||
Robokassa robokassa.Shops
|
||||
// MyNalog configures the professional-income tax export. An empty Key leaves the whole rail
|
||||
// dormant: without somewhere safe to keep the cabinet's refresh token there is no way to stay
|
||||
// signed in, so the console section and both workers stay unregistered.
|
||||
MyNalog mynalogsync.Config
|
||||
}
|
||||
|
||||
// Defaults applied when the corresponding environment variable is unset.
|
||||
@@ -88,6 +94,9 @@ const (
|
||||
defaultLogLevel = "info"
|
||||
defaultGuestReapInterval = time.Hour
|
||||
defaultGuestRetention = 30 * 24 * time.Hour
|
||||
// defaultMyNalogTZ is the taxpayer's time zone. It decides which tax month a near-midnight
|
||||
// payment is filed under, so it follows the taxpayer's registration, not the server's clock.
|
||||
defaultMyNalogTZ = "Europe/Moscow"
|
||||
)
|
||||
|
||||
// Load reads the configuration from the environment, applies defaults for unset
|
||||
@@ -201,6 +210,20 @@ func Load() (Config, error) {
|
||||
shops[robokassa.ChannelAndroid] = android
|
||||
}
|
||||
|
||||
// Professional-income tax export. The key seals the cabinet's refresh token at rest; without it
|
||||
// the rail is dormant, which is the state every deployment starts in.
|
||||
mn := mynalogsync.Config{BaseURL: os.Getenv("BACKEND_MYNALOG_BASE_URL")}
|
||||
if raw := os.Getenv("BACKEND_MYNALOG_KEY"); raw != "" {
|
||||
if mn.Key, err = mynalog.ParseKey(raw); err != nil {
|
||||
return Config{}, fmt.Errorf("config: BACKEND_MYNALOG_KEY: %w", err)
|
||||
}
|
||||
}
|
||||
// The offset a receipt carries decides which tax period an income falls into, so this is the
|
||||
// taxpayer's own zone, not the server's.
|
||||
if mn.Location, err = time.LoadLocation(envOr("BACKEND_MYNALOG_TZ", defaultMyNalogTZ)); err != nil {
|
||||
return Config{}, fmt.Errorf("config: BACKEND_MYNALOG_TZ: %w", err)
|
||||
}
|
||||
|
||||
c := Config{
|
||||
HTTPAddr: envOr("BACKEND_HTTP_ADDR", defaultHTTPAddr),
|
||||
GRPCAddr: envOr("BACKEND_GRPC_ADDR", defaultGRPCAddr),
|
||||
@@ -221,6 +244,7 @@ func Load() (Config, error) {
|
||||
YooKassa: ykShops,
|
||||
YooKassaVatCode: vatCode,
|
||||
Robokassa: shops,
|
||||
MyNalog: mn,
|
||||
}
|
||||
if err := c.validate(); err != nil {
|
||||
return Config{}, err
|
||||
|
||||
Reference in New Issue
Block a user