Yimaru-BackEnd/internal/web_server/handlers/handlers.go
Yared Yemane 1f7b38861e Integrate Chapa for learner subscription payments
Add Chapa checkout, verify, webhook, and callback flows so subscriptions activate only after confirmed payment. Route subscription checkout through Chapa while keeping ArifPay for direct payments. Include integration docs and a Postman collection.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-21 03:35:57 -07:00

176 lines
5.9 KiB
Go

package handlers
import (
"context"
dbgen "Yimaru-Backend/gen/db"
"Yimaru-Backend/internal/config"
"Yimaru-Backend/internal/domain"
activitylogservice "Yimaru-Backend/internal/services/activity_log"
"Yimaru-Backend/internal/services/arifpay"
"Yimaru-Backend/internal/services/chapa"
"Yimaru-Backend/internal/services/assessment"
"Yimaru-Backend/internal/services/authentication"
cloudconvertservice "Yimaru-Backend/internal/services/cloudconvert"
"Yimaru-Backend/internal/services/courses"
"Yimaru-Backend/internal/services/examprep"
"Yimaru-Backend/internal/services/faqs"
issuereporting "Yimaru-Backend/internal/services/issue_reporting"
"Yimaru-Backend/internal/services/lessons"
"Yimaru-Backend/internal/services/lmsprogress"
minioservice "Yimaru-Backend/internal/services/minio"
"Yimaru-Backend/internal/services/modules"
notificationservice "Yimaru-Backend/internal/services/notification"
"Yimaru-Backend/internal/services/personas"
"Yimaru-Backend/internal/services/practices"
"Yimaru-Backend/internal/services/programs"
"Yimaru-Backend/internal/services/questions"
ratingsservice "Yimaru-Backend/internal/services/ratings"
rbacservice "Yimaru-Backend/internal/services/rbac"
"Yimaru-Backend/internal/services/recommendation"
"Yimaru-Backend/internal/services/subscriptions"
"Yimaru-Backend/internal/services/team"
vimeoservice "Yimaru-Backend/internal/services/vimeo"
// referralservice "Yimaru-Backend/internal/services/referal"
"Yimaru-Backend/internal/services/settings"
"Yimaru-Backend/internal/services/transaction"
"Yimaru-Backend/internal/services/user"
jwtutil "Yimaru-Backend/internal/web_server/jwt"
customvalidator "Yimaru-Backend/internal/web_server/validator"
"log/slog"
"go.uber.org/zap"
)
type Handler struct {
assessmentSvc *assessment.Service
questionsSvc *questions.Service
faqSvc *faqs.Service
personaSvc *personas.Service
examPrepSvc *examprep.Service
programSvc *programs.Service
courseSvc *courses.Service
moduleSvc *modules.Service
lessonSvc *lessons.Service
lmsProgressSvc *lmsprogress.Service
practiceSvc *practices.Service
subscriptionsSvc *subscriptions.Service
arifpaySvc *arifpay.ArifpayService
chapaSvc *chapa.Service
logger *slog.Logger
settingSvc *settings.Service
notificationSvc *notificationservice.Service
userSvc *user.Service
transactionSvc *transaction.Service
recommendationSvc recommendation.RecommendationService
authSvc *authentication.Service
vimeoSvc *vimeoservice.Service
teamSvc *team.Service
activityLogSvc *activitylogservice.Service
issueReportingSvc *issuereporting.Service
cloudConvertSvc *cloudconvertservice.Service
minioSvc *minioservice.Service
ratingSvc *ratingsservice.Service
rbacSvc *rbacservice.Service
jwtConfig jwtutil.JwtConfig
validator *customvalidator.CustomValidator
Cfg *config.Config
mongoLoggerSvc *zap.Logger
analyticsDB *dbgen.Queries
}
func New(
assessmentSvc *assessment.Service,
questionsSvc *questions.Service,
faqSvc *faqs.Service,
personaSvc *personas.Service,
examPrepSvc *examprep.Service,
programSvc *programs.Service,
courseSvc *courses.Service,
moduleSvc *modules.Service,
lessonSvc *lessons.Service,
lmsProgressSvc *lmsprogress.Service,
practiceSvc *practices.Service,
subscriptionsSvc *subscriptions.Service,
arifpaySvc *arifpay.ArifpayService,
chapaSvc *chapa.Service,
logger *slog.Logger,
settingSvc *settings.Service,
notificationSvc *notificationservice.Service,
validator *customvalidator.CustomValidator,
recommendationSvc recommendation.RecommendationService,
userSvc *user.Service,
transactionSvc *transaction.Service,
authSvc *authentication.Service,
vimeoSvc *vimeoservice.Service,
teamSvc *team.Service,
activityLogSvc *activitylogservice.Service,
issueReportingSvc *issuereporting.Service,
cloudConvertSvc *cloudconvertservice.Service,
minioSvc *minioservice.Service,
ratingSvc *ratingsservice.Service,
rbacSvc *rbacservice.Service,
jwtConfig jwtutil.JwtConfig,
cfg *config.Config,
mongoLoggerSvc *zap.Logger,
analyticsDB *dbgen.Queries,
) *Handler {
return &Handler{
assessmentSvc: assessmentSvc,
questionsSvc: questionsSvc,
faqSvc: faqSvc,
personaSvc: personaSvc,
examPrepSvc: examPrepSvc,
programSvc: programSvc,
courseSvc: courseSvc,
moduleSvc: moduleSvc,
lessonSvc: lessonSvc,
lmsProgressSvc: lmsProgressSvc,
practiceSvc: practiceSvc,
subscriptionsSvc: subscriptionsSvc,
arifpaySvc: arifpaySvc,
chapaSvc: chapaSvc,
logger: logger,
settingSvc: settingSvc,
notificationSvc: notificationSvc,
validator: validator,
userSvc: userSvc,
transactionSvc: transactionSvc,
recommendationSvc: recommendationSvc,
authSvc: authSvc,
vimeoSvc: vimeoSvc,
teamSvc: teamSvc,
activityLogSvc: activityLogSvc,
issueReportingSvc: issueReportingSvc,
cloudConvertSvc: cloudConvertSvc,
minioSvc: minioSvc,
ratingSvc: ratingSvc,
rbacSvc: rbacSvc,
jwtConfig: jwtConfig,
Cfg: cfg,
mongoLoggerSvc: mongoLoggerSvc,
analyticsDB: analyticsDB,
}
}
func (h *Handler) sendInAppNotification(recipientID int64, notifType domain.NotificationType, headline, message string) {
go func() {
notification := &domain.Notification{
RecipientID: recipientID,
Type: notifType,
Level: domain.NotificationLevelInfo,
DeliveryChannel: domain.DeliveryChannelInApp,
DeliveryStatus: domain.DeliveryStatusPending,
IsRead: false,
Payload: domain.NotificationPayload{
Headline: headline,
Message: message,
},
}
_ = h.notificationSvc.SendNotification(context.Background(), notification)
}()
}