From d3fbc5e514dc79abc295bf2b3c03a7d38c2a40d0 Mon Sep 17 00:00:00 2001 From: Dave Shoreman Date: Sat, 18 Oct 2014 01:16:42 +0100 Subject: [PATCH] Add Stripe API Key settings to close #11 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. --- Plugin.php | 14 ++++++++++++++ models/Settings.php | 13 +++++++++++++ models/settings/fields.yaml | 26 ++++++++++++++++++++++++++ routes.php | 5 ++++- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 models/Settings.php create mode 100644 models/settings/fields.yaml diff --git a/Plugin.php b/Plugin.php index 2615bf9..8106bfc 100644 --- a/Plugin.php +++ b/Plugin.php @@ -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, + ], + ]; + } + } diff --git a/models/Settings.php b/models/Settings.php new file mode 100644 index 0000000..30e7adc --- /dev/null +++ b/models/Settings.php @@ -0,0 +1,13 @@ + 'shop'], function() { @@ -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([