mece request / payment economics

This commit is contained in:
Stephan D
2026-02-24 18:02:20 +01:00
parent 2e08ec9b9b
commit 4c5677202a
32 changed files with 704 additions and 223 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/tech/sendico/payments/storage/model"
pkgmodel "github.com/tech/sendico/pkg/model"
payecon "github.com/tech/sendico/pkg/payments/economics"
paymentv1 "github.com/tech/sendico/pkg/proto/common/payment/v1"
endpointv1 "github.com/tech/sendico/pkg/proto/payments/endpoint/v1"
quotationv2 "github.com/tech/sendico/pkg/proto/payments/quotation/v2"
@@ -28,12 +29,16 @@ func mapIntentSnapshot(src model.PaymentIntent) (*quotationv2.QuoteIntent, error
}
settlementMode := settlementModeToProto(src.SettlementMode)
feeTreatment := payecon.DefaultFeeTreatment()
if len(src.Attributes) > 0 {
feeTreatment = payecon.ResolveFeeTreatmentFromStringOrDefault(src.Attributes["fee_treatment"])
}
return &quotationv2.QuoteIntent{
Source: source,
Destination: destination,
Amount: moneyToProto(src.Amount),
SettlementMode: settlementMode,
FeeTreatment: feeTreatmentForSettlementMode(settlementMode),
FeeTreatment: feeTreatment,
SettlementCurrency: strings.ToUpper(strings.TrimSpace(src.SettlementCurrency)),
Comment: strings.TrimSpace(src.Attributes["comment"]),
}, nil
@@ -186,15 +191,6 @@ func settlementModeToProto(mode model.SettlementMode) paymentv1.SettlementMode {
}
}
func feeTreatmentForSettlementMode(mode paymentv1.SettlementMode) quotationv2.FeeTreatment {
switch mode {
case paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
return quotationv2.FeeTreatment_FEE_TREATMENT_DEDUCT_FROM_DESTINATION
default:
return quotationv2.FeeTreatment_FEE_TREATMENT_ADD_TO_SOURCE
}
}
func uintToString(value uint32) string {
if value == 0 {
return ""

View File

@@ -5,6 +5,7 @@ import (
"time"
"github.com/tech/sendico/payments/storage/model"
payecon "github.com/tech/sendico/pkg/payments/economics"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
@@ -42,7 +43,7 @@ func mapQuoteSnapshot(
ExecutionConditions: executionConditionsToProto(src.ExecutionConditions),
PayerTotalDebitAmount: moneyToProto(src.TotalCost),
ResolvedSettlementMode: resolvedSettlementMode,
ResolvedFeeTreatment: feeTreatmentForSettlementMode(resolvedSettlementMode),
ResolvedFeeTreatment: payecon.DefaultFeeTreatment(),
IntentRef: strings.TrimSpace(intentRef),
}
}

View File

@@ -53,7 +53,7 @@ func TestMap_Success(t *testing.T) {
if got, want := intent.GetSettlementMode(), paymentv1.SettlementMode_SETTLEMENT_FIX_SOURCE; got != want {
t.Fatalf("settlement_mode mismatch: got=%s want=%s", got.String(), want.String())
}
if got, want := intent.GetFeeTreatment(), quotationv2.FeeTreatment_FEE_TREATMENT_ADD_TO_SOURCE; got != want {
if got, want := intent.GetFeeTreatment(), quotationv2.FeeTreatment_FEE_TREATMENT_DEDUCT_FROM_DESTINATION; got != want {
t.Fatalf("fee_treatment mismatch: got=%s want=%s", got.String(), want.String())
}
if got, want := intent.GetComment(), "invoice-7"; got != want {
@@ -92,7 +92,7 @@ func TestMap_Success(t *testing.T) {
if got, want := quote.GetResolvedSettlementMode(), paymentv1.SettlementMode_SETTLEMENT_FIX_RECEIVED; got != want {
t.Fatalf("resolved_settlement_mode mismatch: got=%s want=%s", got.String(), want.String())
}
if got, want := quote.GetResolvedFeeTreatment(), quotationv2.FeeTreatment_FEE_TREATMENT_DEDUCT_FROM_DESTINATION; got != want {
if got, want := quote.GetResolvedFeeTreatment(), quotationv2.FeeTreatment_FEE_TREATMENT_ADD_TO_SOURCE; got != want {
t.Fatalf("resolved_fee_treatment mismatch: got=%s want=%s", got.String(), want.String())
}
if got, want := quote.GetIntentRef(), payment.IntentSnapshot.Ref; got != want {
@@ -241,7 +241,8 @@ func newPaymentFixture() *agg.Payment {
SettlementMode: model.SettlementModeFixSource,
SettlementCurrency: "USD",
Attributes: map[string]string{
"comment": "invoice-7",
"comment": "invoice-7",
"fee_treatment": "deduct_from_destination",
},
},
QuoteSnapshot: &model.PaymentQuoteSnapshot{