fee treatment added

This commit is contained in:
Stephan D
2026-02-24 16:39:08 +01:00
parent 2fe90347a8
commit 2e08ec9b9b
17 changed files with 162 additions and 30 deletions

View File

@@ -313,7 +313,7 @@ func (s *Service) publishPendingConfirmationResult(pending *storagemodel.Pending
return nil
}
func (s *Service) sendTelegramText(ctx context.Context, request *model.TelegramTextRequest) error {
func (s *Service) sendTelegramText(_ context.Context, request *model.TelegramTextRequest) error {
if request == nil {
return merrors.InvalidArgument("telegram text request is nil", "request")
}

View File

@@ -756,27 +756,3 @@ func readEnv(env string) string {
}
var _ grpcapp.Service = (*Service)(nil)
func statusFromConfirmationResult(r *model.ConfirmationResult) storagemodel.PaymentStatus {
if r == nil {
return storagemodel.PaymentStatusWaiting
}
switch r.Status {
case model.ConfirmationStatusConfirmed:
return storagemodel.PaymentStatusProcessing
case model.ConfirmationStatusClarified:
return storagemodel.PaymentStatusWaiting
case model.ConfirmationStatusRejected:
return storagemodel.PaymentStatusFailed
case model.ConfirmationStatusTimeout:
return storagemodel.PaymentStatusFailed
default:
return storagemodel.PaymentStatusFailed
}
}

View File

@@ -8,11 +8,10 @@ import (
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/db/storable"
pm "github.com/tech/sendico/pkg/model"
"github.com/tech/sendico/pkg/mservice"
"go.mongodb.org/mongo-driver/v2/bson"
)
const paymentsV2Collection = "payments_v2"
type paymentDocument struct {
storable.Base `bson:",inline"`
pm.OrganizationBoundBase `bson:",inline"`
@@ -28,7 +27,7 @@ type paymentDocument struct {
}
func (*paymentDocument) Collection() string {
return paymentsV2Collection
return mservice.Payments
}
func toDocument(payment *agg.Payment) (*paymentDocument, error) {

View File

@@ -9,6 +9,7 @@ import (
"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/psvc"
"github.com/tech/sendico/payments/storage"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
orchestrationv2 "github.com/tech/sendico/pkg/proto/payments/orchestration/v2"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.uber.org/zap"
@@ -81,7 +82,7 @@ func buildPaymentRepositoryV2(repo storage.Repository, logger mlogger.Logger) pr
return nil
}
paymentRepo, err := prepo.NewMongo(
db.Collection("payments_v2"),
db.Collection(mservice.Payments),
prepo.Dependencies{Logger: logger.Named("orchestration_v2_prepo")},
)
if err != nil {

View File

@@ -20,6 +20,15 @@ const (
SettlementModeFixReceived SettlementMode = "fix_received"
)
// FeeTreatment controls where fee impact is applied by quotation.
type FeeTreatment string
const (
FeeTreatmentUnspecified FeeTreatment = "unspecified"
FeeTreatmentAddToSource FeeTreatment = "add_to_source"
FeeTreatmentDeductFromDestination FeeTreatment = "deduct_from_destination"
)
// FXSide mirrors the common FX side enum.
type FXSide string

View File

@@ -14,6 +14,7 @@ type PaymentIntent struct {
Amount *paymenttypes.Money `json:"amount,omitempty"`
FX *FXIntent `json:"fx,omitempty"`
SettlementMode SettlementMode `json:"settlement_mode,omitempty"`
FeeTreatment FeeTreatment `json:"fee_treatment,omitempty"`
SettlementCurrency string `json:"settlement_currency,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
Customer *Customer `json:"customer,omitempty"`

View File

@@ -28,6 +28,10 @@ func mapQuoteIntent(intent *srequest.PaymentIntent) (*quotationv2.QuoteIntent, e
if err != nil {
return nil, err
}
feeTreatment, err := mapFeeTreatment(intent.FeeTreatment)
if err != nil {
return nil, err
}
settlementCurrency := strings.TrimSpace(intent.SettlementCurrency)
if settlementCurrency == "" {
settlementCurrency = resolveSettlementCurrency(intent)
@@ -47,6 +51,7 @@ func mapQuoteIntent(intent *srequest.PaymentIntent) (*quotationv2.QuoteIntent, e
Destination: destination,
Amount: mapMoney(intent.Amount),
SettlementMode: settlementMode,
FeeTreatment: feeTreatment,
SettlementCurrency: settlementCurrency,
}
if comment := strings.TrimSpace(intent.Attributes["comment"]); comment != "" {
@@ -250,6 +255,19 @@ func mapSettlementMode(mode srequest.SettlementMode) (paymentv1.SettlementMode,
}
}
func mapFeeTreatment(treatment srequest.FeeTreatment) (quotationv2.FeeTreatment, error) {
switch strings.TrimSpace(string(treatment)) {
case "", string(srequest.FeeTreatmentUnspecified):
return quotationv2.FeeTreatment_FEE_TREATMENT_UNSPECIFIED, nil
case string(srequest.FeeTreatmentAddToSource):
return quotationv2.FeeTreatment_FEE_TREATMENT_ADD_TO_SOURCE, nil
case string(srequest.FeeTreatmentDeductFromDestination):
return quotationv2.FeeTreatment_FEE_TREATMENT_DEDUCT_FROM_DESTINATION, nil
default:
return quotationv2.FeeTreatment_FEE_TREATMENT_UNSPECIFIED, merrors.InvalidArgument("unsupported fee treatment: " + string(treatment))
}
}
func mapChainNetwork(chain srequest.ChainNetwork) (chainv1.ChainNetwork, error) {
switch strings.TrimSpace(string(chain)) {
case "", string(srequest.ChainNetworkUnspecified):

View File

@@ -0,0 +1,82 @@
package paymentapiimp
import (
"testing"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
quotationv2 "github.com/tech/sendico/pkg/proto/payments/quotation/v2"
"github.com/tech/sendico/server/interface/api/srequest"
)
func TestMapQuoteIntent_PropagatesFeeTreatment(t *testing.T) {
source, err := srequest.NewManagedWalletEndpointDTO(srequest.ManagedWalletEndpoint{
ManagedWalletRef: "wallet-source-1",
}, nil)
if err != nil {
t.Fatalf("failed to build source endpoint: %v", err)
}
destination, err := srequest.NewCardEndpointDTO(srequest.CardEndpoint{
Pan: "2200700142860161",
FirstName: "John",
LastName: "Doe",
ExpMonth: 3,
ExpYear: 2030,
}, nil)
if err != nil {
t.Fatalf("failed to build destination endpoint: %v", err)
}
intent := &srequest.PaymentIntent{
Kind: srequest.PaymentKindPayout,
Source: &source,
Destination: &destination,
Amount: &paymenttypes.Money{Amount: "10", Currency: "USDT"},
SettlementMode: srequest.SettlementModeFixReceived,
FeeTreatment: srequest.FeeTreatmentDeductFromDestination,
}
got, err := mapQuoteIntent(intent)
if err != nil {
t.Fatalf("mapQuoteIntent returned error: %v", err)
}
if got == nil {
t.Fatalf("expected mapped quote intent")
}
if got.GetFeeTreatment() != quotationv2.FeeTreatment_FEE_TREATMENT_DEDUCT_FROM_DESTINATION {
t.Fatalf("unexpected fee treatment: got=%s", got.GetFeeTreatment().String())
}
}
func TestMapQuoteIntent_InvalidFeeTreatmentFails(t *testing.T) {
source, err := srequest.NewManagedWalletEndpointDTO(srequest.ManagedWalletEndpoint{
ManagedWalletRef: "wallet-source-1",
}, nil)
if err != nil {
t.Fatalf("failed to build source endpoint: %v", err)
}
destination, err := srequest.NewCardEndpointDTO(srequest.CardEndpoint{
Pan: "2200700142860161",
FirstName: "John",
LastName: "Doe",
ExpMonth: 3,
ExpYear: 2030,
}, nil)
if err != nil {
t.Fatalf("failed to build destination endpoint: %v", err)
}
intent := &srequest.PaymentIntent{
Kind: srequest.PaymentKindPayout,
Source: &source,
Destination: &destination,
Amount: &paymenttypes.Money{Amount: "10", Currency: "USDT"},
SettlementMode: srequest.SettlementModeFixSource,
FeeTreatment: srequest.FeeTreatment("wrong_value"),
}
if _, err := mapQuoteIntent(intent); err == nil {
t.Fatalf("expected error for invalid fee treatment")
}
}