musahmusah/laravel-multipayment-gateways
By following the instructions below, you can effectively manage flutterwave webhook events.
Ensure that this setup is present inside the multipayment-gateways.php configuration file
[
/*
* This refers to the name of the payment gateway being used.
*/
'name' => 'flutterwave',
/**
* When set to false, the package will not verify the signature of the webhook call.
*/
'verify_signature' => true,
/*
* This secret key is used to validate the signature of the webhook call.
*/
'signing_secret' => env('FLUTTERWAVE_SECRET_HASH'),
/*
* This refers to the header that holds the signature.
*/
'signature_header_name' => 'verif-hash',
/*
* This class is responsible for verifying the validity of the signature header.
*
* It should implement the interface \MusahMusah\LaravelMultipaymentGateways\SignatureValidator\PaymentWebhookSignatureValidator.
*/
'signature_validator' => \MusahMusah\LaravelMultipaymentGateways\SignatureValidator\FlutterwaveSignatureValidator::class,
/**
* The webhook handler option allows you to choose how webhook requests are handled in your application.
*
* Available options:
* - 'job': Webhook requests will be handled by a job.
* - 'event': Webhook requests will be handled by an event.
*
* Default: 'job'
*/
'payment_webhook_handler' => 'job',
/**
* The payment_webhook_job option allows you to specify the job class that will be used to process webhook requests for payment methods.
*
* This should be set to a class that extends \MusahMusah\LaravelMultipaymentGateways\Jobs\ProcessPaymentWebhookJob.
*/
'payment_webhook_job' => '',
/**
* The payment_webhook_event option allows you to specify the event class that will be used to process webhook requests for payment methods.
*
* This should be set to a class that extends \MusahMusah\LaravelMultipaymentGateways\Events\PaymentWebhookReceivedEvent.
*/
'payment_webhook_event' => '',
]
In your .env file ensure this key is set:
FLUTTERWAVE_SECRET_HASH=xxxxxxxxx
The package ships with a default signature validator for flutterwave which is used as shown below:
'signature_validator' => \MusahMusah\LaravelMultipaymentGateways\SignatureValidator\DefaultSignatureValidator::class,
To use a custom class for signature validation, create a class that implements the MusahMusah\LaravelMultipaymentGateways\SignatureValidator\PaymentWebhookSignatureValidator interface. Then ensure to update the flutterwave webhook config to use your custom class as illustrated below.
'signature_validator' => YourCustomSignatureValidator::class,
In case you opt not to validate the webhook events, you can disable the signature validation by setting the verify_signature option to false as shown below:
'verify_signature' => false,
The package will then not verify the signature of the webhook call.
This refers to the approach you wish to adopt for processing the webhook event, either by dispatching a job or an event. By default, we have set the configuration to use a job.
If you prefer to use an event, you can update it following the example provided below.
'payment_webhook_handler' => 'event',
To manage flutterwave webhook events using job, create a job class that extends the MusahMusah\LaravelMultipaymentGateways\Jobs\ProcessPaymentWebhookJob class, and modify the configuration as illustrated below:
'payment_webhook_job' => YourCustomFlutterwaveWebhookJob::class,
Sample Usage:
use MusahMusah\LaravelMultipaymentGateways\Jobs\ProcessPaymentWebhookJob;
class YourCustomFlutterwaveWebhookJob extends ProcessPaymentWebhookJob implements ShouldQueue
{
public function handle()
{
// Get the webhook data
$webhookData = $this->webhookPayload;
// Handle the webhook
}
}
To manage flutterwave webhook events using event, you need to create a listener class that listens to the MusahMusah\LaravelMultipaymentGateways\Events\PaymentWebhookReceived event triggered by the package. Then, you should adjust the configuration settings as shown below:
'payment_webhook_event' => '\MusahMusah\LaravelMultipaymentGateways\Events\PaymentWebhookReceivedEvent',
Register the event listener in the EventServiceProvider class.
use MusahMusah\LaravelMultipaymentGateways\Events\PaymentWebhookReceivedEvent;
use App\Listeners\YourCustomFlutterwaveWebhookListener;
protected $listen = [
PaymentWebhookReceivedEvent::class => [
YourCustomFlutterwaveWebhookListener::class,
],
];
Sample Usage:
use MusahMusah\LaravelMultipaymentGateways\Events\PaymentWebhookReceivedEvent;
class YourCustomFlutterwaveWebhookListener
{
public function handle(PaymentWebhookReceivedEvent $event)
{
// Get the webhook data
$webhookData = $event->webhookPayload;
// Handle the webhook
}
}
To include the flutterwave webhook route, follow the example below and add the route to your api.php file:
use Illuminate\Support\Facades\Route;
Route::webhooks('/flutterwave/webhook', 'flutterwave');
How can I help you explore Laravel packages today?