37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/tech/sendico/pkg/api/routers/gsresponse"
|
|
"github.com/tech/sendico/pkg/merrors"
|
|
"github.com/tech/sendico/pkg/mservice"
|
|
mntxv1 "github.com/tech/sendico/pkg/proto/gateway/mntx/v1"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func (s *Service) GetPayout(ctx context.Context, req *mntxv1.GetPayoutRequest) (*mntxv1.GetPayoutResponse, error) {
|
|
return executeUnary(ctx, s, "GetPayout", s.handleGetPayout, req)
|
|
}
|
|
|
|
func (s *Service) handleGetPayout(_ context.Context, req *mntxv1.GetPayoutRequest) gsresponse.Responder[mntxv1.GetPayoutResponse] {
|
|
ref := strings.TrimSpace(req.GetPayoutRef())
|
|
log := s.logger.Named("payout")
|
|
log.Info("Get payout request received", zap.String("payout_ref", ref))
|
|
if ref == "" {
|
|
log.Warn("Get payout request missing payout_ref")
|
|
return gsresponse.InvalidArgument[mntxv1.GetPayoutResponse](s.logger, mservice.MntxGateway, merrors.InvalidArgument("payout_ref is required", "payout_ref"))
|
|
}
|
|
|
|
payout, ok := s.store.Get(ref)
|
|
if !ok {
|
|
log.Warn("Payout not found", zap.String("payout_ref", ref))
|
|
return gsresponse.NotFound[mntxv1.GetPayoutResponse](s.logger, mservice.MntxGateway, merrors.NoData(fmt.Sprintf("payout %s not found", ref)))
|
|
}
|
|
|
|
log.Info("Payout retrieved", zap.String("payout_ref", ref), zap.String("status", payout.GetStatus().String()))
|
|
return gsresponse.Success(&mntxv1.GetPayoutResponse{Payout: payout})
|
|
}
|