Fully separated payment quotation and orchestration flows
This commit is contained in:
70
api/payments/quotation/internal/service/plan/builder.go
Normal file
70
api/payments/quotation/internal/service/plan/builder.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package plan
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
// RouteStore exposes routing definitions for plan construction.
|
||||
type RouteStore interface {
|
||||
List(ctx context.Context, filter *model.PaymentRouteFilter) (*model.PaymentRouteList, error)
|
||||
}
|
||||
|
||||
// PlanTemplateStore exposes plan templates for plan construction.
|
||||
type PlanTemplateStore interface {
|
||||
List(ctx context.Context, filter *model.PaymentPlanTemplateFilter) (*model.PaymentPlanTemplateList, error)
|
||||
}
|
||||
|
||||
// GatewayRegistry exposes gateway instances for capability-based selection.
|
||||
type GatewayRegistry interface {
|
||||
List(ctx context.Context) ([]*model.GatewayInstanceDescriptor, error)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
type SendDirection = sendDirection
|
||||
|
||||
const (
|
||||
SendDirectionAny SendDirection = sendDirectionAny
|
||||
SendDirectionOut SendDirection = sendDirectionOut
|
||||
SendDirectionIn SendDirection = sendDirectionIn
|
||||
)
|
||||
|
||||
func NewDefaultBuilder(logger mlogger.Logger) Builder {
|
||||
return newDefaultBuilder(logger)
|
||||
}
|
||||
|
||||
func RailFromEndpoint(endpoint model.PaymentEndpoint, attrs map[string]string, isSource bool) (model.Rail, string, error) {
|
||||
return railFromEndpoint(endpoint, attrs, isSource)
|
||||
}
|
||||
|
||||
func ResolveRouteNetwork(attrs map[string]string, sourceNetwork, destNetwork string) (string, error) {
|
||||
return resolveRouteNetwork(attrs, sourceNetwork, destNetwork)
|
||||
}
|
||||
|
||||
func SelectTemplate(ctx context.Context, logger mlogger.Logger, templates PlanTemplateStore, sourceRail, destRail model.Rail, network string) (*model.PaymentPlanTemplate, error) {
|
||||
return selectPlanTemplate(ctx, logger, templates, sourceRail, destRail, network)
|
||||
}
|
||||
|
||||
func SendDirectionForRail(rail model.Rail) SendDirection {
|
||||
return sendDirectionForRail(rail)
|
||||
}
|
||||
|
||||
func IsGatewayEligible(gw *model.GatewayInstanceDescriptor, rail model.Rail, network, currency string, action model.RailOperation, dir SendDirection, amount decimal.Decimal) error {
|
||||
return isGatewayEligible(gw, rail, network, currency, action, sendDirection(dir), amount)
|
||||
}
|
||||
|
||||
func ParseRailValue(value string) model.Rail {
|
||||
return parseRailValue(value)
|
||||
}
|
||||
|
||||
func NetworkFromEndpoint(endpoint model.PaymentEndpoint) string {
|
||||
return networkFromEndpoint(endpoint)
|
||||
}
|
||||
Reference in New Issue
Block a user