somme upd

This commit is contained in:
Pasha 2025-07-22 14:28:27 +03:00
parent 330d8753e0
commit f0d3d0c9cd
2 changed files with 5 additions and 5 deletions

@ -8,6 +8,7 @@ import (
"gitea.pena/PenaSide/treasurer/internal/models/alchemy"
"gitea.pena/PenaSide/treasurer/internal/repository"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
"go.uber.org/zap"
"strconv"
"strings"
@ -63,13 +64,12 @@ func (p *Provider) CreateInvoice(ctx context.Context, req map[string]string) (st
now := time.Now()
payment := &models.Payment{
PaymentID: uuid.NewString(),
UserID: req["user_id"],
ClientIP: req["client_ip"],
Currency: req["currency"],
Type: models.PaymentType(req["type"]),
Type: models.PaymentTypeAlchemy,
Status: models.PaymentStatusWaiting,
Completed: false,
IsDeleted: false,
CreatedAt: now,
UpdatedAt: now,
ToWalletAddress: p.config.WalletAddress,
@ -106,6 +106,7 @@ func (p *Provider) handleWebhook(ctx *fiber.Ctx) error {
if act.ToAddress != p.config.WalletAddress {
continue
}
// todo нужно подумать как сделать так если сумма оплаты оказалась чуть больше ожидаемой...
payment, err := p.repository.FindByWalletsAndAmount(ctx.Context(), act.ToAddress, act.FromAddress, act.Value)
if err != nil {
if err.Type() == errors.ErrNotFound {
@ -113,7 +114,7 @@ func (p *Provider) handleWebhook(ctx *fiber.Ctx) error {
}
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("internal error while searching payment: %s", err.Error()))
}
_, err = p.repository.SetPaymentComplete(ctx.Context(), payment.PaymentID)
_, err = p.repository.SetPaymentStatus(ctx.Context(), payment.PaymentID, models.PaymentStatusSuccessfully)
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("failed to set payment complete: %s", err.Error()))
}

@ -173,7 +173,6 @@ func (r *PaymentRepository) FindByWalletsAndAmount(ctx context.Context, toWallet
PaymentFields.ToWalletAddress: toWalletAddress,
PaymentFields.FromWalletAddress: fromWalletAddress,
PaymentFields.CryptoAmount: cryptoAmount,
PaymentFields.Completed: false,
PaymentFields.Status: models.PaymentStatusWaiting,
}
if err := r.collection.FindOne(ctx, filter).Decode(&payment); err != nil {