Implement yookassa client

This commit is contained in:
2026-03-19 00:09:25 +03:00
parent 075a53f6ef
commit dd2c360cf6
15 changed files with 411 additions and 114 deletions

View File

@@ -98,8 +98,14 @@ func (d *dbService) CreatePayout(payoutModel *orm.Payout, opts ...Optional) erro
return gorm.G[orm.Payout](d.db).Create(p.ctx, payoutModel)
}
// UpdatePayout implements [Service].
func (d *dbService) UpdatePayout(payoutModel *orm.Payout, opts ...Optional) error {
// p := d.getParams(opts...)
panic("unimplemented")
// UpdatePayoutById implements [Service].
func (d *dbService) UpdatePayoutById(id uint, updateModel orm.Payout, opts ...Optional) (int, error) {
p := d.getParams(opts...)
return gorm.G[orm.Payout](d.db).Where("id = ?", id).Updates(p.ctx, updateModel)
}
// UpdatePayoutByPayoutID implements [Service].
func (d *dbService) UpdatePayoutByPayoutID(payoutId string, updateModel orm.Payout, opts ...Optional) (int, error) {
p := d.getParams(opts...)
return gorm.G[orm.Payout](d.db).Where("payout_id = ?", payoutId).Updates(p.ctx, updateModel)
}

View File

@@ -29,7 +29,8 @@ type Service interface {
GetUser(user *orm.User, opts ...Optional) (orm.User, error)
GetPayout(payoutModel *orm.Payout, opts ...Optional) (orm.Payout, error)
CreatePayout(payoutModel *orm.Payout, opts ...Optional) error
UpdatePayout(payoutModel *orm.Payout, opts ...Optional) error
UpdatePayoutById(id uint, updateModel orm.Payout, opts ...Optional) (int, error)
UpdatePayoutByPayoutID(payoutId string, updateModel orm.Payout, opts ...Optional) (int, error)
}
// Params represents the module input params

View File

@@ -1,61 +1,9 @@
package orm
import (
"fmt"
"strings"
"gorm.io/gorm"
)
type PayoutStatus int64
const (
StatusCreated PayoutStatus = iota
StatusCanceled
StatusPending
StatusSucceeded
StatusFailed
)
func (r PayoutStatus) String() string {
switch r {
case StatusCreated:
return "created"
case StatusCanceled:
return "canceled"
case StatusPending:
return "pending"
case StatusSucceeded:
return "succeeded"
case StatusFailed:
return "failed"
}
return "unknown"
}
func (r PayoutStatus) MarshalText() (text []byte, err error) {
return []byte(r.String()), nil
}
func (r *PayoutStatus) UnmarshalText(text []byte) (err error) {
s := strings.ToLower(string(text))
switch s {
case "canceled":
*r = StatusCanceled
case "created":
*r = StatusCreated
case "pending":
*r = StatusPending
case "succeeded":
*r = StatusSucceeded
case "failed":
*r = StatusFailed
default:
err = fmt.Errorf("invalid payment type: %s", s)
}
return err
}
type Payout struct {
gorm.Model
@@ -69,6 +17,6 @@ type Payout struct {
AccountNumber string
Amount float32
Currency string
Status PayoutStatus
Status string
Test bool
}