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