payment gateways wallet service fixes
This commit is contained in:
parent
7575f29386
commit
1e39d75239
|
|
@ -135,24 +135,24 @@ func (s *Service) InitiateWithdrawal(ctx context.Context, userID int64, req doma
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user's wallet
|
// Get user's wallet
|
||||||
wallets, err := s.walletStore.GetWalletsByUser(ctx, userID)
|
wallet, err := s.walletStore.GetCustomerWallet(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get user wallets: %w", err)
|
return nil, fmt.Errorf("failed to get user wallets: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var withdrawWallet domain.Wallet
|
// var withdrawWallet domain.Wallet
|
||||||
for _, wallet := range wallets {
|
// for _, wallet := range wallets {
|
||||||
if wallet.IsWithdraw {
|
// if wallet.IsWithdraw {
|
||||||
withdrawWallet = wallet
|
// withdrawWallet = wallet
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if withdrawWallet.ID == 0 {
|
// if withdrawWallet.ID == 0 {
|
||||||
return nil, errors.New("withdrawal wallet not found")
|
// return nil, errors.New("withdrawal wallet not found")
|
||||||
}
|
// }
|
||||||
// Check balance
|
// Check balance
|
||||||
if withdrawWallet.Balance < domain.Currency(amount) {
|
if float64(wallet.RegularBalance) < float64(amount) {
|
||||||
return nil, domain.ErrInsufficientBalance
|
return nil, domain.ErrInsufficientBalance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ func (s *Service) InitiateWithdrawal(ctx context.Context, userID int64, req doma
|
||||||
Amount: domain.Currency(amount),
|
Amount: domain.Currency(amount),
|
||||||
Type: domain.WITHDRAW,
|
Type: domain.WITHDRAW,
|
||||||
SenderWalletID: domain.ValidInt64{
|
SenderWalletID: domain.ValidInt64{
|
||||||
Value: withdrawWallet.ID,
|
Value: wallet.RegularID,
|
||||||
Valid: true,
|
Valid: true,
|
||||||
},
|
},
|
||||||
Status: string(domain.PaymentStatusPending),
|
Status: string(domain.PaymentStatusPending),
|
||||||
|
|
@ -205,8 +205,8 @@ func (s *Service) InitiateWithdrawal(ctx context.Context, userID int64, req doma
|
||||||
return nil, fmt.Errorf("failed to update withdrawal status: %w", err)
|
return nil, fmt.Errorf("failed to update withdrawal status: %w", err)
|
||||||
}
|
}
|
||||||
// Deduct from wallet (or wait for webhook confirmation depending on your flow)
|
// Deduct from wallet (or wait for webhook confirmation depending on your flow)
|
||||||
newBalance := withdrawWallet.Balance - domain.Currency(amount)
|
newBalance := float64(wallet.RegularBalance) - float64(amount)
|
||||||
if err := s.walletStore.UpdateBalance(ctx, withdrawWallet.ID, newBalance); err != nil {
|
if err := s.walletStore.UpdateBalance(ctx, wallet.RegularID, domain.Currency(newBalance)); err != nil {
|
||||||
return nil, fmt.Errorf("failed to update wallet balance: %w", err)
|
return nil, fmt.Errorf("failed to update wallet balance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,16 +134,16 @@ func (s *SantimPayService) ProcessCallback(ctx context.Context, payload domain.S
|
||||||
return fmt.Errorf("invalid ThirdPartyId '%s': %w", payload.ThirdPartyId, err)
|
return fmt.Errorf("invalid ThirdPartyId '%s': %w", payload.ThirdPartyId, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wallets, err := s.walletSvc.GetWalletsByUser(ctx, userID)
|
wallet, err := s.walletSvc.GetCustomerWallet(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get wallets for user %d: %w", userID, err)
|
return fmt.Errorf("failed to get wallets for customer %d: %w", userID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally, credit user wallet
|
// Optionally, credit user wallet
|
||||||
if transfer.Type == domain.DEPOSIT {
|
if transfer.Type == domain.DEPOSIT {
|
||||||
if _, err := s.walletSvc.AddToWallet(
|
if _, err := s.walletSvc.AddToWallet(
|
||||||
ctx,
|
ctx,
|
||||||
wallets[0].ID,
|
wallet.RegularID,
|
||||||
domain.Currency(amount),
|
domain.Currency(amount),
|
||||||
domain.ValidInt64{},
|
domain.ValidInt64{},
|
||||||
domain.TRANSFER_SANTIMPAY,
|
domain.TRANSFER_SANTIMPAY,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user