Skip to content

Commit 33776fd

Browse files
authored
Merge pull request #32 from hammercode-dev/feat/vibe-code-pg-xendit-testing
[FEAT] - finising payment xendit transaction events
2 parents d60eaca + 63ba09f commit 33776fd

28 files changed

+2904
-38
lines changed

.env.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ CORS_ALLOWED_METHODS="GET,POST,PUT,PATCH,DELETE,OPTIONS"
1313
SMTP_HOST="[email protected]"
1414
SMTP_PASSWORD="123456"
1515
SMTP_PORT="587"
16-
SMTP_EMAIL="smtp.gmail.com"
16+
SMTP_EMAIL="smtp.gmail.com"
17+
18+
# Xendit Payment Gateway Configuration
19+
# Get your API key from: https://dashboard.xendit.co/settings/developers#api-keys
20+
# Use test mode API key for development (starts with xnd_development_)
21+
XENDIT_API_KEY="xnd_development_your_api_key_here"
22+
XENDIT_WEBHOOK_TOKEN="your_webhook_verification_token_here"
23+
XENDIT_SUCCESS_REDIRECT="http://localhost:3000/payment/success"
24+
XENDIT_FAILURE_REDIRECT="http://localhost:3000/payment/failed"

app/app.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,29 @@ import (
44
blogPost "github.com/hammer-code/lms-be/app/blog_post"
55
"github.com/hammer-code/lms-be/app/middlewares"
66
newsletters "github.com/hammer-code/lms-be/app/newsletters"
7+
transactionEvent "github.com/hammer-code/lms-be/app/transaction_events/delivery/http"
8+
transactionEventRepo "github.com/hammer-code/lms-be/app/transaction_events/repository"
9+
transactionEventUC "github.com/hammer-code/lms-be/app/transaction_events/usecase"
710
users "github.com/hammer-code/lms-be/app/users"
811
"github.com/hammer-code/lms-be/config"
912
"github.com/hammer-code/lms-be/domain"
1013
pkgDB "github.com/hammer-code/lms-be/pkg/db"
1114
"github.com/hammer-code/lms-be/pkg/jwt"
15+
"github.com/hammer-code/lms-be/pkg/xendit"
1216
"gorm.io/driver/postgres"
1317

1418
events "github.com/hammer-code/lms-be/app/events"
1519
images "github.com/hammer-code/lms-be/app/images"
1620
)
1721

1822
type App struct {
19-
Middleware domain.Middleware
20-
UserHandler domain.UserHandler
21-
NewLetterHandler domain.NewslettterHandler
22-
EventHandler domain.EventHandler
23-
ImageHandler domain.ImageHandler
24-
BlogPostHandler domain.BlogPostHandler
23+
Middleware domain.Middleware
24+
UserHandler domain.UserHandler
25+
NewLetterHandler domain.NewslettterHandler
26+
EventHandler domain.EventHandler
27+
ImageHandler domain.ImageHandler
28+
BlogPostHandler domain.BlogPostHandler
29+
TransactionEventHandler domain.TransactionEventHandler
2530
}
2631

2732
func InitApp(
@@ -36,12 +41,16 @@ func InitApp(
3641
dbTx := pkgDB.NewDBTransaction(db)
3742
jwtInstance := jwt.NewJwt(cfg.JWT_SECRET_KEY)
3843

44+
// Xendit client
45+
xenditClient := xendit.NewClient(cfg.XENDIT_API_KEY)
46+
3947
// repository
4048
userRepo := users.InitRepository(dbTx)
4149
newsletterRepo := newsletters.InitRepository(dbTx)
4250
eventRepo := events.InitRepository(dbTx)
4351
imgRepo := images.InitRepository(dbTx)
4452
blogPostRepo := blogPost.InitRepository(dbTx)
53+
transactionEventRepository := transactionEventRepo.NewRepository(db)
4554

4655
// Middlewares
4756
middleware := middlewares.InitMiddleware(jwtInstance, userRepo)
@@ -52,20 +61,23 @@ func InitApp(
5261
eventUC := events.InitUsecase(cfg, eventRepo, imgRepo, dbTx)
5362
imgUc := images.InitUsecase(imgRepo, dbTx)
5463
blogPostUc := blogPost.InitUseCase(blogPostRepo, jwtInstance)
64+
transactionEventUsecase := transactionEventUC.NewUsecase(transactionEventRepository, eventRepo, xenditClient, cfg)
5565

5666
// handler
5767
userHandler := users.InitHandler(userUsecase)
5868
newsletterHandler := newsletters.InitHandler(newsletterUC, middleware)
5969
eventHandler := events.InitHandler(eventUC)
6070
ImageHandler := images.InitHandler(imgUc)
6171
blogPostHandler := blogPost.InitHandler(blogPostUc)
72+
transactionEventHandler := transactionEvent.NewHandler(transactionEventUsecase, cfg)
6273

6374
return App{
64-
UserHandler: userHandler,
65-
NewLetterHandler: newsletterHandler,
66-
Middleware: middleware,
67-
EventHandler: eventHandler,
68-
ImageHandler: ImageHandler,
69-
BlogPostHandler: blogPostHandler,
75+
UserHandler: userHandler,
76+
NewLetterHandler: newsletterHandler,
77+
Middleware: middleware,
78+
EventHandler: eventHandler,
79+
ImageHandler: ImageHandler,
80+
BlogPostHandler: blogPostHandler,
81+
TransactionEventHandler: transactionEventHandler,
7082
}
7183
}

app/events/repository/get_registration_event.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
func (repo *repository) GetRegistrationEvent(ctx context.Context, orderNo string) (data domain.RegistrationEvent, err error) {
1010
db := repo.db.DB(ctx).Model(&domain.RegistrationEvent{})
1111

12-
err = db.Where("order_no = ?", orderNo).Find(&data).Error
12+
err = db.Preload("User").Where("order_no = ?", orderNo).Find(&data).Error
1313
if err != nil {
1414
return
1515
}
@@ -20,15 +20,15 @@ func (repo *repository) GetRegistrationEvent(ctx context.Context, orderNo string
2020
func (repo *repository) GetRegistrationEventByID(ctx context.Context, id uint) (data domain.RegistrationEvent, err error) {
2121
db := repo.db.DB(ctx).Model(&domain.RegistrationEvent{})
2222

23-
err = db.Where("id = ?", id).Find(&data).Error
23+
err = db.Preload("User").Where("id = ?", id).Find(&data).Error
2424
if err != nil {
2525
return
2626
}
2727

2828
return data, err
2929
}
3030

31-
func (repo *repository) GetRegistrationEventUserByStatus(ctx context.Context, eventID uint, userID uint, statuses []string) (data []domain.RegistrationEvent, err error) {
31+
func (repo *repository) GetRegistrationEventUserByStatus(ctx context.Context, eventID uint, userID string, statuses []string) (data []domain.RegistrationEvent, err error) {
3232
db := repo.db.DB(ctx).Model(&domain.RegistrationEvent{})
3333

3434
err = db.Where("event_id = ?", eventID).Where("user_id = ?", userID).Where("status IN (?)", statuses).Find(&data).Error

app/events/repository/list_registration.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ func (repo *repository) ListRegistration(ctx context.Context, filter domain.Even
1010
db := repo.db.DB(ctx).Model(&domain.RegistrationEvent{}).
1111
Preload("Event").
1212
Preload("Event.Tags").
13-
Preload("Event.Speakers")
13+
Preload("Event.Speakers").
14+
Preload("User").
15+
Preload("Transaction")
16+
17+
// Filter by user email (only show registrations for the logged-in user)
18+
if email != "" {
19+
db = db.Joins("JOIN users ON users.id = CAST(registration_events.user_id AS INTEGER)").
20+
Where("users.email = ?", email)
21+
}
1422

1523
if filter.Status != "" {
1624
db = db.Where("registration_events.status = ?", filter.Status)

app/events/usecase/create_registration_event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (uc usecase) CreateRegistrationEvent(ctx context.Context, payload domain.Re
2323
// get user data from context
2424
userData := ctx.Value(contextkey.UserKey).(domain.User)
2525

26-
registrations, err := uc.repository.GetRegistrationEventUserByStatus(ctx, payload.EventID, uint(userData.ID), []string{constants.PENDING, constants.SUCCESS})
26+
registrations, err := uc.repository.GetRegistrationEventUserByStatus(ctx, payload.EventID, strconv.Itoa(userData.ID), []string{constants.PENDING, constants.SUCCESS})
2727
if err != nil {
2828
err = utils.NewInternalServerError(ctx, err)
2929
return domain.RegisterEventResponse{}, err

app/events/usecase/list_registration_event.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ func (uc usecase) ListRegistration(ctx context.Context, filter domain.EventFilte
2323

2424
for i, data := range datas {
2525
datas[i].ImageProofPayment = fmt.Sprintf("%s/api/v1/public/storage/images/%s", baseURL, data.ImageProofPayment)
26-
26+
2727
// Update event image URL
2828
if datas[i].Event.Image != "" {
2929
datas[i].Event.Image = fmt.Sprintf("%s/api/v1/public/storage/images/%s", baseURL, datas[i].Event.Image)
3030
}
31+
32+
if data.Transaction != nil && data.Transaction.InvoiceURL != nil {
33+
datas[i].PaymentURL = *data.Transaction.InvoiceURL
34+
datas[i].TransactionNo = *&data.Transaction.TransactionNo
35+
}
3136
}
32-
37+
3338
return datas, domain.NewPagination(tData, filter.FilterPagination), err
3439
}

0 commit comments

Comments
 (0)