saveinmed/backend-old/internal/usecase/payment_config.go
2026-01-16 10:51:52 -03:00

44 lines
1.6 KiB
Go

package usecase
import (
"context"
"github.com/gofrs/uuid/v5"
"github.com/saveinmed/backend-go/internal/domain"
)
// GetPaymentGatewayConfig returns the configuration for a specific provider
func (s *Service) GetPaymentGatewayConfig(ctx context.Context, provider string) (*domain.PaymentGatewayConfig, error) {
return s.repo.GetPaymentGatewayConfig(ctx, provider)
}
// UpsertPaymentGatewayConfig updates global gateway configuration
func (s *Service) UpsertPaymentGatewayConfig(ctx context.Context, config *domain.PaymentGatewayConfig) error {
// Logic to encrypt credentials could go here
return s.repo.UpsertPaymentGatewayConfig(ctx, config)
}
// GetSellerPaymentAccount returns a seller's connected account details
func (s *Service) GetSellerPaymentAccount(ctx context.Context, sellerID uuid.UUID) (*domain.SellerPaymentAccount, error) {
return s.repo.GetSellerPaymentAccount(ctx, sellerID)
}
// OnboardSeller initiates the onboarding process for a seller (e.g. Stripe Connect)
func (s *Service) OnboardSeller(ctx context.Context, sellerID uuid.UUID, gateway string) (string, error) {
// 1. Generate Connect Link (Mock for now or call gateway)
// For MVP, just return a dummy link and create pending record
// Real implementation would use s.pay.CreateConnectLink(...)
// Ensure record exists
account := &domain.SellerPaymentAccount{
SellerID: sellerID,
Gateway: gateway,
Status: "pending",
AccountType: "standard", // default
}
if err := s.repo.UpsertSellerPaymentAccount(ctx, account); err != nil {
return "", err
}
return "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_123&scope=read_write", nil
}