# Installation

First, grab the latest stable version via composer:

```bash
$ composer require r4nkt/laravel-r4nkt-sdk
```

The service provider will automatically register itself.

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

```bash
php artisan vendor:publish --provider="R4nkt\\LaravelR4nkt\\LaravelR4nktServiceProvider" --tag="laravel-r4nkt-sdk-config"
```

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

```php
return [

    /*
    |--------------------------------------------------------------------------
    | Base URL
    |--------------------------------------------------------------------------
    |
    | This determines the base URL for the API that the SDK will use. Generally
    | speaking, you shouldn't ever need to set or change.
    |
    */

    'base_url' => env('R4NKT_BASE_URL', 'https://api.r4nkt.com/v1'),

    /*
    |--------------------------------------------------------------------------
    | 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 implement
    | `R4nkt\Laravel\Support\CustomPlayerIdResolver\CustomPlayerIdResolver`
    |
    */

    'custom_player_id_resolver' => \R4nkt\Laravel\Support\CustomPlayerIdResolver\PrimaryKeyCustomPlayerIdResolver::class,

    /*
    |--------------------------------------------------------------------------
    | Custom Player ID Decoder
    |--------------------------------------------------------------------------
    |
    | This class is responsible for decoding the player's custom ID.
    |
    | This class should implement
    | `R4nkt\Laravel\Support\CustomPlayerIdDecoder\CustomPlayerIdDecoder`
    |
    */

    'custom_player_id_decoder' => \R4nkt\Laravel\Support\CustomPlayerIdDecoder\PrimaryKeyCustomPlayerIdDecoder::class,

    /*
    |--------------------------------------------------------------------------
    | Date/Time UTC Resolver
    |--------------------------------------------------------------------------
    |
    | This class is responsible for resolving the date/time UTC value to a
    | properly formatted string.
    |
    | This class should implement
    | `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:

```php
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:

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

{% hint style="info" %}
Both the webhook secret and URL values can be found on the games management page.
{% endhint %}

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.r4nkt.com/laravel-package/installation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
