PHP code example of vanthao03596 / laravel-paddle-webhooks
1. Go to this page and download the library: Download vanthao03596/laravel-paddle-webhooks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
vanthao03596 / laravel-paddle-webhooks example snippets
return [
/*
* Paddle will sign each webhook using a public key to create signature . You can find the used public key at the
* webhook configuration settings: https://vendors.paddle.com/public-key.
*/
'signing_secret' => env('PADDLE_PUBLIC_KEY'),
/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Paddle event type.
*
* You can find a list of Paddle webhook types here:
* https://developer.paddle.com/webhook-reference/intro.
*/
'jobs' => [
// 'subscription_created' => \App\Jobs\PaddleWebhooks\HandleSubscriptionCreated::class,
// 'payment_succeeded' => \App\Jobs\PaddleWebhooks\HandlePaymentSucceeded::class,
],
/*
* The classname of the model to be used. The class should equal or extend
* Vanthao03596\PaddleWebhooks\ProcessPaddleWebhookJob.
*/
'model' => \Vanthao03596\PaddleWebhooks\ProcessPaddleWebhookJob::class,
/**
* This class determines if the webhook call should be stored and processed.
*/
'profile' => \Spatie\WebhookClient\WebhookProfile\ProcessEverythingWebhookProfile::class,
/*
* When disabled, the package will not verify if the signature is valid.
* This can be handy in local environments.
*/
'verify_signature' => env('PADDLE_SIGNATURE_VERIFY', true),
];
namespace App\Jobs\PaddleWebhooks;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class HandleChargeableSource implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
/** @var \Spatie\WebhookClient\Models\WebhookCall */
public $webhookCall;
public function __construct(WebhookCall $webhookCall)
{
$this->webhookCall = $webhookCall;
}
public function handle()
{
// do your work here
// you can access the payload of the webhook call with `$this->webhookCall->payload`
}
}
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'paddle-webhooks::subscription_created' => [
App\Listeners\ChargeSource::class,
],
];
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;
class ChargeSource implements ShouldQueue
{
public function handle(WebhookCall $webhookCall)
{
// do your work here
// you can access the payload of the webhook call with `$webhookCall->payload`
}
}
use Spatie\WebhookClient\Models\WebhookCall;
use Spatie\PaddleWebhooks\ProcessPaddleWebhookJob;
dispatch(new ProcessPaddleWebhookJob(WebhookCall::find($id)));
use Spatie\PaddleWebhooks\ProcessPaddleWebhookJob;
class MyCustomPaddleWebhookJob extends ProcessPaddleWebhookJob
{
public function handle()
{
// do some custom stuff beforehand
parent::handle();
// do some custom stuff afterwards
}
}
use Illuminate\Http\Request;
use Spatie\WebhookClient\Models\WebhookCall;
use Spatie\WebhookClient\WebhookProfile\WebhookProfile;
class PaddleWebhookProfile implements WebhookProfile
{
public function shouldProcess(Request $request): bool
{
return ! WebhookCall::where('payload->id', $request->get('id'))->exists();
}
}
// secret for when Paddle posts to webhook-url/account
'signing_secret_account' => 'whsec_abc',
// secret for when Paddle posts to webhook-url/connect
'signing_secret_connect' => 'whsec_123',