1. Go to this page and download the library: Download rias/craft-stripe-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/ */
rias / craft-stripe-webhooks example snippets
return [
/*
* Stripe will sign each webhook using a secret. You can find the used secret at the
* webhook configuration settings: https://dashboard.stripe.com/account/webhooks.
*/
'signingSecret' => '',
/*
* You can define the job that should be run when a certain webhook hits your application
* here. The key is the name of the Stripe event type with the `.` replaced by a `_`.
*
* You can find a list of Stripe webhook types here:
* https://stripe.com/docs/api#event_types.
*/
'jobs' => [
// 'source_chargeable' => \modules\sitemodule\jobs\StripeWebhooks\HandleChargeableSource::class,
// 'charge_failed' => \modules\sitemodule\jobs\StripeWebhooks\HandleFailedCharge::class,
],
/*
* The classname of the model to be used. The class should equal or extend
* rias\stripewebhooks\records\StripeWebhookCall.
*/
'model' => \rias\stripewebhooks\records\StripeWebhookCall::class,
/*
* The url of the Stripe endpoint you want to use in your application
*/
'endpoint' => 'stripe-webhooks',
];
namespace modules\sitemodule\jobs\StripeWebhooks;
use Craft;
use craft\queue\BaseJob;
class HandleChargeableSource extends BaseJob
{
/** @var \rias\stripewebhooks\records\StripeWebhookCall */
public $model;
public function execute($queue)
{
// do your work here
// you can access the payload of the webhook call with `$this->model->payload`
}
}