31 lines
1.0 KiB
Go
31 lines
1.0 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"
|
|
)
|
|
|
|
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())
|
|
if 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 {
|
|
return gsresponse.NotFound[mntxv1.GetPayoutResponse](s.logger, mservice.MntxGateway, merrors.NoData(fmt.Sprintf("payout %s not found", ref)))
|
|
}
|
|
|
|
return gsresponse.Success(&mntxv1.GetPayoutResponse{Payout: payout})
|
|
}
|