Skip to content

Commit

Permalink
Add Stripe API Key settings to close #11
Browse files Browse the repository at this point in the history
Removes the hardcoded API key and replaces it with a new Settings
page in the backend. Also adds a setting for the active keyset,
in case anyone wants to use test mode while in production.
  • Loading branch information
dshoreman committed Oct 18, 2014
1 parent 413d402 commit d3fbc5e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ public function registerPermissions()
];
}

public function registerSettings()
{
return [
'settings' => [
'label' => 'Stripe Settings',
'description' => 'Manage your Stripe API keys.',
'category' => 'Shop',
'icon' => 'icon-credit-card',
'class' => 'Dshoreman\Shop\Models\Settings',
'order' => 200,
],
];
}

}
13 changes: 13 additions & 0 deletions models/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php namespace Dshoreman\Shop\Models;

use Model;

class Settings extends Model {

public $implement = ['System.Behaviors.SettingsModel'];

public $settingsCode = 'dshoreman_shop_settings';

public $settingsFields = 'fields.yaml';

}
26 changes: 26 additions & 0 deletions models/settings/fields.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ===================================
# Form Field Definitions
# ===================================

fields:
stripe_active_keys:
label: Active Stripe
type: dropdown
options:
test: Development
live: Production
tabs:
fields:
stripe_test_sec_key:
label: Secret Key
tab: Development
stripe_test_pub_key:
label: Publishable Key
tab: Development

stripe_live_sec_key:
label: Secret Key
tab: Production
stripe_live_pub_key:
label: Publishable Key
tab: Production
5 changes: 4 additions & 1 deletion routes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use DShoreman\Shop\Models\Order as ShopOrder;
use DShoreman\Shop\Models\Settings;

Route::group(['prefix' => 'shop'], function()
{
Expand Down Expand Up @@ -32,7 +33,9 @@
$order->shipping_postcode = post('stripeShippingAddressZip');
$order->shipping_country = post('stripeShippingAddressCountry');

Stripe::setApiKey('sk_test_NHbBmLzRSL7G06gpyLVraQ2Z');
Settings::get('stripe_active_keys') == 'live'
? Stripe::setApiKey(Settings::get('stripe_live_sec_key'))
: Stripe::setApiKey(Settings::get('stripe_test_sec_key'));

try {
$charge = Stripe_Charge::create([
Expand Down

0 comments on commit d3fbc5e

Please sign in to comment.