fix for proto migration
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 != "" {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 ""
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user