From b05d2c50e8b236036ba1e944ec72b92cc33603c9 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Mon, 8 May 2017 06:52:30 +0200 Subject: [PATCH] Add mode live --- htdocs/langs/en_US/stripe.lang | 3 ++- htdocs/public/stripe/config.php | 20 ++++++++++++++++---- htdocs/stripe/admin/stripe.php | 33 +++++++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/htdocs/langs/en_US/stripe.lang b/htdocs/langs/en_US/stripe.lang index f19b4e44a52..3f85dc2d544 100644 --- a/htdocs/langs/en_US/stripe.lang +++ b/htdocs/langs/en_US/stripe.lang @@ -37,4 +37,5 @@ NewStripePaymentFailed=New Stripe payment tried but failed STRIPE_TEST_SECRET_KEY=Secret test key STRIPE_TEST_PUBLISHABLE_KEY=Publishable test key STRIPE_LIVE_SECRET_KEY=Secret live key -STRIPE_LIVE_PUBLISHABLE_KEY=Publishable live key \ No newline at end of file +STRIPE_LIVE_PUBLISHABLE_KEY=Publishable live key +StripeLiveEnabled=Stripe live enabled \ No newline at end of file diff --git a/htdocs/public/stripe/config.php b/htdocs/public/stripe/config.php index b94617b4c69..dfd0ea6aa1a 100644 --- a/htdocs/public/stripe/config.php +++ b/htdocs/public/stripe/config.php @@ -29,9 +29,21 @@ require_once DOL_DOCUMENT_ROOT.'/stripe/lib/stripe.lib.php'; require_once DOL_DOCUMENT_ROOT.'/includes/stripe/init.php'; //use \includes\stripe as stripe; -$stripe = array( - "secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY, - "publishable_key" => $conf->global->STRIPE_TEST_PUBLISHABLE_KEY -); +$stripe = array(); + +if(empty($conf->global->SKYPE_LIVE)) +{ + $stripe = array( + "secret_key" => $conf->global->STRIPE_TEST_SECRET_KEY, + "publishable_key" => $conf->global->STRIPE_TEST_PUBLISHABLE_KEY + ); +} +else +{ + $stripe = array( + "secret_key" => $conf->global->STRIPE_LIVE_SECRET_KEY, + "publishable_key" => $conf->global->STRIPE_LIVE_PUBLISHABLE_KEY + ); +} \includes\stripe::setApiKey($stripe['secret_key']); \ No newline at end of file diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 1882d1065b0..6274197a301 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -1,5 +1,6 @@ + * Copyright (C) 2017 Olivier Geffroy * Copyright (C) 2017 Saasprov * * This program is free software; you can redistribute it and/or modify @@ -45,7 +46,7 @@ if ($action == 'setvalue' && $user->admin) { $db->begin(); - $result=dolibarr_set_const($db, "STRIPE_TEST",GETPOST('STRIPE_TEST','alpha'),'chaine',0,'',$conf->entity); + $result=dolibarr_set_const($db, "STRIPE_LIVE",GETPOST('STRIPE_LIVE','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; $result=dolibarr_set_const($db, "STRIPE_TEST_SECRET_KEY",GETPOST('STRIPE_TEST_SECRET_KEY','alpha'),'chaine',0,'',$conf->entity); if (! $result > 0) $error++; @@ -76,6 +77,20 @@ if ($action == 'setvalue' && $user->admin) } } +if ($action=="setlive") +{ + $liveenable = GETPOST('value','int'); + $res = dolibarr_set_const($db, "STRIPE_LIVE", $liveenable,'yesno',0,'',$conf->entity); + if (! $res > 0) $error++; + if (! $error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} /* * View @@ -119,9 +134,19 @@ print ''.$langs->trans("Value").''; print "\n"; $var=!$var; -print ''; -print $langs->trans("STRIPE_TEST").''; -print $form->selectyesno("STRIPE_TEST",$conf->global->STRIPE_TEST,1); +print ''; +print ''; +print $langs->trans("StripeLiveEnabled").''; +if (!empty($conf->global->STRIPE_LIVE)) +{ + print ''; + print img_picto($langs->trans("Activated"),'switch_on'); +} +else +{ + print ''; + print img_picto($langs->trans("Disabled"),'switch_off'); +} print ''; $var=!$var;