Usage
Generators

Laravel SISP allows you to easily customize and extend its functionality. One of the key ways you can extend it is by creating your own custom generators. These generators are responsible for generating specific data used during payment requests, such as merchant session IDs, transaction references, timestamps, etc.

In this guide, we will walk you through how to create a custom generator and add it to the config/sisp.php configuration file.

Create the Custom Generator

To create a custom generator, you will need to create a new action class that implements the logic for generating the required data. You can place this class anywhere within your Laravel application, but we recommend storing it in the app/Actions/Generators directory.

Here’s an example of a custom generator that creates a unique order ID:

Create a new file named OrderReferenceAction.php in the app/Actions/Generators directory:

<?php
 
namespace App\Actions\Generators;
 
use Akira\Sisp\Contracts\Generator;
 
class OrderReferenceAction implements Generator
{
 
   public function __invoke(): string
    {
        // Generate a unique order reference
        return 'ORDER-' . uniqid();
    }
}

Register the Generator in the Configuration

Now that we have our custom generator class, we need to tell Laravel SISP to use it. You do this by adding the generator to the generators array in the config/sisp.php configuration file.

//...
'generators' => [
       //...
        'merchantReference' => OrderReferenceAction::class,
      // ...
    ],
//...

this will replace the default merchantReference generator with your custom OrderReferenceAction generator.