You can insert whatever settings you need either in your config/general.php file, config/pluginhandle.php, or the plugin/config.php file.
You can have different value for your setting in each of the environments you have defined. If you call your setting myplugin_stripe_key
, you'd put something like this in your config file:
return array(
'*' => array(
...
),
'local' => array(
'myplugin_stripe_key' => 'sk_test_xxxxxxxxxxxxxxxxxx',
...
),
'stage' => array(
'myplugin_stripe_key' => 'sk_stage_xxxxxxxxxxxxxxxxxx',
...
),
'prod' => array(
'myplugin_stripe_key' => 'sk_prod_xxxxxxxxxxxxxxxxxx',
...
)
);
In your plugin:
private function _saveStripeCustomer($account, $token = NULL)
{
\Stripe::setApiKey(craft()->config->get('myplugin_stripe_key'));
// ...
}
If you use this several places in your service, I'd fetch all settings in the constructor and save them in an array:
class MypluginService extends BaseApplicationComponent
{
var $settings = array();
public function __construct($urlRecord = null)
{
$this->settings = $this->_initSettings();
}
private function _initSettings()
{
$settings = array();
$settings['myplugin_stripe_key'] = craft()->config->get('myplugin_stripe_key');
return $settings;
}
}
Then you can access them later like this:
\Stripe::setApiKey($this->settings['myplugin_stripe_key']);
If you need this key in javascript, you could create a craft variable that gets the config setting and output it to a javascript variable somewhere in your twig templates. You'd basically use the same way to get the config variable inside the craft variable method.