fee treatment added
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user