Backend: - Renomeado BACKEND_URL para BACKEND_HOST no .env e nas configs para consistência. - Atualizado MercadoPagoGateway para usar o BACKEND_HOST correto na notification_url. - Atualizado payment_handler para receber e processar informações do Pagador (email/doc). - Corrigido erro 500 ao buscar dados de compradores B2B. Frontend: - Criado componente Header reutilizável e aplicado nas páginas internas. - Implementada nova página "Meus Pedidos" com lógica de listagem correta. - Implementada página de "Detalhes do Pedido" (/pedidos/[id]) com alto contraste visual. - Melhorada a legibilidade da página de detalhes (textos pretos/escuros). - Corrigido bug onde pagamentos rejeitados eram tratados como sucesso (agora verifica status 'rejected' no serviço). - Adicionado componente <Toaster /> ao layout principal para corrigir notificações invisíveis. - Adicionado feedback visual persistente de erro na tela de checkout para falhas de pagamento.
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package payments
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/saveinmed/backend-go/internal/domain"
|
|
)
|
|
|
|
// StripeGateway implements payment processing via Stripe.
|
|
// In production, this would use the Stripe Go SDK.
|
|
type StripeGateway struct {
|
|
APIKey string
|
|
MarketplaceCommission float64
|
|
}
|
|
|
|
func NewStripeGateway(apiKey string, commission float64) *StripeGateway {
|
|
return &StripeGateway{
|
|
APIKey: apiKey,
|
|
MarketplaceCommission: commission,
|
|
}
|
|
}
|
|
|
|
func (g *StripeGateway) CreatePreference(ctx context.Context, order *domain.Order, payer *domain.User, sellerAcc *domain.SellerPaymentAccount) (*domain.PaymentPreference, error) {
|
|
select {
|
|
case <-ctx.Done():
|
|
return nil, ctx.Err()
|
|
default:
|
|
}
|
|
|
|
// Calculate marketplace fee
|
|
fee := int64(float64(order.TotalCents) * (g.MarketplaceCommission / 100))
|
|
|
|
// In production, this would:
|
|
// 1. Create a Stripe PaymentIntent with transfer_data for connected accounts
|
|
// 2. Set application_fee_amount for marketplace commission
|
|
// 3. Return the client_secret for frontend confirmation
|
|
|
|
pref := &domain.PaymentPreference{
|
|
OrderID: order.ID,
|
|
Gateway: "stripe",
|
|
CommissionPct: g.MarketplaceCommission,
|
|
MarketplaceFee: fee,
|
|
SellerReceivable: order.TotalCents - fee,
|
|
PaymentURL: fmt.Sprintf("https://checkout.stripe.com/pay/%s", order.ID.String()),
|
|
// In production: would include client_secret, payment_intent_id
|
|
}
|
|
|
|
// Simulate API latency
|
|
time.Sleep(15 * time.Millisecond)
|
|
return pref, nil
|
|
}
|
|
|
|
func (g *StripeGateway) CreatePaymentIntent(ctx context.Context, order *domain.Order) (map[string]interface{}, error) {
|
|
select {
|
|
case <-ctx.Done():
|
|
return nil, ctx.Err()
|
|
default:
|
|
}
|
|
|
|
fee := int64(float64(order.TotalCents) * (g.MarketplaceCommission / 100))
|
|
|
|
// Simulated Stripe PaymentIntent response
|
|
return map[string]interface{}{
|
|
"id": fmt.Sprintf("pi_%s", order.ID.String()[:8]),
|
|
"client_secret": fmt.Sprintf("pi_%s_secret_%d", order.ID.String()[:8], time.Now().UnixNano()),
|
|
"amount": order.TotalCents,
|
|
"currency": "brl",
|
|
"status": "requires_payment_method",
|
|
"application_fee": fee,
|
|
"transfer_data": map[string]interface{}{"destination": order.SellerID.String()},
|
|
}, nil
|
|
}
|