fix for proto migration

This commit is contained in:
Stephan D
2026-02-11 18:15:04 +01:00
parent fab07fdc8e
commit 7b53ca6cef
62 changed files with 517 additions and 554 deletions

View File

@@ -9,8 +9,7 @@ import (
"github.com/tech/sendico/pkg/merrors"
orchestrationv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
quotationv1 "github.com/tech/sendico/pkg/proto/payments/quotation/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
@@ -18,8 +17,6 @@ import (
// Client exposes typed helpers around the payment orchestration and quotation gRPC APIs.
type Client interface {
QuotePayment(ctx context.Context, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.QuotePaymentResponse, error)
QuotePayments(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error)
InitiatePayments(ctx context.Context, req *orchestratorv1.InitiatePaymentsRequest) (*orchestratorv1.InitiatePaymentsResponse, error)
InitiatePayment(ctx context.Context, req *orchestratorv1.InitiatePaymentRequest) (*orchestratorv1.InitiatePaymentResponse, error)
CancelPayment(ctx context.Context, req *orchestratorv1.CancelPaymentRequest) (*orchestratorv1.CancelPaymentResponse, error)
@@ -42,17 +39,11 @@ type grpcOrchestratorClient interface {
ProcessDepositObserved(ctx context.Context, in *orchestratorv1.ProcessDepositObservedRequest, opts ...grpc.CallOption) (*orchestratorv1.ProcessDepositObservedResponse, error)
}
type grpcQuotationClient interface {
QuotePayment(ctx context.Context, in *orchestratorv1.QuotePaymentRequest, opts ...grpc.CallOption) (*orchestratorv1.QuotePaymentResponse, error)
QuotePayments(ctx context.Context, in *orchestratorv1.QuotePaymentsRequest, opts ...grpc.CallOption) (*orchestratorv1.QuotePaymentsResponse, error)
}
type orchestratorClient struct {
cfg Config
conn *grpc.ClientConn
quoteConn *grpc.ClientConn
client grpcOrchestratorClient
quoteClient grpcQuotationClient
cfg Config
conn *grpc.ClientConn
quoteConn *grpc.ClientConn
client grpcOrchestratorClient
}
// New dials the payment orchestrator endpoint and returns a ready client.
@@ -80,11 +71,10 @@ func New(ctx context.Context, cfg Config, opts ...grpc.DialOption) (Client, erro
}
return &orchestratorClient{
cfg: cfg,
conn: conn,
quoteConn: quoteConn,
client: orchestrationv1.NewPaymentExecutionServiceClient(conn),
quoteClient: quotationv1.NewQuotationServiceClient(quoteConn),
cfg: cfg,
conn: conn,
quoteConn: quoteConn,
client: orchestrationv1.NewPaymentExecutionServiceClient(conn),
}, nil
}
@@ -109,28 +99,22 @@ func dial(ctx context.Context, cfg Config, address string, opts ...grpc.DialOpti
// NewWithClient injects a pre-built orchestrator client (useful for tests).
func NewWithClient(cfg Config, oc grpcOrchestratorClient) Client {
return NewWithClients(cfg, oc, nil)
return NewWithClients(cfg, oc)
}
// NewWithClients injects pre-built orchestrator and quotation clients (useful for tests).
func NewWithClients(cfg Config, oc grpcOrchestratorClient, qc grpcQuotationClient) Client {
func NewWithClients(cfg Config, oc grpcOrchestratorClient) Client {
cfg.setDefaults()
if qc == nil {
if q, ok := any(oc).(grpcQuotationClient); ok {
qc = q
}
}
return &orchestratorClient{
cfg: cfg,
client: oc,
quoteClient: qc,
cfg: cfg,
client: oc,
}
}
func (c *orchestratorClient) Close() error {
var firstErr error
if c.quoteConn != nil && c.quoteConn != c.conn {
if err := c.quoteConn.Close(); err != nil && firstErr == nil {
if err := c.quoteConn.Close(); err != nil {
firstErr = err
}
}
@@ -142,24 +126,6 @@ func (c *orchestratorClient) Close() error {
return firstErr
}
func (c *orchestratorClient) QuotePayment(ctx context.Context, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.QuotePaymentResponse, error) {
if c.quoteClient == nil {
return nil, merrors.InvalidArgument("payment-orchestrator: quotation client is not configured")
}
ctx, cancel := c.callContext(ctx)
defer cancel()
return c.quoteClient.QuotePayment(ctx, req)
}
func (c *orchestratorClient) QuotePayments(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error) {
if c.quoteClient == nil {
return nil, merrors.InvalidArgument("payment-orchestrator: quotation client is not configured")
}
ctx, cancel := c.callContext(ctx)
defer cancel()
return c.quoteClient.QuotePayments(ctx, req)
}
func (c *orchestratorClient) InitiatePayments(ctx context.Context, req *orchestratorv1.InitiatePaymentsRequest) (*orchestratorv1.InitiatePaymentsResponse, error) {
ctx, cancel := c.callContext(ctx)
defer cancel()

View File

@@ -3,13 +3,11 @@ package client
import (
"context"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
)
// Fake implements Client for tests.
type Fake struct {
QuotePaymentFn func(ctx context.Context, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.QuotePaymentResponse, error)
QuotePaymentsFn func(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error)
InitiatePaymentsFn func(ctx context.Context, req *orchestratorv1.InitiatePaymentsRequest) (*orchestratorv1.InitiatePaymentsResponse, error)
InitiatePaymentFn func(ctx context.Context, req *orchestratorv1.InitiatePaymentRequest) (*orchestratorv1.InitiatePaymentResponse, error)
CancelPaymentFn func(ctx context.Context, req *orchestratorv1.CancelPaymentRequest) (*orchestratorv1.CancelPaymentResponse, error)
@@ -21,20 +19,6 @@ type Fake struct {
CloseFn func() error
}
func (f *Fake) QuotePayment(ctx context.Context, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.QuotePaymentResponse, error) {
if f.QuotePaymentFn != nil {
return f.QuotePaymentFn(ctx, req)
}
return &orchestratorv1.QuotePaymentResponse{}, nil
}
func (f *Fake) QuotePayments(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error) {
if f.QuotePaymentsFn != nil {
return f.QuotePaymentsFn(ctx, req)
}
return &orchestratorv1.QuotePaymentsResponse{}, nil
}
func (f *Fake) InitiatePayments(ctx context.Context, req *orchestratorv1.InitiatePaymentsRequest) (*orchestratorv1.InitiatePaymentsResponse, error) {
if f.InitiatePaymentsFn != nil {
return f.InitiatePaymentsFn(ctx, req)

View File

@@ -5,7 +5,7 @@ import (
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model/account_role"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
const (
@@ -55,9 +55,9 @@ func EnsureExecutionRefs(payment *model.Payment) *model.ExecutionRefs {
func ExecutionQuote(
payment *model.Payment,
quote *orchestratorv1.PaymentQuote,
quoteFromSnapshot func(*model.PaymentQuoteSnapshot) *orchestratorv1.PaymentQuote,
) *orchestratorv1.PaymentQuote {
quote *sharedv1.PaymentQuote,
quoteFromSnapshot func(*model.PaymentQuoteSnapshot) *sharedv1.PaymentQuote,
) *sharedv1.PaymentQuote {
return executionQuote(payment, quote, quoteFromSnapshot)
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/google/uuid"
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/model/account_role"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func ensureExecutionRefs(payment *model.Payment) *model.ExecutionRefs {
@@ -19,16 +19,16 @@ func ensureExecutionRefs(payment *model.Payment) *model.ExecutionRefs {
func executionQuote(
payment *model.Payment,
quote *orchestratorv1.PaymentQuote,
quoteFromSnapshot func(*model.PaymentQuoteSnapshot) *orchestratorv1.PaymentQuote,
) *orchestratorv1.PaymentQuote {
quote *sharedv1.PaymentQuote,
quoteFromSnapshot func(*model.PaymentQuoteSnapshot) *sharedv1.PaymentQuote,
) *sharedv1.PaymentQuote {
if quote != nil {
return quote
}
if payment != nil && payment.LastQuote != nil && quoteFromSnapshot != nil {
return quoteFromSnapshot(payment.LastQuote)
}
return &orchestratorv1.PaymentQuote{}
return &sharedv1.PaymentQuote{}
}
func ensureExecutionPlanForPlan(

View File

@@ -11,11 +11,11 @@ import (
paymenttypes "github.com/tech/sendico/pkg/payments/types"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
func (s *Service) submitCardFundingTransfers(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote) error {
func (s *Service) submitCardFundingTransfers(ctx context.Context, payment *model.Payment, quote *sharedv1.PaymentQuote) error {
if payment == nil {
return merrors.InvalidArgument("payment is required")
}

View File

@@ -13,7 +13,7 @@ import (
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -107,7 +107,7 @@ func TestSubmitCardFundingTransfers_PlansTopUpAndFunding(t *testing.T) {
},
}
quote := &orchestratorv1.PaymentQuote{
quote := &sharedv1.PaymentQuote{
ExpectedFeeTotal: &moneyv1.Money{Currency: "USDT", Amount: "0.35"},
}
@@ -360,7 +360,7 @@ func TestSubmitCardFundingTransfers_RequiresFeeWalletRef(t *testing.T) {
},
}
quote := &orchestratorv1.PaymentQuote{
quote := &sharedv1.PaymentQuote{
ExpectedFeeTotal: &moneyv1.Money{Currency: "USDT", Amount: "0.35"},
}

View File

@@ -6,13 +6,13 @@ import (
"github.com/tech/sendico/payments/storage"
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/mlogger"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
type paymentEngine interface {
EnsureRepository(ctx context.Context) error
ResolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*orchestratorv1.PaymentQuote, *orchestratorv1.PaymentIntent, *model.PaymentPlan, error)
ExecutePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *orchestratorv1.PaymentQuote) error
ResolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*sharedv1.PaymentQuote, *sharedv1.PaymentIntent, *model.PaymentPlan, error)
ExecutePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *sharedv1.PaymentQuote) error
Repository() storage.Repository
}
@@ -24,11 +24,11 @@ func (e defaultPaymentEngine) EnsureRepository(ctx context.Context) error {
return e.svc.ensureRepository(ctx)
}
func (e defaultPaymentEngine) ResolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*orchestratorv1.PaymentQuote, *orchestratorv1.PaymentIntent, *model.PaymentPlan, error) {
func (e defaultPaymentEngine) ResolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*sharedv1.PaymentQuote, *sharedv1.PaymentIntent, *model.PaymentPlan, error) {
return e.svc.resolvePaymentQuote(ctx, in)
}
func (e defaultPaymentEngine) ExecutePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *orchestratorv1.PaymentQuote) error {
func (e defaultPaymentEngine) ExecutePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *sharedv1.PaymentQuote) error {
return e.svc.executePayment(ctx, store, payment, quote)
}

View File

@@ -14,11 +14,12 @@ import (
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"google.golang.org/protobuf/types/known/timestamppb"
)
func intentFromProto(src *orchestratorv1.PaymentIntent) model.PaymentIntent {
func intentFromProto(src *sharedv1.PaymentIntent) model.PaymentIntent {
if src == nil {
return model.PaymentIntent{}
}
@@ -41,7 +42,7 @@ func intentFromProto(src *orchestratorv1.PaymentIntent) model.PaymentIntent {
return intent
}
func endpointFromProto(src *orchestratorv1.PaymentEndpoint) model.PaymentEndpoint {
func endpointFromProto(src *sharedv1.PaymentEndpoint) model.PaymentEndpoint {
if src == nil {
return model.PaymentEndpoint{Type: model.EndpointTypeUnspecified}
}
@@ -92,7 +93,7 @@ func endpointFromProto(src *orchestratorv1.PaymentEndpoint) model.PaymentEndpoin
return result
}
func fxIntentFromProto(src *orchestratorv1.FXIntent) *model.FXIntent {
func fxIntentFromProto(src *sharedv1.FXIntent) *model.FXIntent {
if src == nil {
return nil
}
@@ -106,7 +107,7 @@ func fxIntentFromProto(src *orchestratorv1.FXIntent) *model.FXIntent {
}
}
func quoteSnapshotToModel(src *orchestratorv1.PaymentQuote) *model.PaymentQuoteSnapshot {
func quoteSnapshotToModel(src *sharedv1.PaymentQuote) *model.PaymentQuoteSnapshot {
if src == nil {
return nil
}
@@ -123,11 +124,11 @@ func quoteSnapshotToModel(src *orchestratorv1.PaymentQuote) *model.PaymentQuoteS
}
}
func toProtoPayment(src *model.Payment) *orchestratorv1.Payment {
func toProtoPayment(src *model.Payment) *sharedv1.Payment {
if src == nil {
return nil
}
payment := &orchestratorv1.Payment{
payment := &sharedv1.Payment{
PaymentRef: src.PaymentRef,
IdempotencyKey: src.IdempotencyKey,
Intent: protoIntentFromModel(src.Intent),
@@ -141,7 +142,7 @@ func toProtoPayment(src *model.Payment) *orchestratorv1.Payment {
Metadata: cloneMetadata(src.Metadata),
}
if src.CardPayout != nil {
payment.CardPayout = &orchestratorv1.CardPayout{
payment.CardPayout = &sharedv1.CardPayout{
PayoutRef: src.CardPayout.PayoutRef,
ProviderPaymentId: src.CardPayout.ProviderPaymentID,
Status: src.CardPayout.Status,
@@ -163,8 +164,8 @@ func toProtoPayment(src *model.Payment) *orchestratorv1.Payment {
return payment
}
func protoIntentFromModel(src model.PaymentIntent) *orchestratorv1.PaymentIntent {
intent := &orchestratorv1.PaymentIntent{
func protoIntentFromModel(src model.PaymentIntent) *sharedv1.PaymentIntent {
intent := &sharedv1.PaymentIntent{
Ref: src.Ref,
Kind: protoKindFromModel(src.Kind),
Source: protoEndpointFromModel(src.Source),
@@ -183,7 +184,7 @@ func protoIntentFromModel(src model.PaymentIntent) *orchestratorv1.PaymentIntent
return intent
}
func customerFromProto(src *orchestratorv1.Customer) *model.Customer {
func customerFromProto(src *sharedv1.Customer) *model.Customer {
if src == nil {
return nil
}
@@ -201,11 +202,11 @@ func customerFromProto(src *orchestratorv1.Customer) *model.Customer {
}
}
func protoCustomerFromModel(src *model.Customer) *orchestratorv1.Customer {
func protoCustomerFromModel(src *model.Customer) *sharedv1.Customer {
if src == nil {
return nil
}
return &orchestratorv1.Customer{
return &sharedv1.Customer{
Id: strings.TrimSpace(src.ID),
FirstName: strings.TrimSpace(src.FirstName),
MiddleName: strings.TrimSpace(src.MiddleName),
@@ -219,16 +220,16 @@ func protoCustomerFromModel(src *model.Customer) *orchestratorv1.Customer {
}
}
func protoEndpointFromModel(src model.PaymentEndpoint) *orchestratorv1.PaymentEndpoint {
endpoint := &orchestratorv1.PaymentEndpoint{
func protoEndpointFromModel(src model.PaymentEndpoint) *sharedv1.PaymentEndpoint {
endpoint := &sharedv1.PaymentEndpoint{
Metadata: cloneMetadata(src.Metadata),
InstanceId: strings.TrimSpace(src.InstanceID),
}
switch src.Type {
case model.EndpointTypeLedger:
if src.Ledger != nil {
endpoint.Endpoint = &orchestratorv1.PaymentEndpoint_Ledger{
Ledger: &orchestratorv1.LedgerEndpoint{
endpoint.Endpoint = &sharedv1.PaymentEndpoint_Ledger{
Ledger: &sharedv1.LedgerEndpoint{
LedgerAccountRef: src.Ledger.LedgerAccountRef,
ContraLedgerAccountRef: src.Ledger.ContraLedgerAccountRef,
},
@@ -236,8 +237,8 @@ func protoEndpointFromModel(src model.PaymentEndpoint) *orchestratorv1.PaymentEn
}
case model.EndpointTypeManagedWallet:
if src.ManagedWallet != nil {
endpoint.Endpoint = &orchestratorv1.PaymentEndpoint_ManagedWallet{
ManagedWallet: &orchestratorv1.ManagedWalletEndpoint{
endpoint.Endpoint = &sharedv1.PaymentEndpoint_ManagedWallet{
ManagedWallet: &sharedv1.ManagedWalletEndpoint{
ManagedWalletRef: src.ManagedWallet.ManagedWalletRef,
Asset: assetToProto(src.ManagedWallet.Asset),
},
@@ -245,8 +246,8 @@ func protoEndpointFromModel(src model.PaymentEndpoint) *orchestratorv1.PaymentEn
}
case model.EndpointTypeExternalChain:
if src.ExternalChain != nil {
endpoint.Endpoint = &orchestratorv1.PaymentEndpoint_ExternalChain{
ExternalChain: &orchestratorv1.ExternalChainEndpoint{
endpoint.Endpoint = &sharedv1.PaymentEndpoint_ExternalChain{
ExternalChain: &sharedv1.ExternalChainEndpoint{
Asset: assetToProto(src.ExternalChain.Asset),
Address: src.ExternalChain.Address,
Memo: src.ExternalChain.Memo,
@@ -255,7 +256,7 @@ func protoEndpointFromModel(src model.PaymentEndpoint) *orchestratorv1.PaymentEn
}
case model.EndpointTypeCard:
if src.Card != nil {
card := &orchestratorv1.CardEndpoint{
card := &sharedv1.CardEndpoint{
CardholderName: src.Card.Cardholder,
CardholderSurname: src.Card.CardholderSurname,
ExpMonth: src.Card.ExpMonth,
@@ -264,12 +265,12 @@ func protoEndpointFromModel(src model.PaymentEndpoint) *orchestratorv1.PaymentEn
MaskedPan: src.Card.MaskedPan,
}
if pan := strings.TrimSpace(src.Card.Pan); pan != "" {
card.Card = &orchestratorv1.CardEndpoint_Pan{Pan: pan}
card.Card = &sharedv1.CardEndpoint_Pan{Pan: pan}
}
if token := strings.TrimSpace(src.Card.Token); token != "" {
card.Card = &orchestratorv1.CardEndpoint_Token{Token: token}
card.Card = &sharedv1.CardEndpoint_Token{Token: token}
}
endpoint.Endpoint = &orchestratorv1.PaymentEndpoint_Card{Card: card}
endpoint.Endpoint = &sharedv1.PaymentEndpoint_Card{Card: card}
}
default:
// leave unspecified
@@ -277,11 +278,11 @@ func protoEndpointFromModel(src model.PaymentEndpoint) *orchestratorv1.PaymentEn
return endpoint
}
func protoFXIntentFromModel(src *model.FXIntent) *orchestratorv1.FXIntent {
func protoFXIntentFromModel(src *model.FXIntent) *sharedv1.FXIntent {
if src == nil {
return nil
}
return &orchestratorv1.FXIntent{
return &sharedv1.FXIntent{
Pair: pairToProto(src.Pair),
Side: fxSideToProto(src.Side),
Firm: src.Firm,
@@ -291,11 +292,11 @@ func protoFXIntentFromModel(src *model.FXIntent) *orchestratorv1.FXIntent {
}
}
func protoExecutionFromModel(src *model.ExecutionRefs) *orchestratorv1.ExecutionRefs {
func protoExecutionFromModel(src *model.ExecutionRefs) *sharedv1.ExecutionRefs {
if src == nil {
return nil
}
return &orchestratorv1.ExecutionRefs{
return &sharedv1.ExecutionRefs{
DebitEntryRef: src.DebitEntryRef,
CreditEntryRef: src.CreditEntryRef,
FxEntryRef: src.FXEntryRef,
@@ -305,11 +306,11 @@ func protoExecutionFromModel(src *model.ExecutionRefs) *orchestratorv1.Execution
}
}
func protoExecutionStepFromModel(src *model.ExecutionStep) *orchestratorv1.ExecutionStep {
func protoExecutionStepFromModel(src *model.ExecutionStep) *sharedv1.ExecutionStep {
if src == nil {
return nil
}
return &orchestratorv1.ExecutionStep{
return &sharedv1.ExecutionStep{
Code: src.Code,
Description: src.Description,
Amount: protoMoney(src.Amount),
@@ -322,11 +323,11 @@ func protoExecutionStepFromModel(src *model.ExecutionStep) *orchestratorv1.Execu
}
}
func protoExecutionPlanFromModel(src *model.ExecutionPlan) *orchestratorv1.ExecutionPlan {
func protoExecutionPlanFromModel(src *model.ExecutionPlan) *sharedv1.ExecutionPlan {
if src == nil {
return nil
}
steps := make([]*orchestratorv1.ExecutionStep, 0, len(src.Steps))
steps := make([]*sharedv1.ExecutionStep, 0, len(src.Steps))
for _, step := range src.Steps {
if protoStep := protoExecutionStepFromModel(step); protoStep != nil {
steps = append(steps, protoStep)
@@ -335,17 +336,17 @@ func protoExecutionPlanFromModel(src *model.ExecutionPlan) *orchestratorv1.Execu
if len(steps) == 0 {
steps = nil
}
return &orchestratorv1.ExecutionPlan{
return &sharedv1.ExecutionPlan{
Steps: steps,
TotalNetworkFee: protoMoney(src.TotalNetworkFee),
}
}
func protoPaymentStepFromModel(src *model.PaymentStep) *orchestratorv1.PaymentStep {
func protoPaymentStepFromModel(src *model.PaymentStep) *sharedv1.PaymentStep {
if src == nil {
return nil
}
return &orchestratorv1.PaymentStep{
return &sharedv1.PaymentStep{
Rail: protoRailFromModel(src.Rail),
GatewayId: strings.TrimSpace(src.GatewayID),
Action: protoRailOperationFromModel(src.Action),
@@ -358,11 +359,11 @@ func protoPaymentStepFromModel(src *model.PaymentStep) *orchestratorv1.PaymentSt
}
}
func protoPaymentPlanFromModel(src *model.PaymentPlan) *orchestratorv1.PaymentPlan {
func protoPaymentPlanFromModel(src *model.PaymentPlan) *sharedv1.PaymentPlan {
if src == nil {
return nil
}
steps := make([]*orchestratorv1.PaymentStep, 0, len(src.Steps))
steps := make([]*sharedv1.PaymentStep, 0, len(src.Steps))
for _, step := range src.Steps {
if protoStep := protoPaymentStepFromModel(step); protoStep != nil {
steps = append(steps, protoStep)
@@ -371,7 +372,7 @@ func protoPaymentPlanFromModel(src *model.PaymentPlan) *orchestratorv1.PaymentPl
if len(steps) == 0 {
steps = nil
}
plan := &orchestratorv1.PaymentPlan{
plan := &sharedv1.PaymentPlan{
Id: strings.TrimSpace(src.ID),
Steps: steps,
IdempotencyKey: strings.TrimSpace(src.IdempotencyKey),
@@ -384,11 +385,11 @@ func protoPaymentPlanFromModel(src *model.PaymentPlan) *orchestratorv1.PaymentPl
return plan
}
func modelQuoteToProto(src *model.PaymentQuoteSnapshot) *orchestratorv1.PaymentQuote {
func modelQuoteToProto(src *model.PaymentQuoteSnapshot) *sharedv1.PaymentQuote {
if src == nil {
return nil
}
return &orchestratorv1.PaymentQuote{
return &sharedv1.PaymentQuote{
DebitAmount: protoMoney(src.DebitAmount),
DebitSettlementAmount: protoMoney(src.DebitSettlementAmount),
ExpectedSettlementAmount: protoMoney(src.ExpectedSettlementAmount),
@@ -423,26 +424,26 @@ func filterFromProto(req *orchestratorv1.ListPaymentsRequest) *model.PaymentFilt
return filter
}
func protoKindFromModel(kind model.PaymentKind) orchestratorv1.PaymentKind {
func protoKindFromModel(kind model.PaymentKind) sharedv1.PaymentKind {
switch kind {
case model.PaymentKindPayout:
return orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT
return sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT
case model.PaymentKindInternalTransfer:
return orchestratorv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER
return sharedv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER
case model.PaymentKindFXConversion:
return orchestratorv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION
return sharedv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION
default:
return orchestratorv1.PaymentKind_PAYMENT_KIND_UNSPECIFIED
return sharedv1.PaymentKind_PAYMENT_KIND_UNSPECIFIED
}
}
func modelKindFromProto(kind orchestratorv1.PaymentKind) model.PaymentKind {
func modelKindFromProto(kind sharedv1.PaymentKind) model.PaymentKind {
switch kind {
case orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT:
case sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT:
return model.PaymentKindPayout
case orchestratorv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER:
case sharedv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER:
return model.PaymentKindInternalTransfer
case orchestratorv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION:
case sharedv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION:
return model.PaymentKindFXConversion
default:
return model.PaymentKindUnspecified
@@ -495,82 +496,82 @@ func protoRailOperationFromModel(action model.RailOperation) gatewayv1.RailOpera
}
}
func protoStateFromModel(state model.PaymentState) orchestratorv1.PaymentState {
func protoStateFromModel(state model.PaymentState) sharedv1.PaymentState {
switch state {
case model.PaymentStateAccepted:
return orchestratorv1.PaymentState_PAYMENT_STATE_ACCEPTED
return sharedv1.PaymentState_PAYMENT_STATE_ACCEPTED
case model.PaymentStateFundsReserved:
return orchestratorv1.PaymentState_PAYMENT_STATE_FUNDS_RESERVED
return sharedv1.PaymentState_PAYMENT_STATE_FUNDS_RESERVED
case model.PaymentStateSubmitted:
return orchestratorv1.PaymentState_PAYMENT_STATE_SUBMITTED
return sharedv1.PaymentState_PAYMENT_STATE_SUBMITTED
case model.PaymentStateSettled:
return orchestratorv1.PaymentState_PAYMENT_STATE_SETTLED
return sharedv1.PaymentState_PAYMENT_STATE_SETTLED
case model.PaymentStateFailed:
return orchestratorv1.PaymentState_PAYMENT_STATE_FAILED
return sharedv1.PaymentState_PAYMENT_STATE_FAILED
case model.PaymentStateCancelled:
return orchestratorv1.PaymentState_PAYMENT_STATE_CANCELLED
return sharedv1.PaymentState_PAYMENT_STATE_CANCELLED
default:
return orchestratorv1.PaymentState_PAYMENT_STATE_UNSPECIFIED
return sharedv1.PaymentState_PAYMENT_STATE_UNSPECIFIED
}
}
func modelStateFromProto(state orchestratorv1.PaymentState) model.PaymentState {
func modelStateFromProto(state sharedv1.PaymentState) model.PaymentState {
switch state {
case orchestratorv1.PaymentState_PAYMENT_STATE_ACCEPTED:
case sharedv1.PaymentState_PAYMENT_STATE_ACCEPTED:
return model.PaymentStateAccepted
case orchestratorv1.PaymentState_PAYMENT_STATE_FUNDS_RESERVED:
case sharedv1.PaymentState_PAYMENT_STATE_FUNDS_RESERVED:
return model.PaymentStateFundsReserved
case orchestratorv1.PaymentState_PAYMENT_STATE_SUBMITTED:
case sharedv1.PaymentState_PAYMENT_STATE_SUBMITTED:
return model.PaymentStateSubmitted
case orchestratorv1.PaymentState_PAYMENT_STATE_SETTLED:
case sharedv1.PaymentState_PAYMENT_STATE_SETTLED:
return model.PaymentStateSettled
case orchestratorv1.PaymentState_PAYMENT_STATE_FAILED:
case sharedv1.PaymentState_PAYMENT_STATE_FAILED:
return model.PaymentStateFailed
case orchestratorv1.PaymentState_PAYMENT_STATE_CANCELLED:
case sharedv1.PaymentState_PAYMENT_STATE_CANCELLED:
return model.PaymentStateCancelled
default:
return model.PaymentStateUnspecified
}
}
func protoFailureFromModel(code model.PaymentFailureCode) orchestratorv1.PaymentFailureCode {
func protoFailureFromModel(code model.PaymentFailureCode) sharedv1.PaymentFailureCode {
switch code {
case model.PaymentFailureCodeBalance:
return orchestratorv1.PaymentFailureCode_FAILURE_BALANCE
return sharedv1.PaymentFailureCode_FAILURE_BALANCE
case model.PaymentFailureCodeLedger:
return orchestratorv1.PaymentFailureCode_FAILURE_LEDGER
return sharedv1.PaymentFailureCode_FAILURE_LEDGER
case model.PaymentFailureCodeFX:
return orchestratorv1.PaymentFailureCode_FAILURE_FX
return sharedv1.PaymentFailureCode_FAILURE_FX
case model.PaymentFailureCodeChain:
return orchestratorv1.PaymentFailureCode_FAILURE_CHAIN
return sharedv1.PaymentFailureCode_FAILURE_CHAIN
case model.PaymentFailureCodeFees:
return orchestratorv1.PaymentFailureCode_FAILURE_FEES
return sharedv1.PaymentFailureCode_FAILURE_FEES
case model.PaymentFailureCodePolicy:
return orchestratorv1.PaymentFailureCode_FAILURE_POLICY
return sharedv1.PaymentFailureCode_FAILURE_POLICY
default:
return orchestratorv1.PaymentFailureCode_FAILURE_UNSPECIFIED
return sharedv1.PaymentFailureCode_FAILURE_UNSPECIFIED
}
}
func settlementModeFromProto(mode orchestratorv1.SettlementMode) model.SettlementMode {
func settlementModeFromProto(mode sharedv1.SettlementMode) model.SettlementMode {
switch mode {
case orchestratorv1.SettlementMode_SETTLEMENT_FIX_SOURCE:
case sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE:
return model.SettlementModeFixSource
case orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
return model.SettlementModeFixReceived
default:
return model.SettlementModeUnspecified
}
}
func settlementModeToProto(mode model.SettlementMode) orchestratorv1.SettlementMode {
func settlementModeToProto(mode model.SettlementMode) sharedv1.SettlementMode {
switch mode {
case model.SettlementModeFixSource:
return orchestratorv1.SettlementMode_SETTLEMENT_FIX_SOURCE
return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE
case model.SettlementModeFixReceived:
return orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED
return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED
default:
return orchestratorv1.SettlementMode_SETTLEMENT_UNSPECIFIED
return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED
}
}

View File

@@ -4,14 +4,14 @@ import (
"testing"
"github.com/tech/sendico/payments/storage/model"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func TestEndpointFromProtoCard(t *testing.T) {
protoEndpoint := &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_Card{
Card: &orchestratorv1.CardEndpoint{
Card: &orchestratorv1.CardEndpoint_Pan{Pan: " 411111 "},
protoEndpoint := &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_Card{
Card: &sharedv1.CardEndpoint{
Card: &sharedv1.CardEndpoint_Pan{Pan: " 411111 "},
CardholderName: " Jane ",
CardholderSurname: " Doe ",
ExpMonth: 12,
@@ -58,7 +58,7 @@ func TestProtoEndpointFromModelCard(t *testing.T) {
if card == nil {
t.Fatalf("card payload missing in proto")
}
token, ok := card.Card.(*orchestratorv1.CardEndpoint_Token)
token, ok := card.Card.(*sharedv1.CardEndpoint_Token)
if !ok || token.Token != "tok_123" {
t.Fatalf("expected token payload, got %T %#v", card.Card, card.Card)
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/model/account_role"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
type Liveness = execution.Liveness
@@ -41,7 +41,7 @@ func ensureExecutionRefs(payment *model.Payment) *model.ExecutionRefs {
return execution.EnsureExecutionRefs(payment)
}
func executionQuote(payment *model.Payment, quote *orchestratorv1.PaymentQuote) *orchestratorv1.PaymentQuote {
func executionQuote(payment *model.Payment, quote *sharedv1.PaymentQuote) *sharedv1.PaymentQuote {
return execution.ExecutionQuote(payment, quote, modelQuoteToProto)
}

View File

@@ -14,7 +14,8 @@ import (
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
"github.com/tech/sendico/pkg/mutil/mzap"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
@@ -79,7 +80,7 @@ func (h *initiatePaymentsCommand) Execute(ctx context.Context, req *orchestrator
return gsresponse.Unavailable[orchestratorv1.InitiatePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err)
}
payments := make([]*orchestratorv1.Payment, 0, len(intents))
payments := make([]*sharedv1.Payment, 0, len(intents))
for i := range intents {
intentProto := protoIntentFromModel(intents[i])
if err := requireNonNilIntent(intentProto); err != nil {
@@ -217,7 +218,7 @@ func (h *initiatePaymentCommand) Execute(ctx context.Context, req *orchestratorv
return gsresponse.Auto[orchestratorv1.InitiatePaymentResponse](h.logger, mservice.PaymentOrchestrator, err)
}
if quoteSnapshot == nil {
quoteSnapshot = &orchestratorv1.PaymentQuote{}
quoteSnapshot = &sharedv1.PaymentQuote{}
}
if err := requireNonNilIntent(resolvedIntent); err != nil {
return gsresponse.InvalidArgument[orchestratorv1.InitiatePaymentResponse](h.logger, mservice.PaymentOrchestrator, err)
@@ -345,9 +346,9 @@ func (h *initiateConversionCommand) Execute(ctx context.Context, req *orchestrat
return gsresponse.InvalidArgument[orchestratorv1.InitiateConversionResponse](h.logger, mservice.PaymentOrchestrator, err)
}
intentProto := &orchestratorv1.PaymentIntent{
intentProto := &sharedv1.PaymentIntent{
Ref: uuid.New().String(),
Kind: orchestratorv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION,
Kind: sharedv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION,
Source: req.GetSource(),
Destination: req.GetDestination(),
Amount: amount,

View File

@@ -12,7 +12,7 @@ import (
"github.com/tech/sendico/pkg/mservice"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
"go.uber.org/zap"
)

View File

@@ -9,7 +9,8 @@ import (
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
@@ -71,7 +72,7 @@ func (h *paymentQueryHandler) listPayments(ctx context.Context, req *orchestrato
NextCursor: result.NextCursor,
},
}
resp.Payments = make([]*orchestratorv1.Payment, 0, len(result.Items))
resp.Payments = make([]*sharedv1.Payment, 0, len(result.Items))
for _, item := range result.Items {
resp.Payments = append(resp.Payments, toProtoPayment(item))
}

View File

@@ -8,7 +8,7 @@ import (
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1"
accountingv1 "github.com/tech/sendico/pkg/proto/common/accounting/v1"
@@ -100,7 +100,7 @@ func resolveTradeAmounts(intentAmount *moneyv1.Money, fxQuote *oraclev1.Quote, s
}
}
func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.EstimateTransferFeeResponse, fxQuote *oraclev1.Quote, mode orchestratorv1.SettlementMode) (*moneyv1.Money, *moneyv1.Money) {
func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.EstimateTransferFeeResponse, fxQuote *oraclev1.Quote, mode sharedv1.SettlementMode) (*moneyv1.Money, *moneyv1.Money) {
if pay == nil {
return nil, nil
}
@@ -142,7 +142,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est
}
switch mode {
case orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
// Sender pays the fee: keep settlement fixed, increase debit.
applyChargeToDebit(fee)
default:
@@ -152,7 +152,7 @@ func computeAggregates(pay, settlement, fee *moneyv1.Money, network *chainv1.Est
if network != nil && network.GetNetworkFee() != nil {
switch mode {
case orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
case sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED:
applyChargeToDebit(network.GetNetworkFee())
default:
applyChargeToSettlement(network.GetNetworkFee())
@@ -276,7 +276,7 @@ func moneyEquals(a, b moneyGetter) bool {
return strings.TrimSpace(a.GetAmount()) == strings.TrimSpace(b.GetAmount())
}
func conversionAmountFromMetadata(meta map[string]string, fx *orchestratorv1.FXIntent) (*moneyv1.Money, error) {
func conversionAmountFromMetadata(meta map[string]string, fx *sharedv1.FXIntent) (*moneyv1.Money, error) {
if meta == nil {
meta = map[string]string{}
}

View File

@@ -9,7 +9,7 @@ import (
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func TestResolveTradeAmountsBuyBase(t *testing.T) {
@@ -50,7 +50,7 @@ func TestComputeAggregatesConvertsCurrencies(t *testing.T) {
},
}
debit, settlement := computeAggregates(pay, settle, fee, network, fxQuote, orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED)
debit, settlement := computeAggregates(pay, settle, fee, network, fxQuote, sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED)
if debit.GetCurrency() != "USD" || debit.GetAmount() != "115" {
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, orchestratorv1.SettlementMode_SETTLEMENT_FIX_SOURCE)
debit, settlement := computeAggregates(pay, settle, fee, nil, fxQuote, sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE)
if debit.GetCurrency() != "USDT" || debit.GetAmount() != "100" {
t.Fatalf("expected debit 100 USDT, got %s %s", debit.GetCurrency(), debit.GetAmount())
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/tech/sendico/pkg/api/routers/gsresponse"
"github.com/tech/sendico/pkg/mservice"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func (s *Service) ensureRepository(ctx context.Context) error {
@@ -24,7 +24,7 @@ func executeUnary[TReq any, TResp any](ctx context.Context, svc *Service, method
return resp, err
}
func shouldEstimateNetworkFee(intent *orchestratorv1.PaymentIntent) bool {
func shouldEstimateNetworkFee(intent *sharedv1.PaymentIntent) bool {
if intent == nil {
return false
}
@@ -35,7 +35,7 @@ func shouldEstimateNetworkFee(intent *orchestratorv1.PaymentIntent) bool {
if dest.GetCard() != nil {
return false
}
if intent.GetKind() == orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT {
if intent.GetKind() == sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT {
return true
}
if dest.GetManagedWallet() != nil || dest.GetExternalChain() != nil {

View File

@@ -5,16 +5,16 @@ import (
"github.com/tech/sendico/payments/storage/model"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func TestShouldEstimateNetworkFeeSkipsCard(t *testing.T) {
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Kind: orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT,
Destination: &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_Card{
Card: &orchestratorv1.CardEndpoint{},
Kind: sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT,
Destination: &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_Card{
Card: &sharedv1.CardEndpoint{},
},
},
}
@@ -24,11 +24,11 @@ func TestShouldEstimateNetworkFeeSkipsCard(t *testing.T) {
}
func TestShouldEstimateNetworkFeeManagedWallet(t *testing.T) {
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Destination: &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_ManagedWallet{
ManagedWallet: &orchestratorv1.ManagedWalletEndpoint{ManagedWalletRef: "mw"},
Destination: &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_ManagedWallet{
ManagedWallet: &sharedv1.ManagedWalletEndpoint{ManagedWalletRef: "mw"},
},
},
}

View File

@@ -11,7 +11,7 @@ import (
fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
@@ -25,7 +25,7 @@ func newPaymentExecutor(deps *serviceDependencies, logger mlogger.Logger, svc *S
return &paymentExecutor{deps: deps, logger: logger, svc: svc}
}
func (p *paymentExecutor) executePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *orchestratorv1.PaymentQuote) error {
func (p *paymentExecutor) executePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *sharedv1.PaymentQuote) error {
if store == nil {
return errStorageUnavailable
}
@@ -45,7 +45,7 @@ func (p *paymentExecutor) executePayment(ctx context.Context, store storage.Paym
return p.executePaymentPlan(ctx, store, payment, quote)
}
func (p *paymentExecutor) applyFX(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote, charges []*ledgerv1.PostingLine, description string, metadata map[string]string, exec *model.ExecutionRefs) error {
func (p *paymentExecutor) applyFX(ctx context.Context, payment *model.Payment, quote *sharedv1.PaymentQuote, charges []*ledgerv1.PostingLine, description string, metadata map[string]string, exec *model.ExecutionRefs) error {
intent := payment.Intent
source := intent.Source.Ledger
destination := intent.Destination.Ledger

View File

@@ -8,10 +8,10 @@ import (
"github.com/tech/sendico/pkg/model/account_role"
"github.com/tech/sendico/pkg/payments/rail"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func (p *paymentExecutor) buildCryptoTransferRequest(payment *model.Payment, amount *paymenttypes.Money, action model.RailOperation, idempotencyKey, operationRef string, quote *orchestratorv1.PaymentQuote, fromRole, toRole *account_role.AccountRole) (rail.TransferRequest, error) {
func (p *paymentExecutor) buildCryptoTransferRequest(payment *model.Payment, amount *paymenttypes.Money, action model.RailOperation, idempotencyKey, operationRef string, quote *sharedv1.PaymentQuote, fromRole, toRole *account_role.AccountRole) (rail.TransferRequest, error) {
if payment == nil {
return rail.TransferRequest{}, merrors.InvalidArgument("chain: payment is required")
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/tech/sendico/payments/storage"
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/merrors"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
@@ -35,7 +35,7 @@ func (p *paymentExecutor) pickIndependentSteps(
store storage.PaymentsStore,
waiting []*model.ExecutionStep,
payment *model.Payment,
quote *orchestratorv1.PaymentQuote,
quote *sharedv1.PaymentQuote,
) error {
logger := l.With(zap.Int("waiting_steps", len(waiting)))
@@ -112,7 +112,7 @@ func (p *paymentExecutor) pickWaitingSteps(
l *zap.Logger,
store storage.PaymentsStore,
payment *model.Payment,
quote *orchestratorv1.PaymentQuote,
quote *sharedv1.PaymentQuote,
) error {
if payment == nil || payment.ExecutionPlan == nil {
l.Debug("No execution plan")
@@ -145,7 +145,7 @@ func (p *paymentExecutor) executePaymentPlan(
ctx context.Context,
store storage.PaymentsStore,
payment *model.Payment,
quote *orchestratorv1.PaymentQuote,
quote *sharedv1.PaymentQuote,
) error {
if payment == nil {

View File

@@ -15,7 +15,7 @@ import (
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"
@@ -151,7 +151,7 @@ func TestExecutePaymentPlan_SourceBeforeDestination(t *testing.T) {
store.payments[payment.PaymentRef] = payment
if err := executor.executePaymentPlan(ctx, store, payment, &orchestratorv1.PaymentQuote{}); err != nil {
if err := executor.executePaymentPlan(ctx, store, payment, &sharedv1.PaymentQuote{}); err != nil {
t.Fatalf("executePaymentPlan error: %v", err)
}
@@ -177,7 +177,7 @@ func TestExecutePaymentPlan_SourceBeforeDestination(t *testing.T) {
// ---- имитируем подтверждение сети по crypto_send ----
setExecutionStepStatus(steps["crypto_send"], model.OperationStateSuccess)
if err := executor.executePaymentPlan(ctx, store, payment, &orchestratorv1.PaymentQuote{}); err != nil {
if err := executor.executePaymentPlan(ctx, store, payment, &sharedv1.PaymentQuote{}); err != nil {
t.Fatalf("executePaymentPlan resume error: %v", err)
}
@@ -192,7 +192,7 @@ func TestExecutePaymentPlan_SourceBeforeDestination(t *testing.T) {
// Имитируем подтверждение observe (это unlock ledger_credit)
setExecutionStepStatus(steps["crypto_observe"], model.OperationStateSuccess)
if err := executor.executePaymentPlan(ctx, store, payment, &orchestratorv1.PaymentQuote{}); err != nil {
if err := executor.executePaymentPlan(ctx, store, payment, &sharedv1.PaymentQuote{}); err != nil {
t.Fatalf("executePaymentPlan resume after observe error: %v", err)
}
@@ -207,7 +207,7 @@ func TestExecutePaymentPlan_SourceBeforeDestination(t *testing.T) {
cardStep := executionStepsByCode(payment.ExecutionPlan)["card_payout"]
setExecutionStepStatus(cardStep, model.OperationStateSuccess)
if err := executor.executePaymentPlan(ctx, store, payment, &orchestratorv1.PaymentQuote{}); err != nil {
if err := executor.executePaymentPlan(ctx, store, payment, &sharedv1.PaymentQuote{}); err != nil {
t.Fatalf("executePaymentPlan finalize error: %v", err)
}
@@ -269,7 +269,7 @@ func TestExecutePaymentPlan_RejectsLegacyLedgerOperations(t *testing.T) {
store.payments[payment.PaymentRef] = payment
err := executor.executePaymentPlan(ctx, store, payment, &orchestratorv1.PaymentQuote{})
err := executor.executePaymentPlan(ctx, store, payment, &sharedv1.PaymentQuote{})
if err == nil {
t.Fatal("expected legacy ledger operation error")
}

View File

@@ -13,12 +13,12 @@ import (
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
func (p *paymentExecutor) postLedgerDebit(ctx context.Context, payment *model.Payment, amount *moneyv1.Money, charges []*ledgerv1.PostingLine, idempotencyKey string, idx int, action model.RailOperation, quote *orchestratorv1.PaymentQuote) (string, error) {
func (p *paymentExecutor) postLedgerDebit(ctx context.Context, payment *model.Payment, amount *moneyv1.Money, charges []*ledgerv1.PostingLine, idempotencyKey string, idx int, action model.RailOperation, quote *sharedv1.PaymentQuote) (string, error) {
paymentRef := ""
if payment != nil {
paymentRef = strings.TrimSpace(payment.PaymentRef)
@@ -45,7 +45,7 @@ func (p *paymentExecutor) postLedgerDebit(ctx context.Context, payment *model.Pa
return ref, nil
}
func (p *paymentExecutor) postLedgerCredit(ctx context.Context, payment *model.Payment, amount *moneyv1.Money, idempotencyKey string, idx int, action model.RailOperation, quote *orchestratorv1.PaymentQuote) (string, error) {
func (p *paymentExecutor) postLedgerCredit(ctx context.Context, payment *model.Payment, amount *moneyv1.Money, idempotencyKey string, idx int, action model.RailOperation, quote *sharedv1.PaymentQuote) (string, error) {
paymentRef := ""
if payment != nil {
paymentRef = strings.TrimSpace(payment.PaymentRef)
@@ -144,7 +144,7 @@ func (p *paymentExecutor) postLedgerMove(ctx context.Context, payment *model.Pay
return entryRef, nil
}
func (p *paymentExecutor) ledgerTxForAction(ctx context.Context, payment *model.Payment, amount *moneyv1.Money, charges []*ledgerv1.PostingLine, idempotencyKey string, idx int, action model.RailOperation, quote *orchestratorv1.PaymentQuote) (rail.LedgerTx, error) {
func (p *paymentExecutor) ledgerTxForAction(ctx context.Context, payment *model.Payment, amount *moneyv1.Money, charges []*ledgerv1.PostingLine, idempotencyKey string, idx int, action model.RailOperation, quote *sharedv1.PaymentQuote) (rail.LedgerTx, error) {
if payment == nil {
return rail.LedgerTx{}, merrors.InvalidArgument("ledger: payment is required")
}

View File

@@ -10,7 +10,7 @@ import (
paymenttypes "github.com/tech/sendico/pkg/payments/types"
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"
@@ -96,7 +96,7 @@ func TestLedgerAccountResolution_UsesRoleAccounts(t *testing.T) {
store := newStubPaymentsStore()
store.payments[payment.PaymentRef] = payment
if err := executor.executePaymentPlan(ctx, store, payment, &orchestratorv1.PaymentQuote{}); err != nil {
if err := executor.executePaymentPlan(ctx, store, payment, &sharedv1.PaymentQuote{}); err != nil {
t.Fatalf("executePaymentPlan error: %v", err)
}
if listCalls == 0 {

View File

@@ -7,7 +7,7 @@ import (
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/merrors"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
@@ -16,7 +16,7 @@ func (p *paymentExecutor) executePlanStep(
payment *model.Payment,
step *model.PaymentStep,
execStep *model.ExecutionStep,
quote *orchestratorv1.PaymentQuote,
quote *sharedv1.PaymentQuote,
charges []*ledgerv1.PostingLine,
idx int,
) (bool, error) {
@@ -144,7 +144,7 @@ func (p *paymentExecutor) executeSendStep(
payment *model.Payment,
step *model.PaymentStep,
execStep *model.ExecutionStep,
quote *orchestratorv1.PaymentQuote,
quote *sharedv1.PaymentQuote,
idx int,
) (bool, error) {

View File

@@ -8,7 +8,7 @@ import (
"github.com/tech/sendico/pkg/model/account_role"
"github.com/tech/sendico/pkg/payments/rail"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
const (
@@ -20,7 +20,7 @@ const (
providerSettlementMetaSourceCurrency = "source_currency"
)
func (p *paymentExecutor) buildProviderSettlementTransferRequest(payment *model.Payment, step *model.PaymentStep, operationRef string, amount *paymenttypes.Money, quote *orchestratorv1.PaymentQuote, idx int, fromRole, toRole *account_role.AccountRole) (rail.TransferRequest, error) {
func (p *paymentExecutor) buildProviderSettlementTransferRequest(payment *model.Payment, step *model.PaymentStep, operationRef string, amount *paymenttypes.Money, quote *sharedv1.PaymentQuote, idx int, fromRole, toRole *account_role.AccountRole) (rail.TransferRequest, error) {
if payment == nil || step == nil {
return rail.TransferRequest{}, merrors.InvalidArgument("provider settlement: payment and step are required")
}
@@ -100,7 +100,7 @@ func (p *paymentExecutor) buildProviderSettlementTransferRequest(payment *model.
return req, nil
}
func paymentGatewayQuoteRef(payment *model.Payment, quote *orchestratorv1.PaymentQuote) string {
func paymentGatewayQuoteRef(payment *model.Payment, quote *sharedv1.PaymentQuote) string {
if quote != nil {
if ref := strings.TrimSpace(quote.GetQuoteRef()); ref != "" {
return ref

View File

@@ -8,7 +8,7 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/model/account_role"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func railFromEndpoint(endpoint model.PaymentEndpoint, attrs map[string]string, isSource bool) (model.Rail, string, error) {
@@ -60,7 +60,7 @@ func cloneAccountRole(role *account_role.AccountRole) *account_role.AccountRole
return &cloned
}
func resolveFeeAmount(payment *model.Payment, quote *orchestratorv1.PaymentQuote) *paymenttypes.Money {
func resolveFeeAmount(payment *model.Payment, quote *sharedv1.PaymentQuote) *paymenttypes.Money {
if quote != nil && quote.GetExpectedFeeTotal() != nil {
return moneyFromProto(quote.GetExpectedFeeTotal())
}

View File

@@ -12,7 +12,8 @@ import (
mb "github.com/tech/sendico/pkg/messaging/broker"
"github.com/tech/sendico/pkg/mlogger"
orchestrationv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"google.golang.org/grpc"
)
@@ -174,7 +175,7 @@ func (s *Service) ProcessCardPayoutUpdate(ctx context.Context, req *orchestrator
return executeUnary(ctx, s, "ProcessCardPayoutUpdate", s.h.events.processCardPayoutUpdate, req)
}
func (s *Service) executePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *orchestratorv1.PaymentQuote) error {
func (s *Service) executePayment(ctx context.Context, store storage.PaymentsStore, payment *model.Payment, quote *sharedv1.PaymentQuote) error {
s.ensureHandlers()
return s.comp.executor.executePayment(ctx, store, payment, quote)
}

View File

@@ -11,13 +11,13 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mservice"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
quotationv1 "github.com/tech/sendico/pkg/proto/payments/quotation/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"google.golang.org/protobuf/proto"
)
func validateMetaAndOrgRef(meta *orchestratorv1.RequestMeta) (string, bson.ObjectID, error) {
func validateMetaAndOrgRef(meta *sharedv1.RequestMeta) (string, bson.ObjectID, error) {
if meta == nil {
return "", bson.NilObjectID, merrors.InvalidArgument("meta is required")
}
@@ -48,7 +48,7 @@ func requirePaymentRef(ref string) (string, error) {
return val, nil
}
func requireNonNilIntent(intent *orchestratorv1.PaymentIntent) error {
func requireNonNilIntent(intent *sharedv1.PaymentIntent) error {
if intent == nil {
return merrors.InvalidArgument("intent is required")
}
@@ -94,8 +94,8 @@ func getPaymentByIdempotencyKey(ctx context.Context, store storage.PaymentsStore
type quoteResolutionInput struct {
OrgRef string
OrgID bson.ObjectID
Meta *orchestratorv1.RequestMeta
Intent *orchestratorv1.PaymentIntent
Meta *sharedv1.RequestMeta
Intent *sharedv1.PaymentIntent
QuoteRef string
IdempotencyKey string
}
@@ -107,7 +107,7 @@ type quoteResolutionError struct {
func (e quoteResolutionError) Error() string { return e.err.Error() }
func (s *Service) resolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*orchestratorv1.PaymentQuote, *orchestratorv1.PaymentIntent, *model.PaymentPlan, error) {
func (s *Service) resolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*sharedv1.PaymentQuote, *sharedv1.PaymentIntent, *model.PaymentPlan, error) {
if ref := strings.TrimSpace(in.QuoteRef); ref != "" {
quotesStore, err := ensureQuotesStore(s.storage)
if err != nil {
@@ -177,7 +177,7 @@ func (s *Service) resolvePaymentQuote(ctx context.Context, in quoteResolutionInp
})
}
func recordIntentFromQuote(record *model.PaymentQuoteRecord) (*orchestratorv1.PaymentIntent, error) {
func recordIntentFromQuote(record *model.PaymentQuoteRecord) (*sharedv1.PaymentIntent, error) {
if record == nil {
return nil, merrors.InvalidArgument("stored quote payload is incomplete")
}
@@ -193,7 +193,7 @@ func recordIntentFromQuote(record *model.PaymentQuoteRecord) (*orchestratorv1.Pa
return protoIntentFromModel(record.Intent), nil
}
func recordQuoteFromQuote(record *model.PaymentQuoteRecord) (*orchestratorv1.PaymentQuote, error) {
func recordQuoteFromQuote(record *model.PaymentQuoteRecord) (*sharedv1.PaymentQuote, error) {
if record == nil {
return nil, merrors.InvalidArgument("stored quote is empty")
}
@@ -225,7 +225,7 @@ func recordPlanFromQuote(record *model.PaymentQuoteRecord) (*model.PaymentPlan,
return nil, nil
}
func newPayment(orgID bson.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, metadata map[string]string, quote *orchestratorv1.PaymentQuote) *model.Payment {
func newPayment(orgID bson.ObjectID, intent *sharedv1.PaymentIntent, idempotencyKey string, metadata map[string]string, quote *sharedv1.PaymentQuote) *model.Payment {
entity := &model.Payment{}
entity.SetID(bson.NewObjectID())
entity.SetOrganizationRef(orgID)

View File

@@ -15,8 +15,9 @@ import (
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
connectorv1 "github.com/tech/sendico/pkg/proto/connector/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
quotationv1 "github.com/tech/sendico/pkg/proto/payments/quotation/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/structpb"
@@ -24,7 +25,7 @@ import (
func TestValidateMetaAndOrgRef(t *testing.T) {
org := bson.NewObjectID()
meta := &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()}
meta := &sharedv1.RequestMeta{OrganizationRef: org.Hex()}
ref, id, err := validateMetaAndOrgRef(meta)
if err != nil {
t.Fatalf("expected nil error: %v", err)
@@ -35,10 +36,10 @@ func TestValidateMetaAndOrgRef(t *testing.T) {
if _, _, err := validateMetaAndOrgRef(nil); err == nil {
t.Fatalf("expected error on nil meta")
}
if _, _, err := validateMetaAndOrgRef(&orchestratorv1.RequestMeta{OrganizationRef: ""}); err == nil {
if _, _, err := validateMetaAndOrgRef(&sharedv1.RequestMeta{OrganizationRef: ""}); err == nil {
t.Fatalf("expected error on empty orgRef")
}
if _, _, err := validateMetaAndOrgRef(&orchestratorv1.RequestMeta{OrganizationRef: "bad"}); err == nil {
if _, _, err := validateMetaAndOrgRef(&sharedv1.RequestMeta{OrganizationRef: "bad"}); err == nil {
t.Fatalf("expected error on invalid orgRef")
}
}
@@ -55,13 +56,13 @@ func TestRequireIdempotencyKey(t *testing.T) {
func TestNewPayment(t *testing.T) {
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Amount: &moneyv1.Money{Currency: "USD", Amount: "10"},
SettlementMode: orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED,
SettlementMode: sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED,
SettlementCurrency: "USD",
}
quote := &orchestratorv1.PaymentQuote{QuoteRef: "q1"}
quote := &sharedv1.PaymentQuote{QuoteRef: "q1"}
p := newPayment(org, intent, "idem", map[string]string{"k": "v"}, quote)
if p.PaymentRef == "" || p.IdempotencyKey != "idem" || p.State != model.PaymentStateAccepted {
t.Fatalf("unexpected payment fields: %+v", p)
@@ -86,8 +87,8 @@ func TestResolvePaymentQuote_NotFound(t *testing.T) {
_, _, _, err := svc.resolvePaymentQuote(context.Background(), quoteResolutionInput{
OrgRef: org.Hex(),
OrgID: org,
Meta: &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()},
Intent: &orchestratorv1.PaymentIntent{
Meta: &sharedv1.RequestMeta{OrganizationRef: org.Hex()},
Intent: &sharedv1.PaymentIntent{
Ref: "ref-1",
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"},
QuoteRef: "missing",
@@ -99,7 +100,7 @@ func TestResolvePaymentQuote_NotFound(t *testing.T) {
func TestResolvePaymentQuote_Expired(t *testing.T) {
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"}
record := &model.PaymentQuoteRecord{
@@ -115,7 +116,7 @@ func TestResolvePaymentQuote_Expired(t *testing.T) {
_, _, _, err := svc.resolvePaymentQuote(context.Background(), quoteResolutionInput{
OrgRef: org.Hex(),
OrgID: org,
Meta: &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()},
Meta: &sharedv1.RequestMeta{OrganizationRef: org.Hex()},
Intent: intent,
QuoteRef: "q1",
})
@@ -126,7 +127,7 @@ func TestResolvePaymentQuote_Expired(t *testing.T) {
func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) {
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"}, SettlementCurrency: "USD"}
record := &model.PaymentQuoteRecord{
@@ -141,7 +142,7 @@ func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) {
quote, resolvedIntent, _, err := svc.resolvePaymentQuote(context.Background(), quoteResolutionInput{
OrgRef: org.Hex(),
OrgID: org,
Meta: &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()},
Meta: &sharedv1.RequestMeta{OrganizationRef: org.Hex()},
QuoteRef: "q1",
})
if err != nil {
@@ -157,7 +158,7 @@ func TestResolvePaymentQuote_QuoteRefUsesStoredIntent(t *testing.T) {
func TestResolvePaymentQuote_QuoteRefSkipsQuoteRecompute(t *testing.T) {
org := bson.NewObjectID()
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"},
SettlementCurrency: "USD",
@@ -176,7 +177,7 @@ func TestResolvePaymentQuote_QuoteRefSkipsQuoteRecompute(t *testing.T) {
_, _, _, err := svc.resolvePaymentQuote(context.Background(), quoteResolutionInput{
OrgRef: org.Hex(),
OrgID: org,
Meta: &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()},
Meta: &sharedv1.RequestMeta{OrganizationRef: org.Hex()},
QuoteRef: "q1",
})
if err != nil {
@@ -188,13 +189,13 @@ func TestInitiatePaymentIdempotency(t *testing.T) {
logger := mloggerfactory.NewLogger(false)
org := bson.NewObjectID()
store := newHelperPaymentStore()
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Source: &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_Ledger{Ledger: &orchestratorv1.LedgerEndpoint{LedgerAccountRef: "ledger:source"}},
Source: &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_Ledger{Ledger: &sharedv1.LedgerEndpoint{LedgerAccountRef: "ledger:source"}},
},
Destination: &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_Ledger{Ledger: &orchestratorv1.LedgerEndpoint{LedgerAccountRef: "ledger:dest"}},
Destination: &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_Ledger{Ledger: &sharedv1.LedgerEndpoint{LedgerAccountRef: "ledger:dest"}},
},
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"},
SettlementCurrency: "USD",
@@ -242,7 +243,7 @@ func TestInitiatePaymentIdempotency(t *testing.T) {
quotePaymentFn: func(ctx context.Context, req *quotationv1.QuotePaymentRequest, opts ...grpc.CallOption) (*quotationv1.QuotePaymentResponse, error) {
amount := req.GetIntent().GetAmount()
return &quotationv1.QuotePaymentResponse{
Quote: &orchestratorv1.PaymentQuote{
Quote: &sharedv1.PaymentQuote{
QuoteRef: "q1",
DebitAmount: amount,
ExpectedSettlementAmount: amount,
@@ -253,7 +254,7 @@ func TestInitiatePaymentIdempotency(t *testing.T) {
}))
svc.ensureHandlers()
req := &orchestratorv1.InitiatePaymentRequest{
Meta: &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()},
Meta: &sharedv1.RequestMeta{OrganizationRef: org.Hex()},
Intent: intent,
IdempotencyKey: "k1",
}
@@ -274,13 +275,13 @@ func TestInitiatePaymentByQuoteRef(t *testing.T) {
logger := mloggerfactory.NewLogger(false)
org := bson.NewObjectID()
store := newHelperPaymentStore()
intent := &orchestratorv1.PaymentIntent{
intent := &sharedv1.PaymentIntent{
Ref: "ref-1",
Source: &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_Ledger{Ledger: &orchestratorv1.LedgerEndpoint{LedgerAccountRef: "ledger:source"}},
Source: &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_Ledger{Ledger: &sharedv1.LedgerEndpoint{LedgerAccountRef: "ledger:source"}},
},
Destination: &orchestratorv1.PaymentEndpoint{
Endpoint: &orchestratorv1.PaymentEndpoint_Ledger{Ledger: &orchestratorv1.LedgerEndpoint{LedgerAccountRef: "ledger:dest"}},
Destination: &sharedv1.PaymentEndpoint{
Endpoint: &sharedv1.PaymentEndpoint_Ledger{Ledger: &sharedv1.LedgerEndpoint{LedgerAccountRef: "ledger:dest"}},
},
Amount: &moneyv1.Money{Currency: "USD", Amount: "1"},
SettlementCurrency: "USD",
@@ -324,7 +325,7 @@ func TestInitiatePaymentByQuoteRef(t *testing.T) {
svc.ensureHandlers()
req := &orchestratorv1.InitiatePaymentRequest{
Meta: &orchestratorv1.RequestMeta{OrganizationRef: org.Hex()},
Meta: &sharedv1.RequestMeta{OrganizationRef: org.Hex()},
QuoteRef: "q1",
IdempotencyKey: "k1",
}

View File

@@ -20,7 +20,8 @@ import (
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.mongodb.org/mongo-driver/v2/bson"
"go.uber.org/zap"
)
@@ -70,7 +71,7 @@ func TestExecutePayment_FXConversionSettled(t *testing.T) {
}
store.payments[payment.PaymentRef] = payment
quote := &orchestratorv1.PaymentQuote{
quote := &sharedv1.PaymentQuote{
FxQuote: &oraclev1.Quote{
QuoteRef: "quote-1",
BaseAmount: &moneyv1.Money{Currency: "USD", Amount: "100"},
@@ -200,7 +201,7 @@ func TestExecutePayment_ChainFailure(t *testing.T) {
},
},
}, payment.IdempotencyKey)
err := svc.executePayment(ctx, store, payment, &orchestratorv1.PaymentQuote{})
err := svc.executePayment(ctx, store, payment, &sharedv1.PaymentQuote{})
if err == nil || err.Error() != "chain failure" {
t.Fatalf("expected chain failure error, got %v", err)
}
@@ -243,7 +244,7 @@ func TestProcessTransferUpdateHandler_Settled(t *testing.T) {
if err != nil {
t.Fatalf("handler returned error: %v", err)
}
if reSP.GetPayment().GetState() != orchestratorv1.PaymentState_PAYMENT_STATE_SETTLED {
if reSP.GetPayment().GetState() != sharedv1.PaymentState_PAYMENT_STATE_SETTLED {
t.Fatalf("expected settled state, got %s", reSP.GetPayment().GetState())
}
}
@@ -324,7 +325,7 @@ func TestProcessTransferUpdateHandler_CardFundingWaitsForSources(t *testing.T) {
if fundStep.State != model.OperationStateSuccess {
t.Fatalf("expected funding step confirmed, got %s", feeStep.State)
}
if resp.GetPayment().GetState() != orchestratorv1.PaymentState_PAYMENT_STATE_SUBMITTED {
if resp.GetPayment().GetState() != sharedv1.PaymentState_PAYMENT_STATE_SUBMITTED {
t.Fatalf("expected submitted state, got %s", resp.GetPayment().GetState())
}
@@ -389,7 +390,7 @@ func TestProcessDepositObservedHandler_MatchesPayment(t *testing.T) {
if err != nil {
t.Fatalf("handler returned error: %v", err)
}
if reSP.GetPayment().GetState() != orchestratorv1.PaymentState_PAYMENT_STATE_SETTLED {
if reSP.GetPayment().GetState() != sharedv1.PaymentState_PAYMENT_STATE_SETTLED {
t.Fatalf("expected settled state, got %s", reSP.GetPayment().GetState())
}
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/tech/sendico/pkg/merrors"
"github.com/tech/sendico/pkg/mlogger"
"github.com/tech/sendico/pkg/mutil/mzap"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
@@ -22,7 +22,7 @@ func New(logger mlogger.Logger) *defaultPlanBuilder {
}
}
func (b *defaultPlanBuilder) Build(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) {
func (b *defaultPlanBuilder) Build(ctx context.Context, payment *model.Payment, quote *sharedv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) {
if payment == nil {
return nil, merrors.InvalidArgument("plan builder: payment is required")
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/tech/sendico/pkg/model/account_role"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func TestDefaultPlanBuilder_BuildsPlanFromRoutes_CryptoToCard(t *testing.T) {
@@ -46,7 +46,7 @@ func TestDefaultPlanBuilder_BuildsPlanFromRoutes_CryptoToCard(t *testing.T) {
},
}
quote := &orchestratorv1.PaymentQuote{
quote := &sharedv1.PaymentQuote{
ExpectedSettlementAmount: &moneyv1.Money{Currency: "USDT", Amount: "95"},
ExpectedFeeTotal: &moneyv1.Money{Currency: "USDT", Amount: "5"},
}
@@ -165,7 +165,7 @@ func TestDefaultPlanBuilder_ErrorsWhenRouteMissing(t *testing.T) {
templates := &stubPlanTemplateStore{}
registry := &stubGatewayRegistry{}
plan, err := builder.Build(ctx, payment, &orchestratorv1.PaymentQuote{}, routes, templates, registry)
plan, err := builder.Build(ctx, payment, &sharedv1.PaymentQuote{}, routes, templates, registry)
if err == nil {
t.Fatalf("expected error, got plan: %#v", plan)
}
@@ -196,7 +196,7 @@ func TestBuildPlanFromTemplate_ProviderSettlementUsesNetAmountWhenFixReceived(t
},
}
quote := &orchestratorv1.PaymentQuote{
quote := &sharedv1.PaymentQuote{
DebitAmount: &moneyv1.Money{Currency: "USDT", Amount: "105"},
ExpectedSettlementAmount: &moneyv1.Money{Currency: "USDT", Amount: "100"},
ExpectedFeeTotal: &moneyv1.Money{Currency: "USDT", Amount: "5"},
@@ -271,7 +271,7 @@ func TestDefaultPlanBuilder_UsesSourceCurrencyForCryptoSendWithFX(t *testing.T)
},
}
quote := &orchestratorv1.PaymentQuote{
quote := &sharedv1.PaymentQuote{
DebitAmount: &moneyv1.Money{Currency: "USDT", Amount: "1.498"},
ExpectedSettlementAmount: &moneyv1.Money{Currency: "RUB", Amount: "108.99"},
ExpectedFeeTotal: &moneyv1.Money{Currency: "USDT", Amount: "0.098"},

View File

@@ -14,7 +14,7 @@ import (
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
chainv1 "github.com/tech/sendico/pkg/proto/gateway/chain/v1"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
type moneyGetter interface {
@@ -185,21 +185,21 @@ func cardPayoutAmount(payment *model.Payment) (*paymenttypes.Money, error) {
return amount, nil
}
func executionQuote(payment *model.Payment, quote *orchestratorv1.PaymentQuote) *orchestratorv1.PaymentQuote {
func executionQuote(payment *model.Payment, quote *sharedv1.PaymentQuote) *sharedv1.PaymentQuote {
if quote != nil {
return quote
}
if payment != nil && payment.LastQuote != nil {
return modelQuoteToProto(payment.LastQuote)
}
return &orchestratorv1.PaymentQuote{}
return &sharedv1.PaymentQuote{}
}
func modelQuoteToProto(src *model.PaymentQuoteSnapshot) *orchestratorv1.PaymentQuote {
func modelQuoteToProto(src *model.PaymentQuoteSnapshot) *sharedv1.PaymentQuote {
if src == nil {
return nil
}
return &orchestratorv1.PaymentQuote{
return &sharedv1.PaymentQuote{
DebitAmount: protoMoney(src.DebitAmount),
DebitSettlementAmount: protoMoney(src.DebitSettlementAmount),
ExpectedSettlementAmount: protoMoney(src.ExpectedSettlementAmount),

View File

@@ -6,7 +6,7 @@ import (
"github.com/tech/sendico/payments/storage/model"
"github.com/tech/sendico/pkg/merrors"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
)
func buildFXConversionPlan(payment *model.Payment) (*model.PaymentPlan, error) {
@@ -28,7 +28,7 @@ func buildFXConversionPlan(payment *model.Payment) (*model.PaymentPlan, error) {
}, nil
}
func resolveSettlementAmount(payment *model.Payment, quote *orchestratorv1.PaymentQuote, fallback *paymenttypes.Money) *paymenttypes.Money {
func resolveSettlementAmount(payment *model.Payment, quote *sharedv1.PaymentQuote, fallback *paymenttypes.Money) *paymenttypes.Money {
if quote != nil && quote.GetExpectedSettlementAmount() != nil {
return moneyFromProto(quote.GetExpectedSettlementAmount())
}
@@ -38,7 +38,7 @@ func resolveSettlementAmount(payment *model.Payment, quote *orchestratorv1.Payme
return cloneMoney(fallback)
}
func resolveDebitAmount(payment *model.Payment, quote *orchestratorv1.PaymentQuote, fallback *paymenttypes.Money) *paymenttypes.Money {
func resolveDebitAmount(payment *model.Payment, quote *sharedv1.PaymentQuote, fallback *paymenttypes.Money) *paymenttypes.Money {
if quote != nil && quote.GetDebitAmount() != nil {
return moneyFromProto(quote.GetDebitAmount())
}
@@ -48,7 +48,7 @@ func resolveDebitAmount(payment *model.Payment, quote *orchestratorv1.PaymentQuo
return cloneMoney(fallback)
}
func resolveFeeAmount(payment *model.Payment, quote *orchestratorv1.PaymentQuote) *paymenttypes.Money {
func resolveFeeAmount(payment *model.Payment, quote *sharedv1.PaymentQuote) *paymenttypes.Money {
if quote != nil && quote.GetExpectedFeeTotal() != nil {
return moneyFromProto(quote.GetExpectedFeeTotal())
}

View File

@@ -9,11 +9,11 @@ import (
"github.com/tech/sendico/pkg/mutil/mzap"
paymenttypes "github.com/tech/sendico/pkg/payments/types"
oraclev1 "github.com/tech/sendico/pkg/proto/oracle/v1"
orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1"
sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1"
"go.uber.org/zap"
)
func (b *defaultPlanBuilder) buildPlanFromTemplate(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote, template *model.PaymentPlanTemplate, sourceRail, destRail model.Rail, sourceNetwork, destNetwork string, gateways GatewayRegistry) (*model.PaymentPlan, error) {
func (b *defaultPlanBuilder) buildPlanFromTemplate(ctx context.Context, payment *model.Payment, quote *sharedv1.PaymentQuote, template *model.PaymentPlanTemplate, sourceRail, destRail model.Rail, sourceNetwork, destNetwork string, gateways GatewayRegistry) (*model.PaymentPlan, error) {
if template == nil {
return nil, merrors.InvalidArgument("plan builder: plan template is required")
}
@@ -352,7 +352,7 @@ func observeAmountForRail(rail model.Rail, source, settlement, payout *paymentty
return source
}
func netSourceAmount(sourceAmount, feeAmount *paymenttypes.Money, quote *orchestratorv1.PaymentQuote) (*paymenttypes.Money, error) {
func netSourceAmount(sourceAmount, feeAmount *paymenttypes.Money, quote *sharedv1.PaymentQuote) (*paymenttypes.Money, error) {
if sourceAmount == nil {
return nil, merrors.InvalidArgument("plan builder: source amount is required")
}
@@ -394,7 +394,7 @@ func netSourceAmount(sourceAmount, feeAmount *paymenttypes.Money, quote *orchest
}, nil
}
func netSettlementAmount(settlementAmount, feeAmount *paymenttypes.Money, quote *orchestratorv1.PaymentQuote) (*paymenttypes.Money, error) {
func netSettlementAmount(settlementAmount, feeAmount *paymenttypes.Money, quote *sharedv1.PaymentQuote) (*paymenttypes.Money, error) {
if settlementAmount == nil {
return nil, merrors.InvalidArgument("plan builder: settlement amount is required")
}