Reorganaze modules, add auth processing.
This commit is contained in:
@@ -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 := ¶ms{
|
||||
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{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user