From 7b53ca6cefba912fe36eb9a9133a0219e32ed0b9 Mon Sep 17 00:00:00 2001 From: Stephan D Date: Wed, 11 Feb 2026 18:15:04 +0100 Subject: [PATCH] fix for proto migration --- api/payments/orchestrator/client/client.go | 62 ++----- api/payments/orchestrator/client/fake.go | 18 +- .../internal/service/execution/export.go | 8 +- .../service/execution/payment_plan_helpers.go | 10 +- .../orchestrator/card_payout_funding.go | 4 +- .../service/orchestrator/card_payout_test.go | 6 +- .../service/orchestrator/command_factory.go | 10 +- .../internal/service/orchestrator/convert.go | 161 +++++++++--------- .../service/orchestrator/convert_card_test.go | 12 +- .../service/orchestrator/execution_compat.go | 4 +- .../service/orchestrator/handlers_commands.go | 11 +- .../service/orchestrator/handlers_events.go | 2 +- .../service/orchestrator/handlers_queries.go | 5 +- .../internal/service/orchestrator/helpers.go | 10 +- .../service/orchestrator/helpers_test.go | 6 +- .../service/orchestrator/internal_helpers.go | 6 +- .../orchestrator/internal_helpers_test.go | 20 +-- .../service/orchestrator/payment_executor.go | 6 +- .../orchestrator/payment_plan_chain.go | 4 +- .../orchestrator/payment_plan_executor.go | 8 +- .../payment_plan_executor_test.go | 12 +- .../orchestrator/payment_plan_ledger.go | 8 +- .../orchestrator/payment_plan_ledger_test.go | 4 +- .../orchestrator/payment_plan_steps.go | 6 +- .../orchestrator/provider_settlement.go | 6 +- .../service/orchestrator/rail_endpoints.go | 4 +- .../internal/service/orchestrator/service.go | 5 +- .../service/orchestrator/service_helpers.go | 18 +- .../orchestrator/service_helpers_test.go | 57 ++++--- .../service/orchestrator/service_test.go | 13 +- .../internal/service/plan_builder/default.go | 4 +- .../service/plan_builder/default_test.go | 10 +- .../internal/service/plan_builder/helpers.go | 10 +- .../internal/service/plan_builder/plans.go | 8 +- .../internal/service/plan_builder/steps.go | 8 +- .../internal/service/plan/builder.go | 4 +- .../internal/service/plan/helpers.go | 8 +- .../service/plan/plan_builder_default.go | 4 +- .../service/plan/plan_builder_plans.go | 8 +- .../service/plan/plan_builder_steps.go | 8 +- .../service/quotation/command_factory.go | 15 +- .../internal/service/quotation/convert.go | 84 ++++----- .../service/quotation/handlers_commands.go | 95 ++++++----- .../internal/service/quotation/helpers.go | 8 +- .../service/quotation/internal_helpers.go | 20 +-- .../service/quotation/payment_plan_factory.go | 8 +- .../service/quotation/plan_builder.go | 4 +- .../quotation/plan_builder_adapters.go | 4 +- .../internal/service/quotation/quote_batch.go | 10 +- .../service/quotation/quote_engine.go | 45 ++--- .../internal/service/quotation/service.go | 6 +- .../service/quotation/service_helpers.go | 21 +-- api/server/go.mod | 11 +- api/server/go.sum | 28 +-- api/server/interface/api/sresponse/payment.go | 13 +- .../internal/server/paymentapiimp/list.go | 13 +- .../internal/server/paymentapiimp/mapper.go | 74 ++++---- .../internal/server/paymentapiimp/pay.go | 7 +- .../internal/server/paymentapiimp/paybatch.go | 5 +- .../internal/server/paymentapiimp/quote.go | 12 +- .../internal/server/paymentapiimp/service.go | 6 +- .../pweb/lib/controllers/multi_quotation.dart | 4 +- 62 files changed, 517 insertions(+), 554 deletions(-) diff --git a/api/payments/orchestrator/client/client.go b/api/payments/orchestrator/client/client.go index eafda8a6..86f67755 100644 --- a/api/payments/orchestrator/client/client.go +++ b/api/payments/orchestrator/client/client.go @@ -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() diff --git a/api/payments/orchestrator/client/fake.go b/api/payments/orchestrator/client/fake.go index b30a3436..8f9fb12d 100644 --- a/api/payments/orchestrator/client/fake.go +++ b/api/payments/orchestrator/client/fake.go @@ -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) diff --git a/api/payments/orchestrator/internal/service/execution/export.go b/api/payments/orchestrator/internal/service/execution/export.go index f842830e..5eeee1b6 100644 --- a/api/payments/orchestrator/internal/service/execution/export.go +++ b/api/payments/orchestrator/internal/service/execution/export.go @@ -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) } diff --git a/api/payments/orchestrator/internal/service/execution/payment_plan_helpers.go b/api/payments/orchestrator/internal/service/execution/payment_plan_helpers.go index a49fd53f..1306b992 100644 --- a/api/payments/orchestrator/internal/service/execution/payment_plan_helpers.go +++ b/api/payments/orchestrator/internal/service/execution/payment_plan_helpers.go @@ -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( diff --git a/api/payments/orchestrator/internal/service/orchestrator/card_payout_funding.go b/api/payments/orchestrator/internal/service/orchestrator/card_payout_funding.go index e558d08e..706e6613 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/card_payout_funding.go +++ b/api/payments/orchestrator/internal/service/orchestrator/card_payout_funding.go @@ -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") } diff --git a/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go b/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go index d438b670..bfbdf623 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/card_payout_test.go @@ -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"}, } diff --git a/api/payments/orchestrator/internal/service/orchestrator/command_factory.go b/api/payments/orchestrator/internal/service/orchestrator/command_factory.go index aa3e0129..aedc0be8 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/command_factory.go +++ b/api/payments/orchestrator/internal/service/orchestrator/command_factory.go @@ -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) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/convert.go b/api/payments/orchestrator/internal/service/orchestrator/convert.go index b01fa470..6aa8ea7d 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/convert.go +++ b/api/payments/orchestrator/internal/service/orchestrator/convert.go @@ -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 } } diff --git a/api/payments/orchestrator/internal/service/orchestrator/convert_card_test.go b/api/payments/orchestrator/internal/service/orchestrator/convert_card_test.go index 928b585b..7d5c1e7c 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/convert_card_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/convert_card_test.go @@ -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) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/execution_compat.go b/api/payments/orchestrator/internal/service/orchestrator/execution_compat.go index d4d77467..c9d312e5 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/execution_compat.go +++ b/api/payments/orchestrator/internal/service/orchestrator/execution_compat.go @@ -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) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go b/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go index 2b07b4c7..36b6f394 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go +++ b/api/payments/orchestrator/internal/service/orchestrator/handlers_commands.go @@ -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, diff --git a/api/payments/orchestrator/internal/service/orchestrator/handlers_events.go b/api/payments/orchestrator/internal/service/orchestrator/handlers_events.go index c4d75792..3513d1d1 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/handlers_events.go +++ b/api/payments/orchestrator/internal/service/orchestrator/handlers_events.go @@ -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" ) diff --git a/api/payments/orchestrator/internal/service/orchestrator/handlers_queries.go b/api/payments/orchestrator/internal/service/orchestrator/handlers_queries.go index 9ae60074..9604a49e 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/handlers_queries.go +++ b/api/payments/orchestrator/internal/service/orchestrator/handlers_queries.go @@ -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)) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/helpers.go b/api/payments/orchestrator/internal/service/orchestrator/helpers.go index 8144b605..da75347f 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/helpers.go +++ b/api/payments/orchestrator/internal/service/orchestrator/helpers.go @@ -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{} } diff --git a/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go b/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go index 1da1f56e..1f86bcff 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/helpers_test.go @@ -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()) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/internal_helpers.go b/api/payments/orchestrator/internal/service/orchestrator/internal_helpers.go index 291602da..062e1f27 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/internal_helpers.go +++ b/api/payments/orchestrator/internal/service/orchestrator/internal_helpers.go @@ -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 { diff --git a/api/payments/orchestrator/internal/service/orchestrator/internal_helpers_test.go b/api/payments/orchestrator/internal/service/orchestrator/internal_helpers_test.go index bee5b7d0..ad9395ef 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/internal_helpers_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/internal_helpers_test.go @@ -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"}, }, }, } diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_executor.go b/api/payments/orchestrator/internal/service/orchestrator/payment_executor.go index 563c67ed..1ef737a4 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_executor.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_executor.go @@ -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 diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_chain.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_chain.go index b495a7c9..c97deb9b 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_chain.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_chain.go @@ -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") } diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor.go index 2eca3e82..671d20c3 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor.go @@ -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 { diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go index ca243ccd..371919b4 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_executor_test.go @@ -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") } diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go index 594cafa5..9cb753c4 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger.go @@ -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") } diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go index 804275da..88525f2a 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_ledger_test.go @@ -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 { diff --git a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go index 1198afe7..ef2a7d4d 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go +++ b/api/payments/orchestrator/internal/service/orchestrator/payment_plan_steps.go @@ -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) { diff --git a/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go b/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go index 96ba0f55..cbebc77d 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go +++ b/api/payments/orchestrator/internal/service/orchestrator/provider_settlement.go @@ -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 diff --git a/api/payments/orchestrator/internal/service/orchestrator/rail_endpoints.go b/api/payments/orchestrator/internal/service/orchestrator/rail_endpoints.go index dfe7e290..b9f5c7bb 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/rail_endpoints.go +++ b/api/payments/orchestrator/internal/service/orchestrator/rail_endpoints.go @@ -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()) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/service.go b/api/payments/orchestrator/internal/service/orchestrator/service.go index ec938347..e7314f6f 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service.go @@ -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) } diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go b/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go index 3ce07583..ed92c95f 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_helpers.go @@ -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) diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go b/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go index 1714f3ed..d5efac9d 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_helpers_test.go @@ -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 "ationv1.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", } diff --git a/api/payments/orchestrator/internal/service/orchestrator/service_test.go b/api/payments/orchestrator/internal/service/orchestrator/service_test.go index 569e7bb7..a80baf65 100644 --- a/api/payments/orchestrator/internal/service/orchestrator/service_test.go +++ b/api/payments/orchestrator/internal/service/orchestrator/service_test.go @@ -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()) } } diff --git a/api/payments/orchestrator/internal/service/plan_builder/default.go b/api/payments/orchestrator/internal/service/plan_builder/default.go index 82626e9b..d47d138d 100644 --- a/api/payments/orchestrator/internal/service/plan_builder/default.go +++ b/api/payments/orchestrator/internal/service/plan_builder/default.go @@ -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") } diff --git a/api/payments/orchestrator/internal/service/plan_builder/default_test.go b/api/payments/orchestrator/internal/service/plan_builder/default_test.go index 4f79641e..6c47772d 100644 --- a/api/payments/orchestrator/internal/service/plan_builder/default_test.go +++ b/api/payments/orchestrator/internal/service/plan_builder/default_test.go @@ -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"}, diff --git a/api/payments/orchestrator/internal/service/plan_builder/helpers.go b/api/payments/orchestrator/internal/service/plan_builder/helpers.go index e4ef8e2d..667d7e1a 100644 --- a/api/payments/orchestrator/internal/service/plan_builder/helpers.go +++ b/api/payments/orchestrator/internal/service/plan_builder/helpers.go @@ -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), diff --git a/api/payments/orchestrator/internal/service/plan_builder/plans.go b/api/payments/orchestrator/internal/service/plan_builder/plans.go index 1747db95..882e82e2 100644 --- a/api/payments/orchestrator/internal/service/plan_builder/plans.go +++ b/api/payments/orchestrator/internal/service/plan_builder/plans.go @@ -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()) } diff --git a/api/payments/orchestrator/internal/service/plan_builder/steps.go b/api/payments/orchestrator/internal/service/plan_builder/steps.go index 980af682..664630dd 100644 --- a/api/payments/orchestrator/internal/service/plan_builder/steps.go +++ b/api/payments/orchestrator/internal/service/plan_builder/steps.go @@ -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") } diff --git a/api/payments/quotation/internal/service/plan/builder.go b/api/payments/quotation/internal/service/plan/builder.go index 53cc429f..a33d086f 100644 --- a/api/payments/quotation/internal/service/plan/builder.go +++ b/api/payments/quotation/internal/service/plan/builder.go @@ -6,7 +6,7 @@ import ( "github.com/shopspring/decimal" "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" ) // RouteStore exposes routing definitions for plan construction. @@ -26,7 +26,7 @@ type GatewayRegistry interface { // Builder constructs ordered payment plans from intents, quotes, and routing policy. type Builder interface { - Build(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) + Build(ctx context.Context, payment *model.Payment, quote *sharedv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) } type SendDirection = sendDirection diff --git a/api/payments/quotation/internal/service/plan/helpers.go b/api/payments/quotation/internal/service/plan/helpers.go index c512fecb..e9a5ccbf 100644 --- a/api/payments/quotation/internal/service/plan/helpers.go +++ b/api/payments/quotation/internal/service/plan/helpers.go @@ -12,7 +12,7 @@ import ( fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" moneyv1 "github.com/tech/sendico/pkg/proto/common/money/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 { @@ -288,12 +288,12 @@ func feeLinesToProto(lines []*paymenttypes.FeeLine) []*feesv1.DerivedPostingLine return result } -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 &orchestratorv1.PaymentQuote{ + return &sharedv1.PaymentQuote{ DebitAmount: protoMoney(payment.LastQuote.DebitAmount), DebitSettlementAmount: protoMoney(payment.LastQuote.DebitSettlementAmount), ExpectedSettlementAmount: protoMoney(payment.LastQuote.ExpectedSettlementAmount), @@ -303,7 +303,7 @@ func executionQuote(payment *model.Payment, quote *orchestratorv1.PaymentQuote) QuoteRef: strings.TrimSpace(payment.LastQuote.QuoteRef), } } - return &orchestratorv1.PaymentQuote{} + return &sharedv1.PaymentQuote{} } func makeMoney(currency string, value decimal.Decimal) *moneyv1.Money { diff --git a/api/payments/quotation/internal/service/plan/plan_builder_default.go b/api/payments/quotation/internal/service/plan/plan_builder_default.go index d857bebb..973ba924 100644 --- a/api/payments/quotation/internal/service/plan/plan_builder_default.go +++ b/api/payments/quotation/internal/service/plan/plan_builder_default.go @@ -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" ) @@ -21,7 +21,7 @@ func newDefaultBuilder(logger mlogger.Logger) *defaultBuilder { } } -func (b *defaultBuilder) Build(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) { +func (b *defaultBuilder) 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") } diff --git a/api/payments/quotation/internal/service/plan/plan_builder_plans.go b/api/payments/quotation/internal/service/plan/plan_builder_plans.go index 6b27caac..c5ebe022 100644 --- a/api/payments/quotation/internal/service/plan/plan_builder_plans.go +++ b/api/payments/quotation/internal/service/plan/plan_builder_plans.go @@ -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()) } diff --git a/api/payments/quotation/internal/service/plan/plan_builder_steps.go b/api/payments/quotation/internal/service/plan/plan_builder_steps.go index df7504ef..ca97624e 100644 --- a/api/payments/quotation/internal/service/plan/plan_builder_steps.go +++ b/api/payments/quotation/internal/service/plan/plan_builder_steps.go @@ -10,11 +10,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 *defaultBuilder) 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 *defaultBuilder) 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") } @@ -353,7 +353,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") } @@ -395,7 +395,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") } diff --git a/api/payments/quotation/internal/service/quotation/command_factory.go b/api/payments/quotation/internal/service/quotation/command_factory.go index 9bb96e29..2a9eef7d 100644 --- a/api/payments/quotation/internal/service/quotation/command_factory.go +++ b/api/payments/quotation/internal/service/quotation/command_factory.go @@ -7,15 +7,16 @@ 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" + 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" ) type paymentEngine interface { EnsureRepository(ctx context.Context) error - BuildPaymentQuote(ctx context.Context, orgRef string, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.PaymentQuote, time.Time, error) - BuildPaymentPlan(ctx context.Context, orgID bson.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, quote *orchestratorv1.PaymentQuote) (*model.PaymentPlan, error) - ResolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*orchestratorv1.PaymentQuote, *orchestratorv1.PaymentIntent, *model.PaymentPlan, error) + BuildPaymentQuote(ctx context.Context, orgRef string, req *quotationv1.QuotePaymentRequest) (*sharedv1.PaymentQuote, time.Time, error) + BuildPaymentPlan(ctx context.Context, orgID bson.ObjectID, intent *sharedv1.PaymentIntent, idempotencyKey string, quote *sharedv1.PaymentQuote) (*model.PaymentPlan, error) + ResolvePaymentQuote(ctx context.Context, in quoteResolutionInput) (*sharedv1.PaymentQuote, *sharedv1.PaymentIntent, *model.PaymentPlan, error) Repository() storage.Repository } @@ -27,15 +28,15 @@ func (e defaultPaymentEngine) EnsureRepository(ctx context.Context) error { return e.svc.ensureRepository(ctx) } -func (e defaultPaymentEngine) BuildPaymentQuote(ctx context.Context, orgRef string, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.PaymentQuote, time.Time, error) { +func (e defaultPaymentEngine) BuildPaymentQuote(ctx context.Context, orgRef string, req *quotationv1.QuotePaymentRequest) (*sharedv1.PaymentQuote, time.Time, error) { return e.svc.buildPaymentQuote(ctx, orgRef, req) } -func (e defaultPaymentEngine) BuildPaymentPlan(ctx context.Context, orgID bson.ObjectID, intent *orchestratorv1.PaymentIntent, idempotencyKey string, quote *orchestratorv1.PaymentQuote) (*model.PaymentPlan, error) { +func (e defaultPaymentEngine) BuildPaymentPlan(ctx context.Context, orgID bson.ObjectID, intent *sharedv1.PaymentIntent, idempotencyKey string, quote *sharedv1.PaymentQuote) (*model.PaymentPlan, error) { return e.svc.buildPaymentPlan(ctx, orgID, intent, idempotencyKey, quote) } -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) } diff --git a/api/payments/quotation/internal/service/quotation/convert.go b/api/payments/quotation/internal/service/quotation/convert.go index e1ab5969..719d5af4 100644 --- a/api/payments/quotation/internal/service/quotation/convert.go +++ b/api/payments/quotation/internal/service/quotation/convert.go @@ -12,10 +12,10 @@ 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 intentFromProto(src *orchestratorv1.PaymentIntent) model.PaymentIntent { +func intentFromProto(src *sharedv1.PaymentIntent) model.PaymentIntent { if src == nil { return model.PaymentIntent{} } @@ -38,7 +38,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} } @@ -89,7 +89,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 } @@ -103,7 +103,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 } @@ -120,8 +120,8 @@ func quoteSnapshotToModel(src *orchestratorv1.PaymentQuote) *model.PaymentQuoteS } } -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), @@ -140,7 +140,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 } @@ -158,11 +158,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), @@ -176,16 +176,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, }, @@ -193,8 +193,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), }, @@ -202,8 +202,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, @@ -212,7 +212,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, @@ -221,12 +221,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 @@ -234,11 +234,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, @@ -248,11 +248,11 @@ func protoFXIntentFromModel(src *model.FXIntent) *orchestratorv1.FXIntent { } } -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), @@ -265,51 +265,51 @@ func modelQuoteToProto(src *model.PaymentQuoteSnapshot) *orchestratorv1.PaymentQ } } -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 } } -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 } } diff --git a/api/payments/quotation/internal/service/quotation/handlers_commands.go b/api/payments/quotation/internal/service/quotation/handlers_commands.go index 00599220..7a1b8fab 100644 --- a/api/payments/quotation/internal/service/quotation/handlers_commands.go +++ b/api/payments/quotation/internal/service/quotation/handlers_commands.go @@ -16,7 +16,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" + 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" "go.uber.org/zap" "google.golang.org/protobuf/proto" @@ -36,7 +37,7 @@ var ( type quoteCtx struct { orgID string orgRef bson.ObjectID - intent *orchestratorv1.PaymentIntent + intent *sharedv1.PaymentIntent previewOnly bool idempotencyKey string hash string @@ -44,14 +45,14 @@ type quoteCtx struct { func (h *quotePaymentCommand) Execute( ctx context.Context, - req *orchestratorv1.QuotePaymentRequest, -) gsresponse.Responder[orchestratorv1.QuotePaymentResponse] { + req *quotationv1.QuotePaymentRequest, +) gsresponse.Responder[quotationv1.QuotePaymentResponse] { if err := h.engine.EnsureRepository(ctx); err != nil { - return gsresponse.Unavailable[orchestratorv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Unavailable[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) } if req == nil { - return gsresponse.InvalidArgument[orchestratorv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, merrors.InvalidArgument("nil request")) + return gsresponse.InvalidArgument[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, merrors.InvalidArgument("nil request")) } qc, err := h.prepareQuoteCtx(req) @@ -61,7 +62,7 @@ func (h *quotePaymentCommand) Execute( quotesStore, err := ensureQuotesStore(h.engine.Repository()) if err != nil { - return gsresponse.Unavailable[orchestratorv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Unavailable[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) } quoteProto, err := h.quotePayment(ctx, quotesStore, qc, req) @@ -69,13 +70,13 @@ func (h *quotePaymentCommand) Execute( return h.mapQuoteErr(err) } - return gsresponse.Success(&orchestratorv1.QuotePaymentResponse{ + return gsresponse.Success("ationv1.QuotePaymentResponse{ IdempotencyKey: req.GetIdempotencyKey(), Quote: quoteProto, }) } -func (h *quotePaymentCommand) prepareQuoteCtx(req *orchestratorv1.QuotePaymentRequest) (*quoteCtx, error) { +func (h *quotePaymentCommand) prepareQuoteCtx(req *quotationv1.QuotePaymentRequest) (*quoteCtx, error) { orgRef, orgID, err := validateMetaAndOrgRef(req.GetMeta()) if err != nil { return nil, err @@ -109,8 +110,8 @@ func (h *quotePaymentCommand) quotePayment( ctx context.Context, quotesStore storage.QuotesStore, qc *quoteCtx, - req *orchestratorv1.QuotePaymentRequest, -) (*orchestratorv1.PaymentQuote, error) { + req *quotationv1.QuotePaymentRequest, +) (*sharedv1.PaymentQuote, error) { if qc.previewOnly { quote, _, err := h.engine.BuildPaymentQuote(ctx, qc.orgID, req) @@ -203,18 +204,18 @@ func (h *quotePaymentCommand) quotePayment( return quote, nil } -func (h *quotePaymentCommand) mapQuoteErr(err error) gsresponse.Responder[orchestratorv1.QuotePaymentResponse] { +func (h *quotePaymentCommand) mapQuoteErr(err error) gsresponse.Responder[quotationv1.QuotePaymentResponse] { if errors.Is(err, errIdempotencyRequired) || errors.Is(err, errPreviewWithIdempotency) || errors.Is(err, errIdempotencyParamMismatch) { - return gsresponse.InvalidArgument[orchestratorv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.InvalidArgument[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) } - return gsresponse.Auto[orchestratorv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentResponse](h.logger, mservice.PaymentOrchestrator, err) } // TODO: temprorarary hashing function, replace with a proper solution later -func hashQuoteRequest(req *orchestratorv1.QuotePaymentRequest) string { - cloned := proto.Clone(req).(*orchestratorv1.QuotePaymentRequest) +func hashQuoteRequest(req *quotationv1.QuotePaymentRequest) string { + cloned := proto.Clone(req).(*quotationv1.QuotePaymentRequest) cloned.Meta = nil cloned.IdempotencyKey = "" cloned.PreviewOnly = false @@ -252,14 +253,14 @@ type quotePaymentsCtx struct { func (h *quotePaymentsCommand) Execute( ctx context.Context, - req *orchestratorv1.QuotePaymentsRequest, -) gsresponse.Responder[orchestratorv1.QuotePaymentsResponse] { + req *quotationv1.QuotePaymentsRequest, +) gsresponse.Responder[quotationv1.QuotePaymentsResponse] { if err := h.engine.EnsureRepository(ctx); err != nil { - return gsresponse.Unavailable[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Unavailable[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } if req == nil { - return gsresponse.InvalidArgument[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, merrors.InvalidArgument("nil request")) + return gsresponse.InvalidArgument[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, merrors.InvalidArgument("nil request")) } qc, intents, err := h.prepare(req) @@ -269,20 +270,20 @@ func (h *quotePaymentsCommand) Execute( quotesStore, err := ensureQuotesStore(h.engine.Repository()) if err != nil { - return gsresponse.Unavailable[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Unavailable[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } if qc.previewOnly { quotes, _, expires, err := h.buildQuotes(ctx, req.GetMeta(), qc.orgRef, qc.idempotencyKey, intents, true) if err != nil { - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } aggregate, expiresAt, err := h.aggregate(quotes, expires) if err != nil { - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } _ = expiresAt - return gsresponse.Success(&orchestratorv1.QuotePaymentsResponse{ + return gsresponse.Success("ationv1.QuotePaymentsResponse{ QuoteRef: "", Aggregate: aggregate, Quotes: quotes, @@ -290,19 +291,19 @@ func (h *quotePaymentsCommand) Execute( } if rec, ok, err := h.tryReuse(ctx, quotesStore, qc); err != nil { - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } else if ok { return gsresponse.Success(h.responseFromRecord(rec)) } quotes, plans, expires, err := h.buildQuotes(ctx, req.GetMeta(), qc.orgRef, qc.idempotencyKey, intents, false) if err != nil { - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } aggregate, expiresAt, err := h.aggregate(quotes, expires) if err != nil { - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } quoteRef := bson.NewObjectID().Hex() @@ -314,7 +315,7 @@ func (h *quotePaymentsCommand) Execute( rec, err := h.storeBatch(ctx, quotesStore, qc, quoteRef, intents, quotes, plans, expiresAt) if err != nil { - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } if rec != nil { @@ -326,7 +327,7 @@ func (h *quotePaymentsCommand) Execute( h.logFields(qc, quoteRef, expiresAt, len(quotes))..., ) - return gsresponse.Success(&orchestratorv1.QuotePaymentsResponse{ + return gsresponse.Success("ationv1.QuotePaymentsResponse{ IdempotencyKey: req.GetIdempotencyKey(), QuoteRef: quoteRef, Aggregate: aggregate, @@ -334,7 +335,7 @@ func (h *quotePaymentsCommand) Execute( }) } -func (h *quotePaymentsCommand) prepare(req *orchestratorv1.QuotePaymentsRequest) (*quotePaymentsCtx, []*orchestratorv1.PaymentIntent, error) { +func (h *quotePaymentsCommand) prepare(req *quotationv1.QuotePaymentsRequest) (*quotePaymentsCtx, []*sharedv1.PaymentIntent, error) { orgRefStr, orgID, err := validateMetaAndOrgRef(req.GetMeta()) if err != nil { return nil, nil, err @@ -410,20 +411,20 @@ func (h *quotePaymentsCommand) tryReuse( func (h *quotePaymentsCommand) buildQuotes( ctx context.Context, - meta *orchestratorv1.RequestMeta, + meta *sharedv1.RequestMeta, orgRef bson.ObjectID, baseKey string, - intents []*orchestratorv1.PaymentIntent, + intents []*sharedv1.PaymentIntent, preview bool, -) ([]*orchestratorv1.PaymentQuote, []*model.PaymentPlan, []time.Time, error) { +) ([]*sharedv1.PaymentQuote, []*model.PaymentPlan, []time.Time, error) { - quotes := make([]*orchestratorv1.PaymentQuote, 0, len(intents)) + quotes := make([]*sharedv1.PaymentQuote, 0, len(intents)) plans := make([]*model.PaymentPlan, 0, len(intents)) expires := make([]time.Time, 0, len(intents)) for i, intent := range intents { perKey := perIntentIdempotencyKey(baseKey, i, len(intents)) - req := &orchestratorv1.QuotePaymentRequest{ + req := "ationv1.QuotePaymentRequest{ Meta: meta, IdempotencyKey: perKey, Intent: intent, @@ -458,9 +459,9 @@ func (h *quotePaymentsCommand) buildQuotes( } func (h *quotePaymentsCommand) aggregate( - quotes []*orchestratorv1.PaymentQuote, + quotes []*sharedv1.PaymentQuote, expires []time.Time, -) (*orchestratorv1.PaymentQuoteAggregate, time.Time, error) { +) (*sharedv1.PaymentQuoteAggregate, time.Time, error) { agg, err := aggregatePaymentQuotes(quotes) if err != nil { @@ -480,8 +481,8 @@ func (h *quotePaymentsCommand) storeBatch( quotesStore storage.QuotesStore, qc *quotePaymentsCtx, quoteRef string, - intents []*orchestratorv1.PaymentIntent, - quotes []*orchestratorv1.PaymentQuote, + intents []*sharedv1.PaymentIntent, + quotes []*sharedv1.PaymentQuote, plans []*model.PaymentPlan, expiresAt time.Time, ) (*model.PaymentQuoteRecord, error) { @@ -515,7 +516,7 @@ func (h *quotePaymentsCommand) storeBatch( return nil, nil } -func (h *quotePaymentsCommand) responseFromRecord(rec *model.PaymentQuoteRecord) *orchestratorv1.QuotePaymentsResponse { +func (h *quotePaymentsCommand) responseFromRecord(rec *model.PaymentQuoteRecord) *quotationv1.QuotePaymentsResponse { quotes := modelQuotesToProto(rec.Quotes) for _, q := range quotes { if q != nil { @@ -524,7 +525,7 @@ func (h *quotePaymentsCommand) responseFromRecord(rec *model.PaymentQuoteRecord) } aggregate, _ := aggregatePaymentQuotes(quotes) - return &orchestratorv1.QuotePaymentsResponse{ + return "ationv1.QuotePaymentsResponse{ QuoteRef: rec.QuoteRef, Aggregate: aggregate, Quotes: quotes, @@ -552,28 +553,28 @@ func (h *quotePaymentsCommand) logFields(qc *quotePaymentsCtx, quoteRef string, return fields } -func (h *quotePaymentsCommand) mapErr(err error) gsresponse.Responder[orchestratorv1.QuotePaymentsResponse] { +func (h *quotePaymentsCommand) mapErr(err error) gsresponse.Responder[quotationv1.QuotePaymentsResponse] { if errors.Is(err, errBatchIdempotencyRequired) || errors.Is(err, errBatchPreviewWithIdempotency) || errors.Is(err, errBatchIdempotencyParamMismatch) || errors.Is(err, errBatchIdempotencyShapeMismatch) { - return gsresponse.InvalidArgument[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.InvalidArgument[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } - return gsresponse.Auto[orchestratorv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) + return gsresponse.Auto[quotationv1.QuotePaymentsResponse](h.logger, mservice.PaymentOrchestrator, err) } -func modelQuotesToProto(snaps []*model.PaymentQuoteSnapshot) []*orchestratorv1.PaymentQuote { +func modelQuotesToProto(snaps []*model.PaymentQuoteSnapshot) []*sharedv1.PaymentQuote { if len(snaps) == 0 { return nil } - out := make([]*orchestratorv1.PaymentQuote, 0, len(snaps)) + out := make([]*sharedv1.PaymentQuote, 0, len(snaps)) for _, s := range snaps { out = append(out, modelQuoteToProto(s)) } return out } -func hashQuotePaymentsIntents(intents []*orchestratorv1.PaymentIntent) (string, error) { +func hashQuotePaymentsIntents(intents []*sharedv1.PaymentIntent) (string, error) { type item struct { Idx int H [32]byte diff --git a/api/payments/quotation/internal/service/quotation/helpers.go b/api/payments/quotation/internal/service/quotation/helpers.go index cae9f5a7..07e86cee 100644 --- a/api/payments/quotation/internal/service/quotation/helpers.go +++ b/api/payments/quotation/internal/service/quotation/helpers.go @@ -8,7 +8,7 @@ import ( oracleclient "github.com/tech/sendico/fx/oracle/client" 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" "google.golang.org/protobuf/proto" feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1" @@ -173,7 +173,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 } @@ -215,7 +215,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: @@ -225,7 +225,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()) diff --git a/api/payments/quotation/internal/service/quotation/internal_helpers.go b/api/payments/quotation/internal/service/quotation/internal_helpers.go index 3e37b356..136611b4 100644 --- a/api/payments/quotation/internal/service/quotation/internal_helpers.go +++ b/api/payments/quotation/internal/service/quotation/internal_helpers.go @@ -9,7 +9,7 @@ import ( "github.com/tech/sendico/pkg/mservice" feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1" fxv1 "github.com/tech/sendico/pkg/proto/common/fx/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 { @@ -33,13 +33,13 @@ func executeUnary[TReq any, TResp any](ctx context.Context, svc *Service, method return resp, err } -func triggerFromKind(kind orchestratorv1.PaymentKind, requiresFX bool) feesv1.Trigger { +func triggerFromKind(kind sharedv1.PaymentKind, requiresFX bool) feesv1.Trigger { switch kind { - case orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT: + case sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT: return feesv1.Trigger_TRIGGER_PAYOUT - case orchestratorv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER: + case sharedv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER: return feesv1.Trigger_TRIGGER_CAPTURE - case orchestratorv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION: + case sharedv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION: return feesv1.Trigger_TRIGGER_FX_CONVERSION default: if requiresFX { @@ -49,7 +49,7 @@ func triggerFromKind(kind orchestratorv1.PaymentKind, requiresFX bool) feesv1.Tr } } -func shouldEstimateNetworkFee(intent *orchestratorv1.PaymentIntent) bool { +func shouldEstimateNetworkFee(intent *sharedv1.PaymentIntent) bool { if intent == nil { return false } @@ -60,7 +60,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 { @@ -69,7 +69,7 @@ func shouldEstimateNetworkFee(intent *orchestratorv1.PaymentIntent) bool { return false } -func shouldRequestFX(intent *orchestratorv1.PaymentIntent) bool { +func shouldRequestFX(intent *sharedv1.PaymentIntent) bool { if intent == nil { return false } @@ -79,7 +79,7 @@ func shouldRequestFX(intent *orchestratorv1.PaymentIntent) bool { return intent.GetRequiresFx() } -func fxIntentForQuote(intent *orchestratorv1.PaymentIntent) *orchestratorv1.FXIntent { +func fxIntentForQuote(intent *sharedv1.PaymentIntent) *sharedv1.FXIntent { if intent == nil { return nil } @@ -97,7 +97,7 @@ func fxIntentForQuote(intent *orchestratorv1.PaymentIntent) *orchestratorv1.FXIn if strings.EqualFold(amount.GetCurrency(), settlementCurrency) { return nil } - return &orchestratorv1.FXIntent{ + return &sharedv1.FXIntent{ Pair: &fxv1.CurrencyPair{ Base: strings.TrimSpace(amount.GetCurrency()), Quote: settlementCurrency, diff --git a/api/payments/quotation/internal/service/quotation/payment_plan_factory.go b/api/payments/quotation/internal/service/quotation/payment_plan_factory.go index 7403a512..c36083d7 100644 --- a/api/payments/quotation/internal/service/quotation/payment_plan_factory.go +++ b/api/payments/quotation/internal/service/quotation/payment_plan_factory.go @@ -8,16 +8,16 @@ 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" "go.mongodb.org/mongo-driver/v2/bson" ) func (s *Service) buildPaymentPlan( ctx context.Context, orgID bson.ObjectID, - intent *orchestratorv1.PaymentIntent, + intent *sharedv1.PaymentIntent, idempotencyKey string, - quote *orchestratorv1.PaymentQuote, + quote *sharedv1.PaymentQuote, ) (*model.PaymentPlan, error) { if s == nil || s.storage == nil { return nil, errStorageUnavailable @@ -42,7 +42,7 @@ func (s *Service) buildPaymentPlan( planQuote := quote if planQuote == nil { - planQuote = &orchestratorv1.PaymentQuote{} + planQuote = &sharedv1.PaymentQuote{} } payment := newPayment(orgID, intent, strings.TrimSpace(idempotencyKey), nil, planQuote) if ref := strings.TrimSpace(planQuote.GetQuoteRef()); ref != "" { diff --git a/api/payments/quotation/internal/service/quotation/plan_builder.go b/api/payments/quotation/internal/service/quotation/plan_builder.go index 3e3a422e..ab4f4671 100644 --- a/api/payments/quotation/internal/service/quotation/plan_builder.go +++ b/api/payments/quotation/internal/service/quotation/plan_builder.go @@ -4,7 +4,7 @@ import ( "context" "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" ) // RouteStore exposes routing definitions for plan construction. @@ -24,5 +24,5 @@ type GatewayRegistry interface { // PlanBuilder constructs ordered payment plans from intents, quotes, and routing policy. type PlanBuilder interface { - Build(ctx context.Context, payment *model.Payment, quote *orchestratorv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) + Build(ctx context.Context, payment *model.Payment, quote *sharedv1.PaymentQuote, routes RouteStore, templates PlanTemplateStore, gateways GatewayRegistry) (*model.PaymentPlan, error) } diff --git a/api/payments/quotation/internal/service/quotation/plan_builder_adapters.go b/api/payments/quotation/internal/service/quotation/plan_builder_adapters.go index 8bfc2a5a..5a0bfc5e 100644 --- a/api/payments/quotation/internal/service/quotation/plan_builder_adapters.go +++ b/api/payments/quotation/internal/service/quotation/plan_builder_adapters.go @@ -6,7 +6,7 @@ import ( "github.com/tech/sendico/payments/quotation/internal/service/plan" "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 defaultPlanBuilder struct { @@ -17,7 +17,7 @@ func newDefaultPlanBuilder(logger mlogger.Logger) PlanBuilder { return &defaultPlanBuilder{inner: plan.NewDefaultBuilder(logger)} } -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) { return b.inner.Build(ctx, payment, quote, routes, templates, gateways) } diff --git a/api/payments/quotation/internal/service/quotation/quote_batch.go b/api/payments/quotation/internal/service/quotation/quote_batch.go index 8eb982ad..e7b2b546 100644 --- a/api/payments/quotation/internal/service/quotation/quote_batch.go +++ b/api/payments/quotation/internal/service/quotation/quote_batch.go @@ -9,7 +9,7 @@ import ( "github.com/shopspring/decimal" "github.com/tech/sendico/payments/storage/model" 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 perIntentIdempotencyKey(base string, index int, total int) string { @@ -39,7 +39,7 @@ func minQuoteExpiry(expires []time.Time) (time.Time, bool) { return min, true } -func aggregatePaymentQuotes(quotes []*orchestratorv1.PaymentQuote) (*orchestratorv1.PaymentQuoteAggregate, error) { +func aggregatePaymentQuotes(quotes []*sharedv1.PaymentQuote) (*sharedv1.PaymentQuoteAggregate, error) { if len(quotes) == 0 { return nil, nil } @@ -68,7 +68,7 @@ func aggregatePaymentQuotes(quotes []*orchestratorv1.PaymentQuote) (*orchestrato } } - return &orchestratorv1.PaymentQuoteAggregate{ + return &sharedv1.PaymentQuoteAggregate{ DebitAmounts: totalsToMoney(debitTotals), ExpectedSettlementAmounts: totalsToMoney(settlementTotals), ExpectedFeeTotals: totalsToMoney(feeTotals), @@ -117,7 +117,7 @@ func totalsToMoney(totals map[string]decimal.Decimal) []*moneyv1.Money { return result } -func intentsFromProto(intents []*orchestratorv1.PaymentIntent) []model.PaymentIntent { +func intentsFromProto(intents []*sharedv1.PaymentIntent) []model.PaymentIntent { if len(intents) == 0 { return nil } @@ -128,7 +128,7 @@ func intentsFromProto(intents []*orchestratorv1.PaymentIntent) []model.PaymentIn return result } -func quoteSnapshotsFromProto(quotes []*orchestratorv1.PaymentQuote) []*model.PaymentQuoteSnapshot { +func quoteSnapshotsFromProto(quotes []*sharedv1.PaymentQuote) []*model.PaymentQuoteSnapshot { if len(quotes) == 0 { return nil } diff --git a/api/payments/quotation/internal/service/quotation/quote_engine.go b/api/payments/quotation/internal/service/quotation/quote_engine.go index 2a140361..b1b80be6 100644 --- a/api/payments/quotation/internal/service/quotation/quote_engine.go +++ b/api/payments/quotation/internal/service/quotation/quote_engine.go @@ -16,12 +16,13 @@ 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" + quotationv1 "github.com/tech/sendico/pkg/proto/payments/quotation/v1" + sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1" "go.uber.org/zap" "google.golang.org/protobuf/types/known/timestamppb" ) -func (s *Service) buildPaymentQuote(ctx context.Context, orgRef string, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.PaymentQuote, time.Time, error) { +func (s *Service) buildPaymentQuote(ctx context.Context, orgRef string, req *quotationv1.QuotePaymentRequest) (*sharedv1.PaymentQuote, time.Time, error) { intent := req.GetIntent() amount := intent.GetAmount() fxSide := fxv1.Side_SIDE_UNSPECIFIED @@ -94,7 +95,7 @@ func (s *Service) buildPaymentQuote(ctx context.Context, orgRef string, req *orc debitAmount, settlementAmount := computeAggregates(payAmount, settlementAmountBeforeFees, feeTotal, networkFee, fxQuote, intent.GetSettlementMode()) - quote := &orchestratorv1.PaymentQuote{ + quote := &sharedv1.PaymentQuote{ DebitAmount: debitAmount, DebitSettlementAmount: payAmount, ExpectedSettlementAmount: settlementAmount, @@ -116,7 +117,7 @@ func (s *Service) buildPaymentQuote(ctx context.Context, orgRef string, req *orc return quote, expiresAt, nil } -func (s *Service) quoteFees(ctx context.Context, orgRef string, req *orchestratorv1.QuotePaymentRequest, baseAmount *moneyv1.Money) (*feesv1.PrecomputeFeesResponse, error) { +func (s *Service) quoteFees(ctx context.Context, orgRef string, req *quotationv1.QuotePaymentRequest, baseAmount *moneyv1.Money) (*feesv1.PrecomputeFeesResponse, error) { if !s.deps.fees.available() { return &feesv1.PrecomputeFeesResponse{}, nil } @@ -152,7 +153,7 @@ func (s *Service) quoteFees(ctx context.Context, orgRef string, req *orchestrato return resp, nil } -func (s *Service) quoteConversionFees(ctx context.Context, orgRef string, req *orchestratorv1.QuotePaymentRequest, baseAmount *moneyv1.Money) (*feesv1.PrecomputeFeesResponse, error) { +func (s *Service) quoteConversionFees(ctx context.Context, orgRef string, req *quotationv1.QuotePaymentRequest, baseAmount *moneyv1.Money) (*feesv1.PrecomputeFeesResponse, error) { if !s.deps.fees.available() { return &feesv1.PrecomputeFeesResponse{}, nil } @@ -196,7 +197,7 @@ func (s *Service) quoteConversionFees(ctx context.Context, orgRef string, req *o return resp, nil } -func (s *Service) shouldQuoteConversionFee(ctx context.Context, intent *orchestratorv1.PaymentIntent) bool { +func (s *Service) shouldQuoteConversionFee(ctx context.Context, intent *sharedv1.PaymentIntent) bool { if intent == nil { return false } @@ -264,7 +265,7 @@ func mergeFeeRules(primary, secondary *feesv1.PrecomputeFeesResponse) []*feesv1. return rules } -func ensureFeeAttributes(intent *orchestratorv1.PaymentIntent, baseAmount *moneyv1.Money, attrs map[string]string) map[string]string { +func ensureFeeAttributes(intent *sharedv1.PaymentIntent, baseAmount *moneyv1.Money, attrs map[string]string) map[string]string { if attrs == nil { attrs = map[string]string{} } @@ -297,7 +298,7 @@ func ensureFeeAttributes(intent *orchestratorv1.PaymentIntent, baseAmount *money return attrs } -func feeTriggerForIntent(intent *orchestratorv1.PaymentIntent) feesv1.Trigger { +func feeTriggerForIntent(intent *sharedv1.PaymentIntent) feesv1.Trigger { if intent == nil { return feesv1.Trigger_TRIGGER_UNSPECIFIED } @@ -308,11 +309,11 @@ func feeTriggerForIntent(intent *orchestratorv1.PaymentIntent) feesv1.Trigger { return trigger } -func isManagedWalletEndpoint(endpoint *orchestratorv1.PaymentEndpoint) bool { +func isManagedWalletEndpoint(endpoint *sharedv1.PaymentEndpoint) bool { return endpoint != nil && endpoint.GetManagedWallet() != nil } -func isLedgerEndpoint(endpoint *orchestratorv1.PaymentEndpoint) bool { +func isLedgerEndpoint(endpoint *sharedv1.PaymentEndpoint) bool { return endpoint != nil && endpoint.GetLedger() != nil } @@ -333,13 +334,13 @@ func setFeeAttributeIfMissing(attrs map[string]string, key, value string) { attrs[key] = value } -func feeOperationFromKind(kind orchestratorv1.PaymentKind) string { +func feeOperationFromKind(kind sharedv1.PaymentKind) string { switch kind { - case orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT: + case sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT: return "payout" - case orchestratorv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER: + case sharedv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER: return "internal_transfer" - case orchestratorv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION: + case sharedv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION: return "fx_conversion" default: return "" @@ -358,7 +359,7 @@ func feeCurrencyFromAmount(baseAmount, intentAmount *moneyv1.Money) string { return "" } -func endpointTypeFromProto(endpoint *orchestratorv1.PaymentEndpoint) string { +func endpointTypeFromProto(endpoint *sharedv1.PaymentEndpoint) string { if endpoint == nil { return "" } @@ -376,7 +377,7 @@ func endpointTypeFromProto(endpoint *orchestratorv1.PaymentEndpoint) string { } } -func assetFromIntent(intent *orchestratorv1.PaymentIntent) *chainv1.Asset { +func assetFromIntent(intent *sharedv1.PaymentIntent) *chainv1.Asset { if intent == nil { return nil } @@ -386,7 +387,7 @@ func assetFromIntent(intent *orchestratorv1.PaymentIntent) *chainv1.Asset { return assetFromEndpoint(intent.GetSource()) } -func assetFromEndpoint(endpoint *orchestratorv1.PaymentEndpoint) *chainv1.Asset { +func assetFromEndpoint(endpoint *sharedv1.PaymentEndpoint) *chainv1.Asset { if endpoint == nil { return nil } @@ -399,7 +400,7 @@ func assetFromEndpoint(endpoint *orchestratorv1.PaymentEndpoint) *chainv1.Asset return nil } -func (s *Service) estimateNetworkFee(ctx context.Context, intent *orchestratorv1.PaymentIntent) (*chainv1.EstimateTransferFeeResponse, error) { +func (s *Service) estimateNetworkFee(ctx context.Context, intent *sharedv1.PaymentIntent) (*chainv1.EstimateTransferFeeResponse, error) { req := &chainv1.EstimateTransferFeeRequest{ Amount: cloneProtoMoney(intent.GetAmount()), } @@ -453,7 +454,7 @@ func (s *Service) estimateNetworkFee(ctx context.Context, intent *orchestratorv1 return resp, nil } -func (s *Service) requestFXQuote(ctx context.Context, orgRef string, req *orchestratorv1.QuotePaymentRequest) (*oraclev1.Quote, error) { +func (s *Service) requestFXQuote(ctx context.Context, orgRef string, req *quotationv1.QuotePaymentRequest) (*oraclev1.Quote, error) { if !s.deps.oracle.available() { if req.GetIntent().GetRequiresFx() { return nil, merrors.Internal("fx_oracle_unavailable") @@ -528,7 +529,7 @@ func feesRequiredForRails(sourceRail, destRail model.Rail) bool { return true } -func (s *Service) feeLedgerAccountForIntent(intent *orchestratorv1.PaymentIntent) string { +func (s *Service) feeLedgerAccountForIntent(intent *sharedv1.PaymentIntent) string { if intent == nil || len(s.deps.feeLedgerAccounts) == 0 { return "" } @@ -540,7 +541,7 @@ func (s *Service) feeLedgerAccountForIntent(intent *orchestratorv1.PaymentIntent return strings.TrimSpace(s.deps.feeLedgerAccounts[key]) } -func (s *Service) assignFeeLedgerAccounts(intent *orchestratorv1.PaymentIntent, lines []*feesv1.DerivedPostingLine) { +func (s *Service) assignFeeLedgerAccounts(intent *sharedv1.PaymentIntent, lines []*feesv1.DerivedPostingLine) { account := s.feeLedgerAccountForIntent(intent) key := s.gatewayKeyFromIntent(intent) @@ -565,7 +566,7 @@ func (s *Service) assignFeeLedgerAccounts(intent *orchestratorv1.PaymentIntent, s.logger.Debug("Applied fee ledger account mapping", zap.String("gateway", key), zap.String("ledger_account", account), zap.Int("lines", missing)) } -func (s *Service) gatewayKeyFromIntent(intent *orchestratorv1.PaymentIntent) string { +func (s *Service) gatewayKeyFromIntent(intent *sharedv1.PaymentIntent) string { if intent == nil { return "" } diff --git a/api/payments/quotation/internal/service/quotation/service.go b/api/payments/quotation/internal/service/quotation/service.go index 18c9233c..418f9aba 100644 --- a/api/payments/quotation/internal/service/quotation/service.go +++ b/api/payments/quotation/internal/service/quotation/service.go @@ -10,7 +10,7 @@ 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" + quotationv1 "github.com/tech/sendico/pkg/proto/payments/quotation/v1" "google.golang.org/grpc" ) @@ -102,13 +102,13 @@ func (s *Service) Register(router routers.GRPC) error { } // QuotePayment aggregates downstream quotes. -func (s *Service) QuotePayment(ctx context.Context, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.QuotePaymentResponse, error) { +func (s *Service) QuotePayment(ctx context.Context, req *quotationv1.QuotePaymentRequest) (*quotationv1.QuotePaymentResponse, error) { s.ensureHandlers() return executeUnary(ctx, s, "QuotePayment", s.h.commands.QuotePayment().Execute, req) } // QuotePayments aggregates downstream quotes for multiple intents. -func (s *Service) QuotePayments(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error) { +func (s *Service) QuotePayments(ctx context.Context, req *quotationv1.QuotePaymentsRequest) (*quotationv1.QuotePaymentsResponse, error) { s.ensureHandlers() return executeUnary(ctx, s, "QuotePayments", s.h.commands.QuotePayments().Execute, req) } diff --git a/api/payments/quotation/internal/service/quotation/service_helpers.go b/api/payments/quotation/internal/service/quotation/service_helpers.go index e7b6c5bc..eefde7fa 100644 --- a/api/payments/quotation/internal/service/quotation/service_helpers.go +++ b/api/payments/quotation/internal/service/quotation/service_helpers.go @@ -8,12 +8,13 @@ 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" + 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") } @@ -28,7 +29,7 @@ func validateMetaAndOrgRef(meta *orchestratorv1.RequestMeta) (string, bson.Objec return orgRef, orgID, nil } -func requireNonNilIntent(intent *orchestratorv1.PaymentIntent) error { +func requireNonNilIntent(intent *sharedv1.PaymentIntent) error { if intent == nil { return merrors.InvalidArgument("intent is required") } @@ -55,8 +56,8 @@ func ensureQuotesStore(repo storage.Repository) (storage.QuotesStore, error) { type quoteResolutionInput struct { OrgRef string OrgID bson.ObjectID - Meta *orchestratorv1.RequestMeta - Intent *orchestratorv1.PaymentIntent + Meta *sharedv1.RequestMeta + Intent *sharedv1.PaymentIntent QuoteRef string IdempotencyKey string } @@ -68,7 +69,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 { @@ -106,7 +107,7 @@ func (s *Service) resolvePaymentQuote(ctx context.Context, in quoteResolutionInp if in.Intent == nil { return nil, nil, nil, merrors.InvalidArgument("intent is required") } - req := &orchestratorv1.QuotePaymentRequest{ + req := "ationv1.QuotePaymentRequest{ Meta: in.Meta, IdempotencyKey: in.IdempotencyKey, Intent: in.Intent, @@ -123,7 +124,7 @@ func (s *Service) resolvePaymentQuote(ctx context.Context, in quoteResolutionInp return quote, in.Intent, plan, nil } -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") } @@ -139,7 +140,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") } @@ -171,7 +172,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) diff --git a/api/server/go.mod b/api/server/go.mod index e3b55754..5e52e34f 100644 --- a/api/server/go.mod +++ b/api/server/go.mod @@ -85,7 +85,6 @@ require ( github.com/go-ole/go-ole v1.3.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect github.com/klauspost/compress v1.18.4 // indirect github.com/lestrrat-go/blackmagic v1.0.4 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect @@ -130,10 +129,12 @@ require ( github.com/yusufpapurcu/wmi v1.2.4 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect - go.opentelemetry.io/otel v1.39.0 // indirect - go.opentelemetry.io/otel/metric v1.39.0 // indirect - go.opentelemetry.io/otel/sdk v1.39.0 // indirect - go.opentelemetry.io/otel/trace v1.39.0 // indirect + go.opentelemetry.io/otel v1.40.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect + go.opentelemetry.io/otel/metric v1.40.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.40.0 // indirect + go.opentelemetry.io/otel/trace v1.40.0 // indirect + go.opentelemetry.io/proto/otlp v1.9.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect golang.org/x/crypto v0.48.0 // indirect diff --git a/api/server/go.sum b/api/server/go.sum index bbed8aa0..79826cbb 100644 --- a/api/server/go.sum +++ b/api/server/go.sum @@ -169,8 +169,8 @@ github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= -github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= -github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -258,20 +258,20 @@ go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 h1:UP6IpuHFkUgOQL9FFQFrZ+5LiwhhYRbi7VZSIx6Nj5s= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0/go.mod h1:qxuZLtbq5QDtdeSHsS7bcf6EH6uO6jUAgk764zd3rhM= -go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48= -go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 h1:f0cb2XPmrqn4XMy9PNliTgRKJgS5WcL/u0/WRYGz4t0= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0/go.mod h1:vnakAaFckOMiMtOIhFI2MNH4FYrZzXCYxmb1LlhoGz8= +go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms= +go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 h1:QKdN8ly8zEMrByybbQgv8cWBcdAarwmIPZ6FThrWXJs= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0/go.mod h1:bTdK1nhqF76qiPoCCdyFIV+N/sRHYXYCTQc+3VCi3MI= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 h1:IeMeyr1aBvBiPVYihXIaeIZba6b8E1bYp7lbdxK8CQg= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0/go.mod h1:oVdCUtjq9MK9BlS7TtucsQwUcXcymNiEDjgDD2jMtZU= -go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0= -go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs= -go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18= -go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE= -go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8= -go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew= -go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI= -go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA= +go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g= +go.opentelemetry.io/otel/metric v1.40.0/go.mod h1:ib/crwQH7N3r5kfiBZQbwrTge743UDc7DTFVZrrXnqc= +go.opentelemetry.io/otel/sdk v1.40.0 h1:KHW/jUzgo6wsPh9At46+h4upjtccTmuZCFAc9OJ71f8= +go.opentelemetry.io/otel/sdk v1.40.0/go.mod h1:Ph7EFdYvxq72Y8Li9q8KebuYUr2KoeyHx0DRMKrYBUE= +go.opentelemetry.io/otel/sdk/metric v1.40.0 h1:mtmdVqgQkeRxHgRv4qhyJduP3fYJRMX4AtAlbuWdCYw= +go.opentelemetry.io/otel/sdk/metric v1.40.0/go.mod h1:4Z2bGMf0KSK3uRjlczMOeMhKU2rhUqdWNoKcYrtcBPg= +go.opentelemetry.io/otel/trace v1.40.0 h1:WA4etStDttCSYuhwvEa8OP8I5EWu24lkOzp+ZYblVjw= +go.opentelemetry.io/otel/trace v1.40.0/go.mod h1:zeAhriXecNGP/s2SEG3+Y8X9ujcJOTqQ5RgdEJcawiA= go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A= go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= diff --git a/api/server/interface/api/sresponse/payment.go b/api/server/interface/api/sresponse/payment.go index 8afd8d47..c545150f 100644 --- a/api/server/interface/api/sresponse/payment.go +++ b/api/server/interface/api/sresponse/payment.go @@ -10,7 +10,8 @@ import ( feesv1 "github.com/tech/sendico/pkg/proto/billing/fees/v1" paginationv1 "github.com/tech/sendico/pkg/proto/common/pagination/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" ) type FeeLine struct { @@ -92,7 +93,7 @@ type paymentResponse struct { } // PaymentQuote wraps a payment quote with refreshed access token. -func PaymentQuoteResponse(logger mlogger.Logger, idempotencyKey string, quote *orchestratorv1.PaymentQuote, token *TokenData) http.HandlerFunc { +func PaymentQuoteResponse(logger mlogger.Logger, idempotencyKey string, quote *sharedv1.PaymentQuote, token *TokenData) http.HandlerFunc { return response.Ok(logger, paymentQuoteResponse{ Quote: toPaymentQuote(quote), IdempotencyKey: idempotencyKey, @@ -101,7 +102,7 @@ func PaymentQuoteResponse(logger mlogger.Logger, idempotencyKey string, quote *o } // PaymentQuotes wraps batch quotes with refreshed access token. -func PaymentQuotesResponse(logger mlogger.Logger, resp *orchestratorv1.QuotePaymentsResponse, token *TokenData) http.HandlerFunc { +func PaymentQuotesResponse(logger mlogger.Logger, resp *quotationv1.QuotePaymentsResponse, token *TokenData) http.HandlerFunc { return response.Ok(logger, paymentQuotesResponse{ Quote: toPaymentQuotes(resp), authResponse: authResponse{AccessToken: *token}, @@ -182,7 +183,7 @@ func toFxQuote(q *oraclev1.Quote) *FxQuote { } } -func toPaymentQuote(q *orchestratorv1.PaymentQuote) *PaymentQuote { +func toPaymentQuote(q *sharedv1.PaymentQuote) *PaymentQuote { if q == nil { return nil } @@ -197,7 +198,7 @@ func toPaymentQuote(q *orchestratorv1.PaymentQuote) *PaymentQuote { } } -func toPaymentQuoteAggregate(q *orchestratorv1.PaymentQuoteAggregate) *PaymentQuoteAggregate { +func toPaymentQuoteAggregate(q *sharedv1.PaymentQuoteAggregate) *PaymentQuoteAggregate { if q == nil { return nil } @@ -208,7 +209,7 @@ func toPaymentQuoteAggregate(q *orchestratorv1.PaymentQuoteAggregate) *PaymentQu } } -func toPaymentQuotes(resp *orchestratorv1.QuotePaymentsResponse) *PaymentQuotes { +func toPaymentQuotes(resp *quotationv1.QuotePaymentsResponse) *PaymentQuotes { if resp == nil { return nil } diff --git a/api/server/internal/server/paymentapiimp/list.go b/api/server/internal/server/paymentapiimp/list.go index 5715946f..d31e6b71 100644 --- a/api/server/internal/server/paymentapiimp/list.go +++ b/api/server/internal/server/paymentapiimp/list.go @@ -10,7 +10,8 @@ import ( "github.com/tech/sendico/pkg/model" "github.com/tech/sendico/pkg/mutil/mzap" 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" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" "go.mongodb.org/mongo-driver/v2/bson" @@ -105,7 +106,7 @@ func listPaymentsPage(r *http.Request) (*paginationv1.CursorPageRequest, error) return page, nil } -func parsePaymentStateFilters(r *http.Request) ([]orchestratorv1.PaymentState, error) { +func parsePaymentStateFilters(r *http.Request) ([]sharedv1.PaymentState, error) { query := r.URL.Query() values := append([]string{}, query["state"]...) values = append(values, query["states"]...) @@ -114,7 +115,7 @@ func parsePaymentStateFilters(r *http.Request) ([]orchestratorv1.PaymentState, e return nil, nil } - states := make([]orchestratorv1.PaymentState, 0, len(values)) + states := make([]sharedv1.PaymentState, 0, len(values)) for _, raw := range values { for _, part := range strings.Split(raw, ",") { trimmed := strings.TrimSpace(part) @@ -135,7 +136,7 @@ func parsePaymentStateFilters(r *http.Request) ([]orchestratorv1.PaymentState, e return states, nil } -func paymentStateFromString(value string) (orchestratorv1.PaymentState, bool) { +func paymentStateFromString(value string) (sharedv1.PaymentState, bool) { upper := strings.ToUpper(strings.TrimSpace(value)) if upper == "" { return 0, false @@ -143,9 +144,9 @@ func paymentStateFromString(value string) (orchestratorv1.PaymentState, bool) { if !strings.HasPrefix(upper, "PAYMENT_STATE_") { upper = "PAYMENT_STATE_" + upper } - enumValue, ok := orchestratorv1.PaymentState_value[upper] + enumValue, ok := sharedv1.PaymentState_value[upper] if !ok { return 0, false } - return orchestratorv1.PaymentState(enumValue), true + return sharedv1.PaymentState(enumValue), true } diff --git a/api/server/internal/server/paymentapiimp/mapper.go b/api/server/internal/server/paymentapiimp/mapper.go index 16a17513..41d27388 100644 --- a/api/server/internal/server/paymentapiimp/mapper.go +++ b/api/server/internal/server/paymentapiimp/mapper.go @@ -9,11 +9,11 @@ import ( fxv1 "github.com/tech/sendico/pkg/proto/common/fx/v1" 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" "github.com/tech/sendico/server/interface/api/srequest" ) -func mapPaymentIntent(intent *srequest.PaymentIntent) (*orchestratorv1.PaymentIntent, error) { +func mapPaymentIntent(intent *srequest.PaymentIntent) (*sharedv1.PaymentIntent, error) { if intent == nil { return nil, merrors.InvalidArgument("intent is required") } @@ -46,7 +46,7 @@ func mapPaymentIntent(intent *srequest.PaymentIntent) (*orchestratorv1.PaymentIn return nil, err } - return &orchestratorv1.PaymentIntent{ + return &sharedv1.PaymentIntent{ Ref: uuid.New().String(), Kind: kind, Source: source, @@ -108,19 +108,19 @@ func resolveSettlementCurrency(intent *srequest.PaymentIntent) string { return "" } -func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestratorv1.PaymentEndpoint, error) { +func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*sharedv1.PaymentEndpoint, error) { if endpoint == nil { return nil, nil } - var result orchestratorv1.PaymentEndpoint + var result sharedv1.PaymentEndpoint switch endpoint.Type { case srequest.EndpointTypeLedger: payload, err := endpoint.DecodeLedger() if err != nil { return nil, merrors.InvalidArgument(field + " endpoint: " + err.Error()) } - result.Endpoint = &orchestratorv1.PaymentEndpoint_Ledger{ + result.Endpoint = &sharedv1.PaymentEndpoint_Ledger{ Ledger: mapLedgerEndpoint(&payload), } case srequest.EndpointTypeManagedWallet: @@ -132,7 +132,7 @@ func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestrato if err != nil { return nil, merrors.InvalidArgument(field + " endpoint: " + err.Error()) } - result.Endpoint = &orchestratorv1.PaymentEndpoint_ManagedWallet{ + result.Endpoint = &sharedv1.PaymentEndpoint_ManagedWallet{ ManagedWallet: mw, } case srequest.EndpointTypeExternalChain: @@ -144,7 +144,7 @@ func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestrato if err != nil { return nil, merrors.InvalidArgument(field + " endpoint: " + err.Error()) } - result.Endpoint = &orchestratorv1.PaymentEndpoint_ExternalChain{ + result.Endpoint = &sharedv1.PaymentEndpoint_ExternalChain{ ExternalChain: ext, } case srequest.EndpointTypeCard: @@ -152,7 +152,7 @@ func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestrato if err != nil { return nil, merrors.InvalidArgument(field + " endpoint: " + err.Error()) } - result.Endpoint = &orchestratorv1.PaymentEndpoint_Card{ + result.Endpoint = &sharedv1.PaymentEndpoint_Card{ Card: mapCardEndpoint(&payload), } case srequest.EndpointTypeCardToken: @@ -160,7 +160,7 @@ func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestrato if err != nil { return nil, merrors.InvalidArgument(field + " endpoint: " + err.Error()) } - result.Endpoint = &orchestratorv1.PaymentEndpoint_Card{ + result.Endpoint = &sharedv1.PaymentEndpoint_Card{ Card: mapCardTokenEndpoint(&payload), } case "": @@ -173,17 +173,17 @@ func mapPaymentEndpoint(endpoint *srequest.Endpoint, field string) (*orchestrato return &result, nil } -func mapLedgerEndpoint(endpoint *srequest.LedgerEndpoint) *orchestratorv1.LedgerEndpoint { +func mapLedgerEndpoint(endpoint *srequest.LedgerEndpoint) *sharedv1.LedgerEndpoint { if endpoint == nil { return nil } - return &orchestratorv1.LedgerEndpoint{ + return &sharedv1.LedgerEndpoint{ LedgerAccountRef: endpoint.LedgerAccountRef, ContraLedgerAccountRef: endpoint.ContraLedgerAccountRef, } } -func mapManagedWalletEndpoint(endpoint *srequest.ManagedWalletEndpoint) (*orchestratorv1.ManagedWalletEndpoint, error) { +func mapManagedWalletEndpoint(endpoint *srequest.ManagedWalletEndpoint) (*sharedv1.ManagedWalletEndpoint, error) { if endpoint == nil { return nil, nil } @@ -191,13 +191,13 @@ func mapManagedWalletEndpoint(endpoint *srequest.ManagedWalletEndpoint) (*orches if err != nil { return nil, err } - return &orchestratorv1.ManagedWalletEndpoint{ + return &sharedv1.ManagedWalletEndpoint{ ManagedWalletRef: endpoint.ManagedWalletRef, Asset: asset, }, nil } -func mapExternalChainEndpoint(endpoint *srequest.ExternalChainEndpoint) (*orchestratorv1.ExternalChainEndpoint, error) { +func mapExternalChainEndpoint(endpoint *srequest.ExternalChainEndpoint) (*sharedv1.ExternalChainEndpoint, error) { if endpoint == nil { return nil, nil } @@ -205,7 +205,7 @@ func mapExternalChainEndpoint(endpoint *srequest.ExternalChainEndpoint) (*orches if err != nil { return nil, err } - return &orchestratorv1.ExternalChainEndpoint{ + return &sharedv1.ExternalChainEndpoint{ Asset: asset, Address: endpoint.Address, Memo: endpoint.Memo, @@ -237,7 +237,7 @@ func mapMoney(m *paymenttypes.Money) *moneyv1.Money { } } -func mapFXIntent(fx *srequest.FXIntent) (*orchestratorv1.FXIntent, error) { +func mapFXIntent(fx *srequest.FXIntent) (*sharedv1.FXIntent, error) { if fx == nil { return nil, nil } @@ -245,7 +245,7 @@ func mapFXIntent(fx *srequest.FXIntent) (*orchestratorv1.FXIntent, error) { if err != nil { return nil, err } - return &orchestratorv1.FXIntent{ + return &sharedv1.FXIntent{ Pair: mapCurrencyPair(fx.Pair), Side: side, Firm: fx.Firm, @@ -255,11 +255,11 @@ func mapFXIntent(fx *srequest.FXIntent) (*orchestratorv1.FXIntent, error) { }, nil } -func mapCustomer(customer *srequest.Customer) *orchestratorv1.Customer { +func mapCustomer(customer *srequest.Customer) *sharedv1.Customer { if customer == nil { return nil } - return &orchestratorv1.Customer{ + return &sharedv1.Customer{ Id: strings.TrimSpace(customer.ID), FirstName: strings.TrimSpace(customer.FirstName), MiddleName: strings.TrimSpace(customer.MiddleName), @@ -283,11 +283,11 @@ func mapCurrencyPair(pair *srequest.CurrencyPair) *fxv1.CurrencyPair { } } -func mapCardEndpoint(card *srequest.CardEndpoint) *orchestratorv1.CardEndpoint { +func mapCardEndpoint(card *srequest.CardEndpoint) *sharedv1.CardEndpoint { if card == nil { return nil } - result := &orchestratorv1.CardEndpoint{ + result := &sharedv1.CardEndpoint{ CardholderName: strings.TrimSpace(card.FirstName), CardholderSurname: strings.TrimSpace(card.LastName), ExpMonth: card.ExpMonth, @@ -295,46 +295,46 @@ func mapCardEndpoint(card *srequest.CardEndpoint) *orchestratorv1.CardEndpoint { Country: strings.TrimSpace(card.Country), } if pan := strings.TrimSpace(card.Pan); pan != "" { - result.Card = &orchestratorv1.CardEndpoint_Pan{Pan: pan} + result.Card = &sharedv1.CardEndpoint_Pan{Pan: pan} } return result } -func mapCardTokenEndpoint(card *srequest.CardTokenEndpoint) *orchestratorv1.CardEndpoint { +func mapCardTokenEndpoint(card *srequest.CardTokenEndpoint) *sharedv1.CardEndpoint { if card == nil { return nil } - return &orchestratorv1.CardEndpoint{ - Card: &orchestratorv1.CardEndpoint_Token{Token: strings.TrimSpace(card.Token)}, + return &sharedv1.CardEndpoint{ + Card: &sharedv1.CardEndpoint_Token{Token: strings.TrimSpace(card.Token)}, MaskedPan: strings.TrimSpace(card.MaskedPan), } } -func mapPaymentKind(kind srequest.PaymentKind) (orchestratorv1.PaymentKind, error) { +func mapPaymentKind(kind srequest.PaymentKind) (sharedv1.PaymentKind, error) { switch strings.TrimSpace(string(kind)) { case "", string(srequest.PaymentKindUnspecified): - return orchestratorv1.PaymentKind_PAYMENT_KIND_UNSPECIFIED, nil + return sharedv1.PaymentKind_PAYMENT_KIND_UNSPECIFIED, nil case string(srequest.PaymentKindPayout): - return orchestratorv1.PaymentKind_PAYMENT_KIND_PAYOUT, nil + return sharedv1.PaymentKind_PAYMENT_KIND_PAYOUT, nil case string(srequest.PaymentKindInternalTransfer): - return orchestratorv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER, nil + return sharedv1.PaymentKind_PAYMENT_KIND_INTERNAL_TRANSFER, nil case string(srequest.PaymentKindFxConversion): - return orchestratorv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION, nil + return sharedv1.PaymentKind_PAYMENT_KIND_FX_CONVERSION, nil default: - return orchestratorv1.PaymentKind_PAYMENT_KIND_UNSPECIFIED, merrors.InvalidArgument("unsupported payment kind: " + string(kind)) + return sharedv1.PaymentKind_PAYMENT_KIND_UNSPECIFIED, merrors.InvalidArgument("unsupported payment kind: " + string(kind)) } } -func mapSettlementMode(mode srequest.SettlementMode) (orchestratorv1.SettlementMode, error) { +func mapSettlementMode(mode srequest.SettlementMode) (sharedv1.SettlementMode, error) { switch strings.TrimSpace(string(mode)) { case "", string(srequest.SettlementModeUnspecified): - return orchestratorv1.SettlementMode_SETTLEMENT_UNSPECIFIED, nil + return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED, nil case string(srequest.SettlementModeFixSource): - return orchestratorv1.SettlementMode_SETTLEMENT_FIX_SOURCE, nil + return sharedv1.SettlementMode_SETTLEMENT_FIX_SOURCE, nil case string(srequest.SettlementModeFixReceived): - return orchestratorv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, nil + return sharedv1.SettlementMode_SETTLEMENT_FIX_RECEIVED, nil default: - return orchestratorv1.SettlementMode_SETTLEMENT_UNSPECIFIED, merrors.InvalidArgument("unsupported settlement mode: " + string(mode)) + return sharedv1.SettlementMode_SETTLEMENT_UNSPECIFIED, merrors.InvalidArgument("unsupported settlement mode: " + string(mode)) } } diff --git a/api/server/internal/server/paymentapiimp/pay.go b/api/server/internal/server/paymentapiimp/pay.go index 71fa2b96..e9c15532 100644 --- a/api/server/internal/server/paymentapiimp/pay.go +++ b/api/server/internal/server/paymentapiimp/pay.go @@ -9,7 +9,8 @@ import ( "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" "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" "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" @@ -57,7 +58,7 @@ func (a *PaymentAPI) initiatePayment(r *http.Request, account *model.Account, to } } - var intent *orchestratorv1.PaymentIntent + var intent *sharedv1.PaymentIntent if payload.Intent != nil { applyCustomerIP(payload.Intent, r.RemoteAddr) intent, err = mapPaymentIntent(payload.Intent) @@ -67,7 +68,7 @@ func (a *PaymentAPI) initiatePayment(r *http.Request, account *model.Account, to } req := &orchestratorv1.InitiatePaymentRequest{ - Meta: &orchestratorv1.RequestMeta{ + Meta: &sharedv1.RequestMeta{ OrganizationRef: orgRef.Hex(), }, IdempotencyKey: strings.TrimSpace(payload.IdempotencyKey), diff --git a/api/server/internal/server/paymentapiimp/paybatch.go b/api/server/internal/server/paymentapiimp/paybatch.go index ac1f5962..eeb36b80 100644 --- a/api/server/internal/server/paymentapiimp/paybatch.go +++ b/api/server/internal/server/paymentapiimp/paybatch.go @@ -8,7 +8,8 @@ import ( "github.com/tech/sendico/pkg/api/http/response" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - 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" "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" @@ -40,7 +41,7 @@ func (a *PaymentAPI) initiatePaymentsByQuote(r *http.Request, account *model.Acc } req := &orchestratorv1.InitiatePaymentsRequest{ - Meta: &orchestratorv1.RequestMeta{ + Meta: &sharedv1.RequestMeta{ OrganizationRef: orgRef.Hex(), }, IdempotencyKey: strings.TrimSpace(payload.IdempotencyKey), diff --git a/api/server/internal/server/paymentapiimp/quote.go b/api/server/internal/server/paymentapiimp/quote.go index 6090da4d..88e196b7 100644 --- a/api/server/internal/server/paymentapiimp/quote.go +++ b/api/server/internal/server/paymentapiimp/quote.go @@ -8,7 +8,7 @@ import ( "github.com/tech/sendico/pkg/api/http/response" "github.com/tech/sendico/pkg/merrors" "github.com/tech/sendico/pkg/model" - orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" + sharedv1 "github.com/tech/sendico/pkg/proto/payments/shared/v1" "github.com/tech/sendico/server/interface/api/srequest" "github.com/tech/sendico/server/interface/api/sresponse" mutil "github.com/tech/sendico/server/internal/mutil/param" @@ -51,8 +51,8 @@ func (a *PaymentAPI) quotePayment(r *http.Request, account *model.Account, token return response.BadPayload(a.logger, a.Name(), err) } - req := &orchestratorv1.QuotePaymentRequest{ - Meta: &orchestratorv1.RequestMeta{ + req := "ationv1.QuotePaymentRequest{ + Meta: &sharedv1.RequestMeta{ OrganizationRef: orgRef.Hex(), }, IdempotencyKey: payload.IdempotencyKey, @@ -96,7 +96,7 @@ func (a *PaymentAPI) quotePayments(r *http.Request, account *model.Account, toke return response.Auto(a.logger, a.Name(), err) } - intents := make([]*orchestratorv1.PaymentIntent, 0, len(payload.Intents)) + intents := make([]*sharedv1.PaymentIntent, 0, len(payload.Intents)) for i := range payload.Intents { applyCustomerIP(&payload.Intents[i], r.RemoteAddr) intent, err := mapPaymentIntent(&payload.Intents[i]) @@ -107,8 +107,8 @@ func (a *PaymentAPI) quotePayments(r *http.Request, account *model.Account, toke intents = append(intents, intent) } - req := &orchestratorv1.QuotePaymentsRequest{ - Meta: &orchestratorv1.RequestMeta{ + req := "ationv1.QuotePaymentResponse{ + Meta: &sharedv1.RequestMeta{ OrganizationRef: orgRef.Hex(), }, IdempotencyKey: payload.IdempotencyKey, diff --git a/api/server/internal/server/paymentapiimp/service.go b/api/server/internal/server/paymentapiimp/service.go index de32fc7a..b87c9344 100644 --- a/api/server/internal/server/paymentapiimp/service.go +++ b/api/server/internal/server/paymentapiimp/service.go @@ -17,7 +17,7 @@ import ( msgconsumer "github.com/tech/sendico/pkg/messaging/consumer" "github.com/tech/sendico/pkg/mlogger" "github.com/tech/sendico/pkg/mservice" - orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestrator/v1" + orchestratorv1 "github.com/tech/sendico/pkg/proto/payments/orchestration/v1" eapi "github.com/tech/sendico/server/interface/api" mutil "github.com/tech/sendico/server/internal/mutil/param" "go.mongodb.org/mongo-driver/v2/bson" @@ -25,8 +25,8 @@ import ( ) type paymentClient interface { - QuotePayment(ctx context.Context, req *orchestratorv1.QuotePaymentRequest) (*orchestratorv1.QuotePaymentResponse, error) - QuotePayments(ctx context.Context, req *orchestratorv1.QuotePaymentsRequest) (*orchestratorv1.QuotePaymentsResponse, error) + QuotePayment(ctx context.Context, req *quotationv1.QuotePaymentRequest) (*quotationv1.QuotePaymentResponse, error) + QuotePayments(ctx context.Context, req *quotationv1.QuotePaymentRequest) (*quotationv1.QuotePaymentsResponse, error) InitiatePayments(ctx context.Context, req *orchestratorv1.InitiatePaymentsRequest) (*orchestratorv1.InitiatePaymentsResponse, error) InitiatePayment(ctx context.Context, req *orchestratorv1.InitiatePaymentRequest) (*orchestratorv1.InitiatePaymentResponse, error) ListPayments(ctx context.Context, req *orchestratorv1.ListPaymentsRequest) (*orchestratorv1.ListPaymentsResponse, error) diff --git a/frontend/pweb/lib/controllers/multi_quotation.dart b/frontend/pweb/lib/controllers/multi_quotation.dart index ec37b242..de1911d8 100644 --- a/frontend/pweb/lib/controllers/multi_quotation.dart +++ b/frontend/pweb/lib/controllers/multi_quotation.dart @@ -44,9 +44,7 @@ class MultiQuotationController extends ChangeNotifier { } final expiresAt = quoteExpiresAt; - final scheduledAt = expiresAt == null - ? null - : expiresAt.subtract(_autoRefreshLead); + final scheduledAt = expiresAt?.subtract(_autoRefreshLead); _autoRefreshController.setEnabled(true); _autoRefreshController.sync(