Files
payouts/internal/service/yookassa/yookassa_service.go

68 lines
1.6 KiB
Go

package yookassa
import (
"context"
"net/http"
"payouts/internal/models"
"payouts/internal/service/database/orm"
"payouts/internal/service/yookassa/config"
"payouts/internal/service/yookassa/gen"
"github.com/ogen-go/ogen/ogenerrors"
)
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].
func (y *yookassaService) BasicAuth(ctx context.Context, operationName gen.OperationName) (gen.BasicAuth, error) {
return gen.BasicAuth{
Username: y.conf.ApiPaymentKey,
Password: y.conf.ApiBaseSecret,
}, nil
}
// OAuth2 implements [gen.SecuritySource].
func (y *yookassaService) OAuth2(ctx context.Context, operationName gen.OperationName) (gen.OAuth2, error) {
return gen.OAuth2{}, ogenerrors.ErrSkipClientSecurity
}
// CreatePayout implements [Service].
func (y *yookassaService) CreatePayout(req models.PayoutReq, userSession *orm.User, opts ...Optional) {
params := y.getParams(opts...)
y.payClient.PayoutsPost(params.ctx, &gen.PayoutRequest{}, gen.PayoutsPostParams{})
}