From 01020bb694acc023c15d0b82d226b57a1dcc4dcd Mon Sep 17 00:00:00 2001 From: Stephan D Date: Fri, 13 Feb 2026 15:41:42 +0100 Subject: [PATCH] fixed settlement mode import --- .../internal/service/orchestrator/convert.go | 15 ++++++++------- .../internal/service/orchestrator/helpers.go | 7 ++++--- .../internal/service/orchestrator/helpers_test.go | 6 +++--- .../service/orchestrator/service_helpers_test.go | 3 ++- .../internal/service/quotation/convert.go | 15 ++++++++------- .../internal/service/quotation/helpers.go | 8 ++++---- .../internal/server/paymentapiimp/mapper.go | 11 ++++++----- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/api/payments/orchestrator/internal/service/orchestrator/convert.go b/api/payments/orchestrator/internal/service/orchestrator/convert.go index 3516d077..12e6b3ce 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/convert.go +++ b/api/payments/orchestrator/internal/service/orchestrator/convert.go @@ -12,6 +12,7 @@ import ( fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" gatewayv1 "github.com/tech/sendico/pkg/proto/common/gateway/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1" @@ -553,25 +554,25 @@ func protoFailureFromModel(code model.PaymentFailureCode) sharedv1.PaymentFailur } } -func settlementModeFromProto(mode sharedv1.SettlementMode) model.SettlementMode { +func settlementModeFromProto(mode paymentv1.SettlementMode) model.SettlementMode { switch mode { - case sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE: + case paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE: return model.SettlementModeFixSource - case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: + case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: return model.SettlementModeFixReceived default: return model.SettlementModeUnspecified } } -func settlementModeToProto(mode model.SettlementMode) sharedv1.SettlementMode { +func settlementModeToProto(mode model.SettlementMode) paymentv1.SettlementMode { switch mode { case model.SettlementModeFixSource: - return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE + return paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE case model.SettlementModeFixReceived: - return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED + return paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED default: - return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED + return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED } } diff --git a/api/payments/orchestrator/internal/service/orchestrator/helpers.go b/api/payments/orchestrator/internal/service/orchestrator/helpers.go index da75347f..28717bff 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/helpers.go +++ b/api/payments/orchestrator/internal/service/orchestrator/helpers.go @@ -14,6 +14,7 @@ import ( accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1" fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" ) type moneyGetter interface { @@ -100,7 +101,7 @@ func resolveTradeAmounts(intentAmount *moneyv1.Money, fxQuote *oraclev1.Quote, s } } -func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.EstimateTransferFeeResponse, fxQuote *oraclev1.Quote, mode sharedv1.SettlementMode) (*moneyv1.Money, *moneyv1.Money) { +func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.EstimateTransferFeeResponse, fxQuote *oraclev1.Quote, mode paymentv1.SettlementMode) (*moneyv1.Money, *moneyv1.Money) { if pay == nil { return nil, nil } @@ -142,7 +143,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est } switch mode { - case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: + case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: // Sender pays the fee: keep settlement fixed, increase debit. applyChargeToDebit(fee) default: @@ -152,7 +153,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est if network != nil && network.GetNetworkFee() != nil { switch mode { - case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: + case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: applyChargeToDebit(network.GetNetworkFee()) default: applyChargeToSettlement(network.GetNetworkFee()) diff --git a/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go b/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go index 1f86bcff..cb49ab5a 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go @@ -7,9 +7,9 @@ import ( accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1" fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1" - sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1" ) func TestResolveTradeAmountsBuyBase(t *testing.T) { @@ -50,7 +50,7 @@ func TestComputeAggregatesConvertsCurrencies(t *testing.T) { }, } - debit, settlement := computeAggregates(pay, settle, fee, network, fxQuote, sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED) + debit, settlement := computeAggregates(pay, settle, fee, network, fxQuote, paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED) if debit.GetCurrency() != "USD" || debit.GetAmount() != "115" { t.Fatalf("expected debit 115 USD, got %s %s", debit.GetCurrency(), debit.GetAmount()) } @@ -71,7 +71,7 @@ func TestComputeAggregatesRecipientPaysFee(t *testing.T) { }, } - debit, settlement := computeAggregates(pay, settle, fee, nil, fxQuote, sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE) + debit, settlement := computeAggregates(pay, settle, fee, nil, fxQuote, paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE) if debit.GetCurrency() != "USDT" || debit.GetAmount() != "100" { t.Fatalf("expected debit 100 USDT, got %s %s", debit.GetCurrency(), debit.GetAmount()) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go b/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go index 971c01f6..7eac6bb5 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go @@ -14,6 +14,7 @@ import ( "github.com/tech/sendico/pkg/model/account_role" paymenttypes "github.com/tech/sendico/pkg/payments/types" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1" ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1" orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1" @@ -60,7 +61,7 @@ func TestNewPayment(t *testing.T) { intent := &sharedv1.PaymentIntent{ Ref: "ref-1", Amount: &moneyv1.Money{Currency: "USD", Amount: "10"}, - SettlementMode: sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, + SettlementMode: paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, SettlementCurrency: "USD", } quote := &sharedv1.PaymentQuote{QuoteRef: "q1"} diff --git a/api/payments/quotation/internal/service/quotation/convert.go b/api/payments/quotation/internal/service/quotation/convert.go index 5d31a541..452690fd 100644 --- a/api/payments/quotation/internal/service/quotation/convert.go +++ b/api/payments/quotation/internal/service/quotation/convert.go @@ -11,6 +11,7 @@ import ( accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1" fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1" sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1" @@ -293,25 +294,25 @@ func modelKindFromProto(kind sharedv1.PaymentKind) model.PaymentKind { } } -func settlementModeFromProto(mode sharedv1.SettlementMode) model.SettlementMode { +func settlementModeFromProto(mode paymentv1.SettlementMode) model.SettlementMode { switch mode { - case sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE: + case paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE: return model.SettlementModeFixSource - case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: + case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: return model.SettlementModeFixReceived default: return model.SettlementModeUnspecified } } -func settlementModeToProto(mode model.SettlementMode) sharedv1.SettlementMode { +func settlementModeToProto(mode model.SettlementMode) paymentv1.SettlementMode { switch mode { case model.SettlementModeFixSource: - return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE + return paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE case model.SettlementModeFixReceived: - return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED + return paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED default: - return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED + return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED } } diff --git a/api/payments/quotation/internal/service/quotation/helpers.go b/api/payments/quotation/internal/service/quotation/helpers.go index 4389fa22..1bc1b1ec 100644 --- a/api/payments/quotation/internal/service/quotation/helpers.go +++ b/api/payments/quotation/internal/service/quotation/helpers.go @@ -8,7 +8,6 @@ import ( oracleclient "github.com/tech/sendico/fx/oracle/client" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1" - sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" @@ -16,6 +15,7 @@ import ( accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1" fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" ) type moneyGetter interface { @@ -174,7 +174,7 @@ func resolveTradeAmounts(intentAmount *moneyv1.Money, fxQuote *oraclev1.Quote, s } } -func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.EstimateTransferFeeResponse, fxQuote *oraclev1.Quote, mode sharedv1.SettlementMode) (*moneyv1.Money, *moneyv1.Money) { +func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.EstimateTransferFeeResponse, fxQuote *oraclev1.Quote, mode paymentv1.SettlementMode) (*moneyv1.Money, *moneyv1.Money) { if pay == nil { return nil, nil } @@ -216,7 +216,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est } switch mode { - case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: + case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: // Sender pays the fee: keep settlement fixed, increase debit. applyChargeToDebit(fee) default: @@ -226,7 +226,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est if network != nil && network.GetNetworkFee() != nil { switch mode { - case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: + case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED: applyChargeToDebit(network.GetNetworkFee()) default: applyChargeToSettlement(network.GetNetworkFee()) diff --git a/api/server/internal/server/paymentapiimp/mapper.go b/api/server/internal/server/paymentapiimp/mapper.go index 41d27388..883a9799 100644 --- a/api/server/internal/server/paymentapiimp/mapper.go +++ b/api/server/internal/server/paymentapiimp/mapper.go @@ -8,6 +8,7 @@ import ( paymenttypes "github.com/tech/sendico/pkg/payments/types" fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1" + paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1" chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1" sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1" "github.com/tech/sendico/server/interface/api/srequest" @@ -325,16 +326,16 @@ func mapPaymentKind(kind srequest.PaymentKind) (sharedv1.PaymentKind, error) { } } -func mapSettlementMode(mode srequest.SettlementMode) (sharedv1.SettlementMode, error) { +func mapSettlementMode(mode srequest.SettlementMode) (paymentv1.SettlementMode, error) { switch strings.TrimSpace(string(mode)) { case "", string(srequest.SettlementModeUnspecified): - return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED, nil + return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED, nil case string(srequest.SettlementModeFixSource): - return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE, nil + return paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE, nil case string(srequest.SettlementModeFixReceived): - return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, nil + return paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, nil default: - return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED, merrors.InvalidArgument("unsupported settlement mode: " + string(mode)) + return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED, merrors.InvalidArgument("unsupported settlement mode: " + string(mode)) } }