somme upd
This commit is contained in:
parent
330d8753e0
commit
f0d3d0c9cd
@ -8,6 +8,7 @@ import (
|
|||||||
"gitea.pena/PenaSide/treasurer/internal/models/alchemy"
|
"gitea.pena/PenaSide/treasurer/internal/models/alchemy"
|
||||||
"gitea.pena/PenaSide/treasurer/internal/repository"
|
"gitea.pena/PenaSide/treasurer/internal/repository"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"github.com/google/uuid"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -63,13 +64,12 @@ func (p *Provider) CreateInvoice(ctx context.Context, req map[string]string) (st
|
|||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
payment := &models.Payment{
|
payment := &models.Payment{
|
||||||
|
PaymentID: uuid.NewString(),
|
||||||
UserID: req["user_id"],
|
UserID: req["user_id"],
|
||||||
ClientIP: req["client_ip"],
|
ClientIP: req["client_ip"],
|
||||||
Currency: req["currency"],
|
Currency: req["currency"],
|
||||||
Type: models.PaymentType(req["type"]),
|
Type: models.PaymentTypeAlchemy,
|
||||||
Status: models.PaymentStatusWaiting,
|
Status: models.PaymentStatusWaiting,
|
||||||
Completed: false,
|
|
||||||
IsDeleted: false,
|
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
ToWalletAddress: p.config.WalletAddress,
|
ToWalletAddress: p.config.WalletAddress,
|
||||||
@ -106,6 +106,7 @@ func (p *Provider) handleWebhook(ctx *fiber.Ctx) error {
|
|||||||
if act.ToAddress != p.config.WalletAddress {
|
if act.ToAddress != p.config.WalletAddress {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// todo нужно подумать как сделать так если сумма оплаты оказалась чуть больше ожидаемой...
|
||||||
payment, err := p.repository.FindByWalletsAndAmount(ctx.Context(), act.ToAddress, act.FromAddress, act.Value)
|
payment, err := p.repository.FindByWalletsAndAmount(ctx.Context(), act.ToAddress, act.FromAddress, act.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Type() == errors.ErrNotFound {
|
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()))
|
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 {
|
if err != nil {
|
||||||
return ctx.Status(fiber.StatusInternalServerError).SendString(fmt.Sprintf("failed to set payment complete: %s", err.Error()))
|
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.ToWalletAddress: toWalletAddress,
|
||||||
PaymentFields.FromWalletAddress: fromWalletAddress,
|
PaymentFields.FromWalletAddress: fromWalletAddress,
|
||||||
PaymentFields.CryptoAmount: cryptoAmount,
|
PaymentFields.CryptoAmount: cryptoAmount,
|
||||||
PaymentFields.Completed: false,
|
|
||||||
PaymentFields.Status: models.PaymentStatusWaiting,
|
PaymentFields.Status: models.PaymentStatusWaiting,
|
||||||
}
|
}
|
||||||
if err := r.collection.FindOne(ctx, filter).Decode(&payment); err != nil {
|
if err := r.collection.FindOne(ctx, filter).Decode(&payment); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user