Skip to content

Fix: Payment Verification Error Handling#234

Open
iRahmanG wants to merge 2 commits into
rdodiya:gssoc_developfrom
iRahmanG:fix/payment-verification-validation
Open

Fix: Payment Verification Error Handling#234
iRahmanG wants to merge 2 commits into
rdodiya:gssoc_developfrom
iRahmanG:fix/payment-verification-validation

Conversation

@iRahmanG
Copy link
Copy Markdown
Contributor

Summary

This PR fixes the issue in PaymentServiceImpl where markPaymentAsVerified and markPaymentAsCancelled silently ignored invalid paymentId values.
Now, both methods throw PaymentNotFoundException when the payment record is missing.

Changes

  • Replaced ifPresent with orElseThrow in both methods
  • Added warning logs when paymentId is not found
  • Introduced PaymentNotFoundException for clear error reporting
  • Ensured success logs confirm updates when records are found

Issue Reference

Fixes: #223

…g in markPaymentAsVerified and markPaymentAsCancelled
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #223 by ensuring payment status update operations no longer fail silently when a paymentId doesn’t exist, improving correctness and observability in the payment verification flow.

Changes:

  • Updated markPaymentAsVerified and markPaymentAsCancelled to throw when no payment record is found (replacing ifPresent with orElseThrow).
  • Added warning + success logs around payment status updates.
  • Introduced a dedicated PaymentNotFoundException.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
RestroHub/src/main/java/com/restroly/qrmenu/payment/service/PaymentServiceImpl.java Switches from silent no-op to exception-based handling when paymentId is missing; adds logs for not-found and success paths.
RestroHub/src/main/java/com/restroly/qrmenu/payment/exception/PaymentNotFoundException.java Adds a new exception type intended to represent a missing payment record.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +7
package com.restroly.qrmenu.payment.exception;

public class PaymentNotFoundException extends RuntimeException {
public PaymentNotFoundException(String message) {
super(message);
}
}

PaymentVerification entity = verificationRepository.findByPaymentId(paymentId)
.orElseThrow(() ->{
log.warn("PaymentId: {} not found in database",paymentId);

PaymentVerification entity = verificationRepository.findByPaymentId(paymentId)
.orElseThrow(() -> {
log.warn("PaymentId: {} not found in database",paymentId);
Comment on lines +111 to +115
PaymentVerification entity = verificationRepository.findByPaymentId(paymentId)
.orElseThrow(() ->{
log.warn("PaymentId: {} not found in database",paymentId);
return new PaymentNotFoundException("Payment record not found for paymentId: " + paymentId);
});
@rdodiya
Copy link
Copy Markdown
Owner

rdodiya commented May 31, 2026

Hi @iRahmanG ,
Please review above points and provide necessary code changes

@iRahmanG
Copy link
Copy Markdown
Contributor Author

Hi @rdodiya

I’ve updated PaymentNotFoundException to extend ResourceNotFoundException instead of RuntimeException.
This ensures it is consistently handled by the GlobalExceptionHandler and now returns a proper 404 Not Found response instead of falling back to the generic 500 error.
Also fixed the space formatting.

Thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: markPayment methods fail silently

3 participants