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
+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
}