Credit types in Spike

Spike works best when selling credits which users can then consume when using the app. Sometimes you may have different areas of usage in your app, and you might want to spend different types of credits in each area. A typical example would be sending emails and SMS. You might want to give different amounts of credits for email and SMS because of their different costs to you as a business. That's where credit types come in.


First, once you decide what types of credits you would like to sell, you can define them in config/spike.php, like so:

    | Credit types
    | You can have multiple types of credits that you can sell and use,
    | like API credits, SMS, emails, etc. Here you can configure the
    | different credit types that will be available for users.

    'credit_types' => [
            // ID is used when referencing the credit type in the code, i.e. `$user->credits('sms')->balance()`.
            'id' => 'credits',

            // The translation key with inflection to use for this credit type.
            'translation_key' => 'spike::translations.credits',

            // The icon for credit type. Leaving this `null` will use the default icon (coins).
            // Accepted values are: URL string (absolute or relative), SVG string, or null.
            'icon' => null,

        // [
        //     'id' => 'sms',
        //     'translation_key' => 'app.sms',
        //     'icon' => null,
        // ],
idstringThe identifier for this credit type. Used in various places, such as $user->credits($id)->balance()
translation_keystringThe path to the translation which describes this credit type. It should include both singular and plural translations separated with the pipe symbol, i.e. credit|credits
iconURL string, SVG string, or nullThe icon displayed in the UI for this credit type.

Empty balances in the UI

Sometimes you may have too many credit types to display them in the billing portal, and most of them will have zero value.

You can hide credit types from the user if they do not have any balance for them. To do that, look at the theme section in the config/spike.php configuration:

    'theme' => [
        // ...

        // Whether to display zero values for credit types that the user did not yet purchase.
        'display_empty_credit_balances' => false,

Using multiple types of credits

To learn how to spend, adjust, or sell the different types of credits, click one of these links:


If you have any questions, feedback, or need any help setting up Spike within your project, feel free to reach out to me.