unified gateway interfaces

This commit is contained in:
Stephan D
2026-01-04 12:47:43 +01:00
parent 743f683d92
commit 59c83e414a
41 changed files with 927 additions and 186 deletions

View File

@@ -1,19 +1,22 @@
package srequest
import (
"strings"
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/model"
)
type PaymentIntent struct {
Kind PaymentKind `json:"kind,omitempty"`
Source *Endpoint `json:"source,omitempty"`
Destination *Endpoint `json:"destination,omitempty"`
Amount *model.Money `json:"amount,omitempty"`
FX *FXIntent `json:"fx,omitempty"`
SettlementMode SettlementMode `json:"settlement_mode,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
Customer *Customer `json:"customer,omitempty"`
Kind PaymentKind `json:"kind,omitempty"`
Source *Endpoint `json:"source,omitempty"`
Destination *Endpoint `json:"destination,omitempty"`
Amount *model.Money `json:"amount,omitempty"`
FX *FXIntent `json:"fx,omitempty"`
SettlementMode SettlementMode `json:"settlement_mode,omitempty"`
SettlementCurrency string `json:"settlement_currency,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
Customer *Customer `json:"customer,omitempty"`
}
type AssetResolverStub struct{}
@@ -51,5 +54,11 @@ func (p *PaymentIntent) Validate() error {
}
}
if strings.TrimSpace(p.SettlementCurrency) != "" {
if err := ValidateCurrency(p.SettlementCurrency, &AssetResolverStub{}); err != nil {
return err
}
}
return nil
}

View File

@@ -26,6 +26,10 @@ func mapPaymentIntent(intent *srequest.PaymentIntent) (*orchestratorv1.PaymentIn
if err != nil {
return nil, err
}
settlementCurrency := strings.TrimSpace(intent.SettlementCurrency)
if settlementCurrency == "" {
settlementCurrency = resolveSettlementCurrency(intent)
}
source, err := mapPaymentEndpoint(intent.Source, "source")
if err != nil {
@@ -42,18 +46,66 @@ func mapPaymentIntent(intent *srequest.PaymentIntent) (*orchestratorv1.PaymentIn
}
return &orchestratorv1.PaymentIntent{
Kind: kind,
Source: source,
Destination: destination,
Amount: mapMoney(intent.Amount),
RequiresFx: fx != nil,
Fx: fx,
SettlementMode: settlementMode,
Attributes: copyStringMap(intent.Attributes),
Customer: mapCustomer(intent.Customer),
Kind: kind,
Source: source,
Destination: destination,
Amount: mapMoney(intent.Amount),
RequiresFx: fx != nil,
Fx: fx,
SettlementMode: settlementMode,
SettlementCurrency: settlementCurrency,
Attributes: copyStringMap(intent.Attributes),
Customer: mapCustomer(intent.Customer),
}, nil
}
func resolveSettlementCurrency(intent *srequest.PaymentIntent) string {
if intent == nil {
return ""
}
fx := intent.FX
if fx != nil && fx.Pair != nil {
base := strings.TrimSpace(fx.Pair.Base)
quote := strings.TrimSpace(fx.Pair.Quote)
switch strings.TrimSpace(string(fx.Side)) {
case string(srequest.FXSideBuyBaseSellQuote):
if base != "" {
return base
}
case string(srequest.FXSideSellBaseBuyQuote):
if quote != "" {
return quote
}
}
if intent.Amount != nil {
amountCurrency := strings.TrimSpace(intent.Amount.Currency)
if amountCurrency != "" {
switch {
case strings.EqualFold(amountCurrency, base) && quote != "":
return quote
case strings.EqualFold(amountCurrency, quote) && base != "":
return base
default:
return amountCurrency
}
}
}
if quote != "" {
return quote
}
if base != "" {
return base
}
}
if intent.Amount != nil {
return strings.TrimSpace(intent.Amount.Currency)
}
return ""
}
func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestratorv1.PaymentEndpoint, error) {
if endpoint == nil {
return nil, nil