This commit is contained in:
aditya.siregar
2024-10-27 19:48:10 +07:00
parent 758df918ae
commit 081a1aa27b
13 changed files with 190 additions and 35 deletions
+3 -3
View File
@@ -51,9 +51,9 @@ func (u *AuthServiceImpl) AuthenticateUser(ctx context.Context, email, password
return nil, errors.ErrorUserIsNotFound
}
//if ok := u.crypto.CompareHashAndPassword(user.Password, password); !ok {
// //return nil, errors.ErrorUserInvalidLogin
//}
if ok := u.crypto.CompareHashAndPassword(user.Password, password); !ok {
return nil, errors.ErrorUserInvalidLogin
}
signedToken, err := u.crypto.GenerateJWT(user.ToUser())
+33 -2
View File
@@ -32,6 +32,7 @@ type OrderService struct {
transaction repository.TransactionRepository
txmanager repository.TransactionManager
wallet repository.WalletRepository
linkquRepo repository.LinkQu
cfg Config
}
@@ -42,6 +43,7 @@ func NewOrderService(
txmanager repository.TransactionManager,
wallet repository.WalletRepository, cfg Config,
transaction repository.TransactionRepository,
linkquRepo repository.LinkQu,
) *OrderService {
return &OrderService{
repo: repo,
@@ -53,6 +55,7 @@ func NewOrderService(
wallet: wallet,
cfg: cfg,
transaction: transaction,
linkquRepo: linkquRepo,
}
}
@@ -558,9 +561,9 @@ func (s *OrderService) processPayment(ctx context.Context, tx *gorm.DB, req *ent
func updatePaymentState(status string) string {
switch status {
case "settlement", "capture":
case "settlement", "capture", "paid", "settle":
return "PAID"
case "expire", "deny", "cancel", "failure":
case "expire", "deny", "cancel", "failure", "EXPIRED":
return "EXPIRED"
default:
return status
@@ -680,3 +683,31 @@ func (s *OrderService) GetPrintDetail(ctx mycontext.Context, id int64) (*entity.
return order, nil
}
func (s *OrderService) ProcessLinkQuCallback(ctx context.Context, req *entity.LinkQuCallback) error {
tx, err := s.txmanager.Begin(ctx, &sql.TxOptions{Isolation: sql.LevelSerializable})
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
defer tx.Rollback()
pay, err := s.linkquRepo.CheckPaymentStatus(req.PaymentReff)
if err != nil {
return fmt.Errorf("failed to begin transaction: %w", err)
}
if pay.ResponseCode != "00" {
return nil
}
err = s.processPayment(ctx, tx, &entity.CallbackRequest{
TransactionID: req.PartnerReff,
TransactionStatus: pay.Data.StatusPaid,
})
if err != nil {
return fmt.Errorf("failed to process payment: %w", err)
}
return tx.Commit().Error
}
+2 -1
View File
@@ -47,7 +47,7 @@ func NewServiceManagerImpl(cfg *config.Config, repo *repository.RepoManagerImpl)
UserSvc: users.NewUserService(repo.User),
StudioSvc: studio.NewStudioService(repo.Studio),
ProductSvc: product.NewProductService(repo.Product),
OrderSvc: order.NewOrderService(repo.Order, repo.Product, repo.Crypto, repo.PG, repo.Payment, repo.Trx, repo.Wallet, &cfg.Order, repo.Transaction),
OrderSvc: order.NewOrderService(repo.Order, repo.Product, repo.Crypto, repo.PG, repo.Payment, repo.Trx, repo.Wallet, &cfg.Order, repo.Transaction, repo.LinkQu),
OSSSvc: oss.NewOSSService(repo.OSS),
PartnerSvc: partner.NewPartnerService(
repo.Partner, users.NewUserService(repo.User), repo.Trx, repo.Wallet, repo.User),
@@ -114,6 +114,7 @@ type Order interface {
GetPaymentDistribution(ctx mycontext.Context, req entity.OrderSearch) ([]entity.PaymentTypeDistribution, error)
GetByID(ctx mycontext.Context, id int64, referenceID string) (*entity.Order, error)
GetPrintDetail(ctx mycontext.Context, id int64) (*entity.OrderPrintDetail, error)
ProcessLinkQuCallback(ctx context.Context, req *entity.LinkQuCallback) error
}
type OSSService interface {