Recommended way to include API keys in a multi-environment configuration? What is the recommended way to configure public api keys for multi-environment configurations (i.e. local, dev, stage, production)? Is there a way to set these in either the craft/config/general.php or in plugin/config.php files?

Currently I am having to include these in each of my service methods (and something similar again in my javascript files):

private function _saveStripeCustomer($account, $token = NULL)
{
    \Stripe::setApiKey("sk_test_xxxxxxxxxxxxxxxxxx");
    // ...
}


I am generally following the configuration method shown here (both multi-environment and multi-locale). And a plugin config.php as described here.
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(
    '*' =&gt; array(
      ...
    ),

    'local' =&gt; array(
        'myplugin_stripe_key' =&gt; 'sk_test_xxxxxxxxxxxxxxxxxx',
        ...
    ),

    'stage' =&gt; array(
        'myplugin_stripe_key' =&gt; 'sk_stage_xxxxxxxxxxxxxxxxxx',
        ...
    ),

    'prod' =&gt; array(
        'myplugin_stripe_key' =&gt; 'sk_prod_xxxxxxxxxxxxxxxxxx',
        ...
    )
);


In your plugin:

private function _saveStripeCustomer($account, $token = NULL)
{
  \Stripe::setApiKey(craft()-&gt;config-&gt;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-&gt;settings = $this-&gt;_initSettings();
    }

    private function _initSettings()
    {
        $settings = array();
        $settings['myplugin_stripe_key'] = craft()-&gt;config-&gt;get('myplugin_stripe_key');
        return $settings;
    }
}


Then you can access them later like this:

\Stripe::setApiKey($this-&gt;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.