Installation

First, grab the latest stable version via composer:

$ composer require r4nkt/laravel-r4nkt

The service provider will automatically register itself.

To publish the configuration file, you must use the following command:

$ php artisan vendor:publish --provider="R4nkt\LaravelWebhooks\R4nktServiceProvider" --tag="config"

Here are the contents of the new configuration file, config/r4nkt.php:

return [
/*
|--------------------------------------------------------------------------
| API Token
|--------------------------------------------------------------------------
|
| R4nkt requires that you use an API token when communicating with its API.
| Make one at the r4nkt API settings page: https://r4nkt.com/settings#/api
|
*/
'api_token' => env('R4NKT_API_TOKEN'),
/*
|--------------------------------------------------------------------------
| Game ID
|--------------------------------------------------------------------------
|
| R4nkt also requires that you specify the game ID for each API call. Find
| this at the game configuration settings: https://r4nkt.com/settings/games
|
*/
'game_id' => env('R4NKT_GAME_ID'),
/*
|--------------------------------------------------------------------------
| Webhook Signing Secret
|--------------------------------------------------------------------------
|
| R4nkt will sign webhooks using a secret. You can find the secret used for
| individual games at the game configuration settings:
| - https://r4nkt.com/settings/games
|
*/
'signing_secret' => env('R4NKT_SIGNING_SECRET'),
/*
|--------------------------------------------------------------------------
| Custom Player ID Resolver
|--------------------------------------------------------------------------
|
| This class is responsible for determining the player's custom ID.
|
| This class should extend
| `R4nkt\Laravel\Support\CustomPlayerIdResolver\CustomPlayerIdResolver`
|
*/
'custom_player_id_resolver' => \R4nkt\Laravel\Support\CustomPlayerIdResolver\PrimaryKeyCustomPlayerIdResolver::class,
/*
|--------------------------------------------------------------------------
| Date/Time UTC Resolver
|--------------------------------------------------------------------------
|
| This class is responsible for resolving the date/time UTC value to a
| properly formatted string.
|
| This class should extend
| `R4nkt\Laravel\Support\DateTimeUtcResolver\DateTimeUtcResolver`
|
*/
'date_time_utc_resolver' => \R4nkt\Laravel\Support\DateTimeUtcResolver\DefaultDateTimeUtcResolver::class,
/*
|--------------------------------------------------------------------------
| Webhook Jobs
|--------------------------------------------------------------------------
|
| Here you can define the job that should be run when a certain webhook
| hits your application.
|
| You can find a list of R4nkt webhook types here:
| - https://r4nkt.com/docs/webhooks/events
|
*/
'jobs' => [
// 'badge-earned' => \App\Jobs\R4nktWebhooks\HandleBadgeEarned::class,
// ...
],
];

You should set the signing_secret value for the specific game you are interested in receiving webhooks from.

Finally, you should set up routing. The route that is set up here should match the webhook URL for the specific game you are interested in receiving webhooks from. To do so, you must pass this route using the following command in your app's routes file:

Route::R4nktWebhooks('configured-webhook-route');

This command registers a POST route to a package controller.

Because r4nkt has no way of getting a CSRF token, you must add that route to the $except array of the VerifyCsrfToken middleware like so:

protected $except = [
'configured-webhook-route',
];

Both the webhook secret and URL values can be found on the games management page.