From bbf781bba351aa769a59645e46f669daa9018658 Mon Sep 17 00:00:00 2001 From: Stephan D Date: Tue, 3 Feb 2026 16:10:47 +0100 Subject: [PATCH] tg fizx --- .../internal/service/gateway/service.go | 3 ++ .../orchestrator/payment_plan_steps.go | 28 +++++++++++++++++++ api/pkg/model/confirmation.go | 1 + 3 files changed, 32 insertions(+) diff --git a/api/gateway/tgsettle/internal/service/gateway/service.go b/api/gateway/tgsettle/internal/service/gateway/service.go index 1a62b888..78e3dd75 100644 --- a/api/gateway/tgsettle/internal/service/gateway/service.go +++ b/api/gateway/tgsettle/internal/service/gateway/service.go @@ -406,6 +406,7 @@ func (s *Service) buildConfirmationRequest(intent *model.PaymentGatewayIntent) ( Rail: rail, OperationRef: intent.OperationRef, IntentRef: intent.IntentRef, + PaymentRef: intent.PaymentRef, }, nil } @@ -530,6 +531,7 @@ func paymentRecordFromIntent(intent *model.PaymentGatewayIntent, confirmReq *mod record.RequestedMoney = intent.RequestedMoney record.IntentRef = intent.IntentRef record.OperationRef = intent.OperationRef + record.PaymentRef = intent.PaymentRef } if confirmReq != nil { record.IdempotencyKey = strings.TrimSpace(confirmReq.RequestID) @@ -539,6 +541,7 @@ func paymentRecordFromIntent(intent *model.PaymentGatewayIntent, confirmReq *mod record.RequestedMoney = confirmReq.RequestedMoney record.IntentRef = strings.TrimSpace(confirmReq.IntentRef) record.OperationRef = strings.TrimSpace(confirmReq.OperationRef) + record.PaymentRef = confirmReq.PaymentRef // ExpiresAt is not used to derive an "expired" status — it can be kept for informational purposes only. if confirmReq.TimeoutSeconds > 0 { record.ExpiresAt = time.Now().Add(time.Duration(confirmReq.TimeoutSeconds) * time.Second) diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go index c78d6a2f..478d100b 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go @@ -2,6 +2,8 @@ package orchestrator import ( "context" + "fmt" + "math/big" "strings" "github.com/tech/sendico/payments/orchestrator/storage/model" @@ -139,6 +141,23 @@ func (p *paymentExecutor) executePlanStep( } } +func sub(a, b string) (string, error) { + ra, ok := new(big.Rat).SetString(a) + if !ok { + return "", fmt.Errorf("invalid number: %s", a) + } + + rb, ok := new(big.Rat).SetString(b) + if !ok { + return "", fmt.Errorf("invalid number: %s", b) + } + + ra.Sub(ra, rb) + + // 2 знака после запятой (как у тебя) + return ra.FloatString(2), nil +} + func (p *paymentExecutor) executeSendStep( ctx context.Context, payment *model.Payment, @@ -268,6 +287,15 @@ func (p *paymentExecutor) executeSendStep( logger.Warn("Invalid provider settlement amount", zap.Error(err)) return false, err } + fee, err := requireMoney(cloneMoney(payment.LastQuote.ExpectedFeeTotal), "provider settlement amount") + if err != nil { + logger.Warn("Invalid provider settlement amount", zap.Error(err)) + return false, err + } + if fee.Currency != amount.Currency { + logger.Warn("Fee and amount currencies do not match") + return false, merrors.DataConflict("settlement payment: currencies mismatch") + } if !p.deps.railGateways.available() { logger.Warn("Rail gateway unavailable") diff --git a/api/pkg/model/confirmation.go b/api/pkg/model/confirmation.go index 106ff588..98cbfbd4 100644 --- a/api/pkg/model/confirmation.go +++ b/api/pkg/model/confirmation.go @@ -23,6 +23,7 @@ type ConfirmationRequest struct { Rail string `bson:"rail,omitempty" json:"rail,omitempty"` OperationRef string `bson:"operationRef,omitempty" json:"operation_ref,omitempty"` IntentRef string `bson:"intentRef,omitempty" json:"intent_ref,omitempty"` + PaymentRef string `bson:"paymentRef,omitempty" json:"payment_ref,omitempty"` } type ConfirmationResult struct { -- 2.49.1