Reorganaze modules, add auth processing.

This commit is contained in:
2026-03-13 00:07:23 +03:00
parent 95b1b867db
commit 970e64745b
14 changed files with 220 additions and 97 deletions

View File

@@ -2,6 +2,9 @@ package yookassa
import (
"context"
"net/http"
"payouts/internal/models"
"payouts/internal/service/database/orm"
"payouts/internal/service/yookassa/config"
"payouts/internal/service/yookassa/gen"
@@ -11,6 +14,36 @@ import (
type yookassaService struct {
conf config.YooKassa
payClient *gen.Client
ctx context.Context
}
func NewYookassaService(conf config.YooKassa) (Service, error) {
svc := &yookassaService{
conf: conf,
ctx: context.Background(),
}
payClient, err := gen.NewClient(conf.BaseUrl, svc, gen.WithClient(&http.Client{
Timeout: conf.Timeout,
}))
if err != nil {
return nil, err
}
svc.payClient = payClient
// payClient.PaymentsPost()
return svc, nil
}
func (y *yookassaService) getParams(options ...Optional) *params {
params := &params{
ctx: y.ctx,
}
for _, opt := range options {
opt(params)
}
return params
}
// BasicAuth implements [gen.SecuritySource].
@@ -26,17 +59,9 @@ func (y *yookassaService) OAuth2(ctx context.Context, operationName gen.Operatio
return gen.OAuth2{}, ogenerrors.ErrSkipClientSecurity
}
func NewYookassaService(conf config.YooKassa) (Service, error) {
// CreatePayout implements [Service].
func (y *yookassaService) CreatePayout(req models.PayoutReq, userSession *orm.User, opts ...Optional) {
params := y.getParams(opts...)
svc := &yookassaService{
conf: conf,
}
payClient, err := gen.NewClient(conf.BaseUrl, svc)
if err != nil {
return nil, err
}
svc.payClient = payClient
// payClient.PaymentsPost()
return svc, nil
y.payClient.PayoutsPost(params.ctx, &gen.PayoutRequest{}, gen.PayoutsPostParams{})
}