Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Timeout Handling to verify() Method with Custom Exception #263

Merged
merged 4 commits into from
Sep 4, 2024

Conversation

alissn
Copy link
Contributor

@alissn alissn commented Aug 31, 2024

Description

After meeting with the technical team of SnappPay, want to add a timeout of 60 seconds to the verify() method. If the timeout is reached, the method should then call GetPaymentStatus (handled by the driver's status() method) to retrieve the payment status.

on catch timeout, check status of transaction, if status is VERIFY return Receipt. else throw exception.

To handle this scenario, a new exception named TimeoutException has been introduced. This exception extends from PurchaseFailedException, ensuring that the existing project logic does not require changes.

Here's an example of how the exception can be used:

// At the top of the file.
use Shetabit\Multipay\Payment;
use Shetabit\Multipay\Exceptions\InvalidPaymentException;
use Shetabit\Multipay\Exceptions\TimeoutException;
use Shetabit\Multipay\Exceptions\PurchaseFailedException;

try {
    $receipt = $payment->amount(1000)->transactionId($transaction_id)->verify();

    echo $receipt->getReferenceId();

    ...
} catch (TimeoutException $exception) {
    echo $exception->getMessage();
} catch (PurchaseFailedException $exception) {
    echo $exception->getMessage();
} catch (InvalidPaymentException $exception) {
    echo $exception->getMessage();
}

If TimeoutException is not caught, it will be handled by PurchaseFailedException.

How Has This Been Tested?

The method was tested using the oauth() function. When the timeout was set to 0.01, a GuzzleHttp\Exception\ConnectException was thrown. When the timeout was set to 2 seconds, a driver-specific error was returned.

Screenshots of the testing process are provided:
Testing Timeout
Driver Error

Types of Changes

Please put an x in the relevant boxes:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@alissn
Copy link
Contributor Author

alissn commented Sep 3, 2024

@khanzadimahdi
it's ready to merge. I changed Exception name.

@khanzadimahdi khanzadimahdi merged commit d7b075d into shetabit:master Sep 4, 2024
2 checks passed
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.

2 participants