72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package quotation
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/tech/sendico/payments/storage"
|
|
"github.com/tech/sendico/payments/storage/model"
|
|
"github.com/tech/sendico/pkg/mlogger"
|
|
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 *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
|
|
}
|
|
|
|
type defaultPaymentEngine struct {
|
|
svc *Service
|
|
}
|
|
|
|
func (e defaultPaymentEngine) EnsureRepository(ctx context.Context) error {
|
|
return e.svc.ensureRepository(ctx)
|
|
}
|
|
|
|
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 *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) (*sharedv1.PaymentQuote, *sharedv1.PaymentIntent, *model.PaymentPlan, error) {
|
|
return e.svc.resolvePaymentQuote(ctx, in)
|
|
}
|
|
|
|
func (e defaultPaymentEngine) Repository() storage.Repository {
|
|
return e.svc.storage
|
|
}
|
|
|
|
type paymentCommandFactory struct {
|
|
engine paymentEngine
|
|
logger mlogger.Logger
|
|
}
|
|
|
|
func newPaymentCommandFactory(engine paymentEngine, logger mlogger.Logger) *paymentCommandFactory {
|
|
return &paymentCommandFactory{
|
|
engine: engine,
|
|
logger: logger.Named("commands"),
|
|
}
|
|
}
|
|
|
|
func (f *paymentCommandFactory) QuotePayment() *quotePaymentCommand {
|
|
return "ePaymentCommand{
|
|
engine: f.engine,
|
|
logger: f.logger.Named("quote.payment"),
|
|
}
|
|
}
|
|
|
|
func (f *paymentCommandFactory) QuotePayments() *quotePaymentsCommand {
|
|
return "ePaymentsCommand{
|
|
engine: f.engine,
|
|
logger: f.logger.Named("quote.payments"),
|
|
}
|
|
}
|