- Add PaymentHandler with methods for creating payment intents, confirming payments, and handling webhooks - Implement PaymentService interface with Stripe payment processing logic - Create DTOs for payment-related requests in services/interfaces.go - Add error handling and validation for payment-related operations - Configure Stripe API key and support for automatic payment methods - Implement webhook signature verification and event processing - Enhance error responses with detailed error messages and appropriate HTTP status codes Enables full payment flow using Stripe, supporting intent creation, payment confirmation, and webhook handling for robust transaction management.
91 lines
3.0 KiB
Go
91 lines
3.0 KiB
Go
package services
|
|
|
|
import (
|
|
"time"
|
|
|
|
"attune-heart-therapy/internal/models"
|
|
|
|
"github.com/stripe/stripe-go/v76"
|
|
)
|
|
|
|
// UserService handles user-related operations
|
|
type UserService interface {
|
|
Register(req RegisterRequest) (*models.User, error)
|
|
Login(email, password string) (*models.User, string, error) // returns user and JWT token
|
|
GetProfile(userID uint) (*models.User, error)
|
|
UpdateProfile(userID uint, req UpdateProfileRequest) (*models.User, error)
|
|
}
|
|
|
|
// BookingService handles booking operations
|
|
type BookingService interface {
|
|
GetAvailableSlots(date time.Time) ([]models.Schedule, error)
|
|
CreateBooking(userID uint, req BookingRequest) (*models.Booking, error)
|
|
GetUserBookings(userID uint) ([]models.Booking, error)
|
|
CancelBooking(userID, bookingID uint) error
|
|
RescheduleBooking(userID, bookingID uint, newScheduleID uint) error
|
|
}
|
|
|
|
// PaymentService handles Stripe integration
|
|
type PaymentService interface {
|
|
CreatePaymentIntent(amount float64, currency string) (*stripe.PaymentIntent, error)
|
|
ConfirmPayment(paymentIntentID string) (*stripe.PaymentIntent, error)
|
|
HandleWebhook(payload []byte, signature string) error
|
|
}
|
|
|
|
// NotificationService handles email notifications
|
|
type NotificationService interface {
|
|
SendWelcomeEmail(user *models.User) error
|
|
SendPaymentNotification(user *models.User, booking *models.Booking, success bool) error
|
|
SendMeetingInfo(user *models.User, booking *models.Booking) error
|
|
SendReminder(user *models.User, booking *models.Booking) error
|
|
ScheduleReminder(bookingID uint, reminderTime time.Time) error
|
|
}
|
|
|
|
// JitsiService handles video conference integration
|
|
type JitsiService interface {
|
|
CreateMeeting(bookingID uint, scheduledAt time.Time) (*JitsiMeeting, error)
|
|
GetMeetingURL(roomID string) string
|
|
DeleteMeeting(roomID string) error
|
|
}
|
|
|
|
// JitsiMeeting represents a Jitsi meeting
|
|
type JitsiMeeting struct {
|
|
RoomID string `json:"room_id"`
|
|
RoomURL string `json:"room_url"`
|
|
}
|
|
|
|
// Request/Response DTOs
|
|
type RegisterRequest struct {
|
|
FirstName string `json:"first_name" binding:"required"`
|
|
LastName string `json:"last_name" binding:"required"`
|
|
Email string `json:"email" binding:"required,email"`
|
|
Phone string `json:"phone"`
|
|
Location string `json:"location"`
|
|
DateOfBirth time.Time `json:"date_of_birth"`
|
|
Password string `json:"password" binding:"required,min=6"`
|
|
}
|
|
|
|
type UpdateProfileRequest struct {
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Phone string `json:"phone"`
|
|
Location string `json:"location"`
|
|
DateOfBirth time.Time `json:"date_of_birth"`
|
|
}
|
|
|
|
type BookingRequest struct {
|
|
ScheduleID uint `json:"schedule_id" binding:"required"`
|
|
Notes string `json:"notes"`
|
|
Amount float64 `json:"amount" binding:"required"`
|
|
}
|
|
|
|
// Payment DTOs
|
|
type CreatePaymentIntentRequest struct {
|
|
Amount float64 `json:"amount" binding:"required,gt=0"`
|
|
Currency string `json:"currency"`
|
|
}
|
|
|
|
type ConfirmPaymentRequest struct {
|
|
PaymentIntentID string `json:"payment_intent_id" binding:"required"`
|
|
}
|