Config Options

In addition to setting the various config options for Charge in your CP, you can specify some settings in a config file.

By setting these options in config file you can version these settings, and enable mutli-enviroment settings. This can be especialy useful run local and testing installs in test mode, while keeping the production version in live.

Setup #

To specify your config settings in a config file, you'll need to create a new config file called charge.php and place it in your site's craft/config/ folder, along side your general.php, db.php and any other config files you might have.

Options #

The following config options can be set :

credentials #

stripeTestCredentialsPK string
Stripe Test Public Key
stripeTestCredentialsSK string
Stripe Test Secret Key
stripeLiveCredentialsPK string
Stripe Live Public Key
stripeLiveCredentialsSK string
Stripe Live Secret Key
stripeDefaultCurrency string
Default Currency. eg. usd

mode #

stripeAccountMode string, live or test
The mode for the stripe payments.

charges #

template string
The template path for the charge element template. eg. payment/_detail
urlFormat string
The format for the charge element urls. eg. payment/thanks/{hash}

connect #

enabled bool
Is connect enabled for the site.
devClientId string
The development client id for the connect application
prodClientId string
The production client id for the connect application

logs #

enabled bool
Are logs enabled for the site
retention int
The number of hours to retain the logs for. Defaults to 24. Pass 0 to retain forever. Logs can still be cleared manually in the CP.

Usage #

The most common setup is to specify your stripe keys in your config file. For this, your charge.php config file would look like :

<?php

return [
    'credentials' => [
        'stripeTestCredentialsSK' => 'sk_test_..........',
        'stripeTestCredentialsPK' => 'pk_test_..........',
        'stripeLiveCredentialsSK' => 'sk_............',
        'stripeLiveCredentialsPK' => 'pk_............',
    ]
];

A more complex setup might be to specify more options, with a multi-enviroment override. This exactly like all craft multi-enviroment options.

The following example will setup the basic charge config using the * option, and then override for various test, and staging domains.

<?php

return [
    '*' => [
        'credentials' => [
            'stripeTestCredentialsSK' => 'sk_test_......',
            'stripeTestCredentialsPK' => 'pk_test_......',
            'stripeLiveCredentialsSK' => 'sk_......',
            'stripeLiveCredentialsPK' => 'pk_......',
        ],
        'mode'        => [
            'stripeAccountMode' => 'live'
        ],
        'logs'        => [
            'enabled'   => true,
            'retention' => 168 // 1 week
        ]
    ],
    'craft.dev' => [
        'mode' => [
            'stripeAccountMode' => 'test'
        ], 
        'logs' => [
            'enabled' => true,
            'retention' => 24 // 1 day
        ]
    ],
    'staging.somedomain.com' => [
        'mode' => [
            'stripeAccountMode' => 'test'
        ],
        'logs' => [
            'enabled' => false
        ]
    ],
];