this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:sparkles: improved handler output with payment Id and cardId

+21 -9
+13 -1
internal/dto/payments.go
··· 1 1 package dto 2 2 3 + import "github.com/google/uuid" 4 + 3 5 type PaymentCardInput struct { 4 6 Number string `json:"number"` 5 7 HolderName string `json:"holderName"` ··· 17 19 } 18 20 19 21 type PaymentOutput struct { 20 - Message string `json:"message"` 22 + Id uuid.UUID `json:"id"` 23 + CardId uuid.UUID `json:"cardId"` 24 + CurrentAmount uint `json:"currentAmount"` 25 + } 26 + 27 + func NewPaymentOutput(id, cardId uuid.UUID, currentAmount uint) *PaymentOutput { 28 + return &PaymentOutput{ 29 + Id: id, 30 + CardId: cardId, 31 + CurrentAmount: currentAmount, 32 + } 21 33 }
+3 -6
internal/providers/provider.go
··· 36 36 37 37 func (p *UseProviders) Payment(ctx context.Context, payment *domain.Payment) (*domain.Provider, error) { 38 38 var err error = nil 39 - attempts := 0 40 39 41 40 for _, provider := range p.providers { 42 41 requestCtx, cancel := context.WithTimeout(ctx, p.timeout) ··· 46 45 select { 47 46 case data := <-dataCh: 48 47 p.logger.Debug("[Payment] Received request successfully", 49 - zap.String("provider", provider.GetName()), 50 - zap.Int("attempt", attempts)) 48 + zap.String("provider", provider.GetName())) 51 49 52 50 return data, nil 53 51 case error := <-errCh: 54 52 p.logger.Error("[Payment] Received request with error", 55 53 zap.String("provider", provider.GetName()), 56 - zap.Int("attempt", attempts), 57 54 zap.String("error", error.Error())) 58 55 59 56 err = error 60 57 continue 61 58 case <-time.After(p.timeout): 62 59 p.logger.Error("[Payment] Timeout for provider to respond", 63 - zap.String("provider", provider.GetName()), 64 - zap.Int("attempt", attempts)) 60 + zap.String("provider", provider.GetName())) 65 61 66 62 cancel() 67 63 68 64 err = errors.New("Timeout") 69 65 continue 70 66 case <-ctx.Done(): 67 + cancel() 71 68 return nil, ctx.Err() 72 69 } 73 70 }
+5 -2
internal/service/payment_service.go
··· 22 22 return nil, err 23 23 } 24 24 25 - _, err = p.providers.Payment(ctx, payment) 25 + providerData, err := p.providers.Payment(ctx, payment) 26 26 if err != nil { 27 + payment.UpdateStatus(domain.StatusRejected) 27 28 return nil, err 28 29 } 29 30 30 - return &dto.PaymentOutput{Message: "Processed successfully"}, nil 31 + payment.UpdateStatus(domain.StatusApproved) 32 + 33 + return dto.NewPaymentOutput(providerData.Id, providerData.CardId, providerData.CurrentAmount), nil 31 34 }