TG settlement service

This commit is contained in:
Stephan D
2026-01-02 14:54:18 +01:00
parent ea1c69f14a
commit 743f683d92
82 changed files with 4693 additions and 503 deletions

View File

@@ -0,0 +1,77 @@
package notifications
import (
"encoding/json"
"strings"
messaging "github.com/tech/sendico/pkg/messaging/envelope"
"github.com/tech/sendico/pkg/model"
nm "github.com/tech/sendico/pkg/model/notification"
"github.com/tech/sendico/pkg/mservice"
)
type ConfirmationRequestNotification struct {
messaging.Envelope
payload model.ConfirmationRequest
}
func (crn *ConfirmationRequestNotification) Serialize() ([]byte, error) {
data, err := json.Marshal(crn.payload)
if err != nil {
return nil, err
}
return crn.Envelope.Wrap(data)
}
type ConfirmationResultNotification struct {
messaging.Envelope
payload model.ConfirmationResult
}
func (crn *ConfirmationResultNotification) Serialize() ([]byte, error) {
data, err := json.Marshal(crn.payload)
if err != nil {
return nil, err
}
return crn.Envelope.Wrap(data)
}
func confirmationRequestEvent() model.NotificationEvent {
return model.NewNotification(mservice.Notifications, nm.NAConfirmationRequest)
}
func confirmationResultEvent(sourceService, rail string) model.NotificationEvent {
action := strings.TrimSpace(sourceService)
if action == "" {
action = "unknown"
}
action = strings.ToLower(action)
rail = strings.TrimSpace(rail)
if rail == "" {
rail = "default"
}
rail = strings.ToLower(rail)
return model.NewNotification(mservice.Confirmations, nm.NotificationAction(action+"."+rail))
}
func NewConfirmationRequestEnvelope(sender string, request *model.ConfirmationRequest) messaging.Envelope {
var payload model.ConfirmationRequest
if request != nil {
payload = *request
}
return &ConfirmationRequestNotification{
Envelope: messaging.CreateEnvelope(sender, confirmationRequestEvent()),
payload: payload,
}
}
func NewConfirmationResultEnvelope(sender string, result *model.ConfirmationResult, sourceService, rail string) messaging.Envelope {
var payload model.ConfirmationResult
if result != nil {
payload = *result
}
return &ConfirmationResultNotification{
Envelope: messaging.CreateEnvelope(sender, confirmationResultEvent(sourceService, rail)),
payload: payload,
}
}

View File

@@ -0,0 +1,81 @@
package notifications
import (
"context"
"encoding/json"
me "github.com/tech/sendico/pkg/messaging/envelope"
ch "github.com/tech/sendico/pkg/messaging/notifications/confirmations/handler"
np "github.com/tech/sendico/pkg/messaging/notifications/processor"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model"
"go.uber.org/zap"
)
type ConfirmationRequestProcessor struct {
logger mlogger.Logger
handler ch.ConfirmationRequestHandler
event model.NotificationEvent
}
func (crp *ConfirmationRequestProcessor) Process(ctx context.Context, envelope me.Envelope) error {
var msg model.ConfirmationRequest
if err := json.Unmarshal(envelope.GetData(), &msg); err != nil {
crp.logger.Warn("Failed to decode confirmation request envelope", zap.Error(err), zap.String("topic", crp.event.ToString()))
return err
}
if crp.handler == nil {
crp.logger.Warn("Confirmation request handler is not configured", zap.String("topic", crp.event.ToString()))
return nil
}
return crp.handler(ctx, &msg)
}
func (crp *ConfirmationRequestProcessor) GetSubject() model.NotificationEvent {
return crp.event
}
type ConfirmationResultProcessor struct {
logger mlogger.Logger
handler ch.ConfirmationResultHandler
event model.NotificationEvent
}
func (crp *ConfirmationResultProcessor) Process(ctx context.Context, envelope me.Envelope) error {
var msg model.ConfirmationResult
if err := json.Unmarshal(envelope.GetData(), &msg); err != nil {
crp.logger.Warn("Failed to decode confirmation result envelope", zap.Error(err), zap.String("topic", crp.event.ToString()))
return err
}
if crp.handler == nil {
crp.logger.Warn("Confirmation result handler is not configured", zap.String("topic", crp.event.ToString()))
return nil
}
return crp.handler(ctx, &msg)
}
func (crp *ConfirmationResultProcessor) GetSubject() model.NotificationEvent {
return crp.event
}
func NewConfirmationRequestProcessor(logger mlogger.Logger, handler ch.ConfirmationRequestHandler) np.EnvelopeProcessor {
if logger != nil {
logger = logger.Named("confirmation_request_processor")
}
return &ConfirmationRequestProcessor{
logger: logger,
handler: handler,
event: confirmationRequestEvent(),
}
}
func NewConfirmationResultProcessor(logger mlogger.Logger, sourceService, rail string, handler ch.ConfirmationResultHandler) np.EnvelopeProcessor {
if logger != nil {
logger = logger.Named("confirmation_result_processor")
}
return &ConfirmationResultProcessor{
logger: logger,
handler: handler,
event: confirmationResultEvent(sourceService, rail),
}
}