Merge pull request 'fixed settlement mode import' (#502) from quote-500 into main
Reviewed-on: #502
This commit was merged in pull request #502.
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
gatewayv1 "github.com/tech/sendico/pkg/proto/common/gateway/v1"
|
gatewayv1 "github.com/tech/sendico/pkg/proto/common/gateway/v1"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/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"
|
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
||||||
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/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 {
|
switch mode {
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE:
|
||||||
return model.SettlementModeFixSource
|
return model.SettlementModeFixSource
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
||||||
return model.SettlementModeFixReceived
|
return model.SettlementModeFixReceived
|
||||||
default:
|
default:
|
||||||
return model.SettlementModeUnspecified
|
return model.SettlementModeUnspecified
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func settlementModeToProto(mode model.SettlementMode) sharedv1.SettlementMode {
|
func settlementModeToProto(mode model.SettlementMode) paymentv1.SettlementMode {
|
||||||
switch mode {
|
switch mode {
|
||||||
case model.SettlementModeFixSource:
|
case model.SettlementModeFixSource:
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE
|
return paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE
|
||||||
case model.SettlementModeFixReceived:
|
case model.SettlementModeFixReceived:
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED
|
return paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED
|
||||||
default:
|
default:
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED
|
return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||||
|
paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type moneyGetter interface {
|
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 {
|
if pay == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
||||||
// Sender pays the fee: keep settlement fixed, increase debit.
|
// Sender pays the fee: keep settlement fixed, increase debit.
|
||||||
applyChargeToDebit(fee)
|
applyChargeToDebit(fee)
|
||||||
default:
|
default:
|
||||||
@@ -152,7 +153,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est
|
|||||||
|
|
||||||
if network != nil && network.GetNetworkFee() != nil {
|
if network != nil && network.GetNetworkFee() != nil {
|
||||||
switch mode {
|
switch mode {
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
||||||
applyChargeToDebit(network.GetNetworkFee())
|
applyChargeToDebit(network.GetNetworkFee())
|
||||||
default:
|
default:
|
||||||
applyChargeToSettlement(network.GetNetworkFee())
|
applyChargeToSettlement(network.GetNetworkFee())
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/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"
|
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/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) {
|
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" {
|
if debit.GetCurrency() != "USD" || debit.GetAmount() != "115" {
|
||||||
t.Fatalf("expected debit 115 USD, got %s %s", debit.GetCurrency(), debit.GetAmount())
|
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" {
|
if debit.GetCurrency() != "USDT" || debit.GetAmount() != "100" {
|
||||||
t.Fatalf("expected debit 100 USDT, got %s %s", debit.GetCurrency(), debit.GetAmount())
|
t.Fatalf("expected debit 100 USDT, got %s %s", debit.GetCurrency(), debit.GetAmount())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/tech/sendico/pkg/model/account_role"
|
"github.com/tech/sendico/pkg/model/account_role"
|
||||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
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"
|
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
|
||||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||||
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
|
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
|
||||||
@@ -60,7 +61,7 @@ func TestNewPayment(t *testing.T) {
|
|||||||
intent := &sharedv1.PaymentIntent{
|
intent := &sharedv1.PaymentIntent{
|
||||||
Ref: "ref-1",
|
Ref: "ref-1",
|
||||||
Amount: &moneyv1.Money{Currency: "USD", Amount: "10"},
|
Amount: &moneyv1.Money{Currency: "USD", Amount: "10"},
|
||||||
SettlementMode: sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED,
|
SettlementMode: paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED,
|
||||||
SettlementCurrency: "USD",
|
SettlementCurrency: "USD",
|
||||||
}
|
}
|
||||||
quote := &sharedv1.PaymentQuote{QuoteRef: "q1"}
|
quote := &sharedv1.PaymentQuote{QuoteRef: "q1"}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/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"
|
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
|
||||||
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/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 {
|
switch mode {
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE:
|
||||||
return model.SettlementModeFixSource
|
return model.SettlementModeFixSource
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
||||||
return model.SettlementModeFixReceived
|
return model.SettlementModeFixReceived
|
||||||
default:
|
default:
|
||||||
return model.SettlementModeUnspecified
|
return model.SettlementModeUnspecified
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func settlementModeToProto(mode model.SettlementMode) sharedv1.SettlementMode {
|
func settlementModeToProto(mode model.SettlementMode) paymentv1.SettlementMode {
|
||||||
switch mode {
|
switch mode {
|
||||||
case model.SettlementModeFixSource:
|
case model.SettlementModeFixSource:
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE
|
return paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE
|
||||||
case model.SettlementModeFixReceived:
|
case model.SettlementModeFixReceived:
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED
|
return paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED
|
||||||
default:
|
default:
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED
|
return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
oracleclient "github.com/tech/sendico/fx/oracle/client"
|
oracleclient "github.com/tech/sendico/fx/oracle/client"
|
||||||
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||||
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/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/proto"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
@@ -16,6 +15,7 @@ import (
|
|||||||
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
|
||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||||
|
paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type moneyGetter interface {
|
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 {
|
if pay == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
||||||
// Sender pays the fee: keep settlement fixed, increase debit.
|
// Sender pays the fee: keep settlement fixed, increase debit.
|
||||||
applyChargeToDebit(fee)
|
applyChargeToDebit(fee)
|
||||||
default:
|
default:
|
||||||
@@ -226,7 +226,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est
|
|||||||
|
|
||||||
if network != nil && network.GetNetworkFee() != nil {
|
if network != nil && network.GetNetworkFee() != nil {
|
||||||
switch mode {
|
switch mode {
|
||||||
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
|
||||||
applyChargeToDebit(network.GetNetworkFee())
|
applyChargeToDebit(network.GetNetworkFee())
|
||||||
default:
|
default:
|
||||||
applyChargeToSettlement(network.GetNetworkFee())
|
applyChargeToSettlement(network.GetNetworkFee())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
paymenttypes "github.com/tech/sendico/pkg/payments/types"
|
||||||
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
|
||||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/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"
|
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
|
||||||
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
|
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
|
||||||
"github.com/tech/sendico/server/interface/api/srequest"
|
"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)) {
|
switch strings.TrimSpace(string(mode)) {
|
||||||
case "", string(srequest.SettlementModeUnspecified):
|
case "", string(srequest.SettlementModeUnspecified):
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED, nil
|
return paymentv1.SettlementMode_SETTLEMENT_UNSPECIFIED, nil
|
||||||
case string(srequest.SettlementModeFixSource):
|
case string(srequest.SettlementModeFixSource):
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE, nil
|
return paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE, nil
|
||||||
case string(srequest.SettlementModeFixReceived):
|
case string(srequest.SettlementModeFixReceived):
|
||||||
return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, nil
|
return paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, nil
|
||||||
default:
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user