Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Multipayment Gateways Laravel Package

musahmusah/laravel-multipayment-gateways

View on GitHub
Deep Wiki
Context7

Paystack Webhook

By following the instructions below, you can effectively manage paystack webhook events.

Config Setup

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' => 'paystack',
    
     /**
     * 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('PAYSTACK_SECRET'),

    /*
     * This refers to the header that holds the signature.
     */
    'signature_header_name' => 'HTTP_X_PAYSTACK_SIGNATURE',

    /*
     * 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\DefaultSignatureValidator::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' => '',
]

Paystack Signature Validator

The package ships with a default signature validator for paystack which is used as shown below:

'signature_validator' => \MusahMusah\LaravelMultipaymentGateways\SignatureValidator\DefaultSignatureValidator::class,

Custom Signature Validator

To use a custom class for signature validation, create a class that implements the MusahMusah\LaravelMultipaymentGateways\SignatureValidator\PaymentWebhookSignatureValidator interface. Then ensure to update the paystack webhook config to use your custom class as illustrated below.

'signature_validator' => YourCustomSignatureValidator::class,

Disabling Signature Validation

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.

Webhook Handler

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',

Handle Webhook Using Job

To manage paystack 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' => YourCustomPaystackWebhookJob::class,

Sample Usage:

use MusahMusah\LaravelMultipaymentGateways\Jobs\ProcessPaymentWebhookJob;

class YourCustomPaystackWebhookJob extends ProcessPaymentWebhookJob implements ShouldQueue
{
    public function handle()
    {
        // Get the webhook data
        $webhookData = $this->webhookPayload;
        
        // Handle the webhook
    }
}

Handle Webhook Using Event

To manage paystack 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\YourCustomPaystackWebhookListener;

protected $listen = [
    PaymentWebhookReceivedEvent::class => [
        YourCustomPaystackWebhookListener::class,
    ],
];

Sample Usage:

use MusahMusah\LaravelMultipaymentGateways\Events\PaymentWebhookReceivedEvent;
class YourCustomPaystackWebhookListener
{
    public function handle(PaymentWebhookReceivedEvent $event)
    {
        // Get the webhook data
        $webhookData = $event->webhookPayload;
      
        // Handle the webhook
    }
}

Route Setup

To include the paystack webhook route, follow the example below and add the route to your api.php file:

use Illuminate\Support\Facades\Route;

Route::webhooks('/paystack/webhook', 'paystack');
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope