Skip to content

Commit

Permalink
Merge pull request #653 from laravel/add-publishable-key
Browse files Browse the repository at this point in the history
[10.0] Add publishable key to Cashier
  • Loading branch information
taylorotwell authored Apr 25, 2019
2 parents fe576a2 + d5a0936 commit 65d623d
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ class Cashier
const STRIPE_VERSION = '2019-03-14';

/**
* The Stripe API key.
* The publishable Stripe API key.
*
* @var string
*/
protected static $stripeKey;

/**
* The secret Stripe API key.
*
* @var string
*/
protected static $stripeSecret;

/**
* The current currency.
*
Expand All @@ -43,7 +50,7 @@ class Cashier
protected static $formatCurrencyUsing;

/**
* Get the Stripe API key.
* Get the pulishable Stripe API key.
*
* @return string
*/
Expand All @@ -53,15 +60,15 @@ public static function stripeKey()
return static::$stripeKey;
}

if ($key = getenv('STRIPE_SECRET')) {
if ($key = getenv('STRIPE_KEY')) {
return $key;
}

return config('services.stripe.secret');
return config('services.stripe.key');
}

/**
* Set the Stripe API key.
* Set the publishable Stripe API key.
*
* @param string $key
* @return void
Expand All @@ -71,6 +78,35 @@ public static function setStripeKey($key)
static::$stripeKey = $key;
}

/**
* Get the secret Stripe API key.
*
* @return string
*/
public static function stripeSecret()
{
if (static::$stripeSecret) {
return static::$stripeSecret;
}

if ($key = getenv('STRIPE_SECRET')) {
return $key;
}

return config('services.stripe.secret');
}

/**
* Set the secret Stripe API key.
*
* @param string $key
* @return void
*/
public static function setStripeSecret($key)
{
static::$stripeSecret = $key;
}

/**
* Get the default Stripe API options.
*
Expand All @@ -80,7 +116,7 @@ public static function setStripeKey($key)
public static function stripeOptions(array $options = [])
{
return array_merge([
'api_key' => static::stripeKey(),
'api_key' => static::stripeSecret(),
'stripe_version' => static::STRIPE_VERSION,
], $options);
}
Expand Down

0 comments on commit 65d623d

Please sign in to comment.