Usage
Events

Payment Status

Once the payment process is completed, the user will be redirected to the merchant response URL, as specified in your sisp.php config file (urlMerchantResponse). This URL will inform your application of the transaction's outcome, allowing you to take appropriate actions based on the payment status.

Success

When the payment is successful, a SispPaymentSuccess event will be triggered.

You can listen for this event and execute any necessary actions such as updating the order status, sending confirmation emails, or notifying the user about the successful transaction.

Here’s an example of how you can listen for the SispPaymentSuccess event and handle the success response:

// Example of handling a successful payment
 
use Illuminate\Support\Facades\Event;
 
Event::listen('SispPaymentSuccess', function ($data) {
    // Handle successful payment
    // For example:
    // - Update the order status in the database
    // - Send a confirmation email to the user
    // - Log the payment details for records
});

Or you can make a listener with the command:

php artisan make:listener SispPaymentSuccessListener

Then, in the handle method of the listener, you can implement the logic to handle the successful payment.

final class SispPaymentSuccessListener
{
 
    public function handle(SispPaymentRequestSuccess $event): void
    {
        // Handle successful payment
        // For example:
        // - Update the order status in the database
        // - Send a confirmation email to the user
        // - Log the payment details for records
    }
}
 

By listening to the SispPaymentSuccess event, you can implement the next steps in the payment workflow, ensuring that your users have a smooth experience post-payment.

Failed

If the payment fails (due to reasons like insufficient funds, technical errors, or invalid payment details), a SispPaymentFailed event will be triggered. By listening for this event, you can handle the failure scenario appropriately, such as notifying the user about the failure, logging the error for debugging, or offering the option to retry the payment.

Here’s how you can listen for the SispPaymentFailed event and perform actions when the payment fails:

// Example of handling a failed payment
 
use Illuminate\Support\Facades\Event;
 
Event::listen('SispPaymentFailed', function ($data) {
    // Handle failed payment
    // For example:
    // - Notify the user about the payment failure
    // - Log the error for debugging
    // - Optionally allow the user to retry the payment
});

Or you can make a listener with the command:

php artisan make:listener SispPaymentFailedListener

Then, in the handle method of the listener, you can implement the logic to handle the failed payment.

final class SispPaymentFailedListener
{
 
    public function handle(SispPaymentRequestFailed $event): void
    {
        // Handle failed payment
        // For example:
        // - Notify the user about the payment failure
        // - Log the error for debugging
        // - Optionally allow the user to retry the payment
    }
}
 

By responding to a failed payment, you can guide the user to resolve the issue and keep the payment process smooth and user-friendly.

Cancelled by User

If the user decides to cancel the payment, a SispPaymentCancelledByUser event will be triggered. You can listen for this event to take necessary actions, such as updating the order status, informing the user, or offering alternative payment options.

Here's an example of how you can listen for the SispPaymentCancelledByUser event and handle the cancellation:

// Example of handling payment cancellation by the user
 
use Illuminate\Support\Facades\Event;
 
Event::listen('SispPaymentCancelledByUser', function ($data) {
    // Handle payment cancellation by the user
    // For example:
    // - Update order status to 'Cancelled'
    // - Notify the user that the payment was not completed
    // - Provide options for the user to retry the payment or choose another method
});
 

Or you can make a listener with the command:

php artisan make:listener SispPaymentCancelledByUserListener

Then, in the handle method of the listener, you can implement the logic to handle the payment cancellation by the user.

final class SispPaymentCancelledByUserListener
{
 
    public function handle(SispPaymentRequestCancelledByUser $event): void
    {
        // Handle payment cancellation by the user
        // For example:
        // - Update order status to 'Cancelled'
        // - Notify the user that the payment was not completed
        // - Provide options for the user to retry the payment or choose another method
    }
}
 

This gives you the flexibility to handle user cancellations appropriately, ensuring a seamless and responsive user experience

Cancelled for Other Reasons

If the payment is cancelled for reasons beyond the user's control (such as a timeout, system errors, or other unforeseen issues), a SispPaymentCancelled event will be triggered. By listening for this event, you can handle unexpected cancellations in a smooth and professional manner, ensuring that the user is informed and the system behaves as expected.

Here’s how you can listen for the SispPaymentCancelled event and take necessary actions:

// Example of handling payment cancellation for other reasons
 
use Illuminate\Support\Facades\Event;
 
Event::listen('SispPaymentCancelled', function ($data) {
    // Handle unexpected payment cancellation
    // For example:
    // - Notify the user about the cancellation
    // - Log the issue for troubleshooting
    // - Optionally offer the user a chance to try again
});

Or you can make a listener with the command:

php artisan make:listener SispPaymentCancelledListener

Then, in the handle method of the listener, you can implement the logic to handle the unexpected payment cancellation.

final class SispPaymentCancelledListener
{
 
    public function handle(SispPaymentRequestCancelled $event): void
    {
        // Handle unexpected payment cancellation
        // For example:
        // - Notify the user about the cancellation
        // - Log the issue for troubleshooting
        // - Optionally offer the user a chance to try again
    }
}
 

This allows you to maintain control over the user experience and troubleshoot any unexpected issues that arise during the payment process.

Learn More About Laravel Events

Laravel’s powerful event system allows you to listen for various outcomes of the payment process, enabling you to automate actions based on the payment’s status. Whether it’s a successful payment, a failure, a cancellation by the user, or an unexpected issue, you can easily respond to these events to enhance your application's functionality.

For more detailed information on how to work with events in Laravel, check out the official Laravel Events documentation (opens in a new tab).

By leveraging Laravel events, you can:

  • Tailor the user experience: Customize how users are notified or redirected based on payment outcomes.
  • Manage transactions effectively: Automate processes like updating order statuses or logging payment history.
  • Ensure smooth payment processing: Handle errors or cancellations promptly to maintain a seamless payment experience.

Implementing Laravel events in your payment flow will help you create a more robust and responsive payment system for your users.