Skip to content

Commit

Permalink
Merge pull request #111 from eurofurence/issue-110-paylink-fix
Browse files Browse the repository at this point in the history
fix(#110): tentative paylinks only block same type
  • Loading branch information
Jumpy-Squirrel authored Jan 15, 2024
2 parents 59a518a + ccd12ab commit ac8df05
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/interaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ func (s *serviceInteractor) validateAttendeeTransaction(ctx context.Context, new
return apierrors.NewForbidden("transaction is not eligible for requesting a payment link")
}

// Check if there are any pending transactions.
pending, err := s.arePendingPaymentsPresent(ctx, newTransaction.DebitorID)
// Check if there are any pending or tentative transactions that block creation of the payment
pending, err := s.arePendingPaymentsPresent(ctx, newTransaction.DebitorID, newTransaction.PaymentMethod)

if err != nil {
logger.Error("could not retrieve pending payments for debitor %d - [error]: %v", newTransaction.DebitorID, err)
Expand Down Expand Up @@ -544,24 +544,28 @@ func randomDigits(count int) string {
return string(res)
}

func (s *serviceInteractor) arePendingPaymentsPresent(ctx context.Context, debitorID int64) (bool, error) {
func (s *serviceInteractor) arePendingPaymentsPresent(ctx context.Context, debitorID int64, requestedPaymentMethod entities.PaymentMethod) (bool, error) {
transactions, err := s.store.GetTransactionsByFilter(ctx, entities.TransactionQuery{DebitorID: debitorID})
if err != nil {
return false, err
}

// check if there are any existing transactions of type payment, and return if they are
// in pending or tentative state
// in pending state
for _, tt := range transactions {
switch tt.TransactionStatus {
case entities.TransactionStatusPending, entities.TransactionStatusTentative:
case entities.TransactionStatusPending:
if tt.TransactionType == entities.TransactionTypePayment {
return true, nil
}
case entities.TransactionStatusTentative:
if tt.TransactionType == entities.TransactionTypePayment && tt.PaymentMethod == requestedPaymentMethod {
return true, nil
}
}
}

// no pending payment transactions
// no pending payment transactions, and no tentative transactions of the same type
return false, nil
}

Expand Down

0 comments on commit ac8df05

Please sign in to comment.