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
.
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.
The following config options can be set :
credentials
#stripeTestCredentialsPK
stringstripeTestCredentialsSK
stringstripeLiveCredentialsPK
stringstripeLiveCredentialsSK
stringstripeDefaultCurrency
stringusd
mode
#stripeAccountMode
string, live
or test
charges
#template
stringpayment/_detail
urlFormat
stringpayment/thanks/{hash}
connect
#enabled
booldevClientId
stringprodClientId
stringlogs
#enabled
boolretention
int24
. Pass 0
to retain forever. Logs can still be cleared manually in the CP.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
]
],
];