NEW It's easier to switch between sandbox and live for paypal

This commit is contained in:
Laurent Destailleur 2017-05-14 17:05:13 +02:00
parent 998254d9c6
commit caae7e4171
6 changed files with 37 additions and 13 deletions

View File

@ -29,3 +29,4 @@ ShortErrorMessage=Short Error Message
ErrorCode=Error Code ErrorCode=Error Code
ErrorSeverityCode=Error Severity Code ErrorSeverityCode=Error Severity Code
OnlinePaymentSystem=Online payment system OnlinePaymentSystem=Online payment system
PaypalLiveEnabled=Paypal live enabled (otherwise test/sandbox mode)

View File

@ -39,4 +39,4 @@ STRIPE_TEST_SECRET_KEY=Secret test key
STRIPE_TEST_PUBLISHABLE_KEY=Publishable test key STRIPE_TEST_PUBLISHABLE_KEY=Publishable test key
STRIPE_LIVE_SECRET_KEY=Secret live key STRIPE_LIVE_SECRET_KEY=Secret live key
STRIPE_LIVE_PUBLISHABLE_KEY=Publishable live key STRIPE_LIVE_PUBLISHABLE_KEY=Publishable live key
StripeLiveEnabled=Stripe live enabled StripeLiveEnabled=Stripe live enabled (otherwise test/sandbox mode)

View File

@ -44,8 +44,6 @@ if ($action == 'setvalue' && $user->admin)
{ {
$db->begin(); $db->begin();
$result=dolibarr_set_const($db, "PAYPAL_API_SANDBOX",GETPOST('PAYPAL_API_SANDBOX','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
if (! $result > 0) $error++; if (! $result > 0) $error++;
$result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST('PAYPAL_API_PASSWORD','alpha'),'chaine',0,'',$conf->entity); $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST('PAYPAL_API_PASSWORD','alpha'),'chaine',0,'',$conf->entity);
@ -85,6 +83,21 @@ if ($action == 'setvalue' && $user->admin)
} }
} }
if ($action=="setlive")
{
$liveenable = GETPOST('value','int')?0:1;
$res = dolibarr_set_const($db, "PAYPAL_API_SANDBOX", $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 * View
@ -127,13 +140,21 @@ print '<td>'.$langs->trans("AccountParameter").'</td>';
print '<td>'.$langs->trans("Value").'</td>'; print '<td>'.$langs->trans("Value").'</td>';
print "</tr>\n"; print "</tr>\n";
print '<tr class="oddeven">';
print '<tr class="oddeven"><td class="fieldrequired">'; print '<td class="titlefield fieldrequired">';
print $langs->trans("PAYPAL_API_SANDBOX").'</td><td>'; print $langs->trans("PaypalLiveEnabled").'</td><td>';
print $form->selectyesno("PAYPAL_API_SANDBOX",$conf->global->PAYPAL_API_SANDBOX,1); if (empty($conf->global->PAYPAL_API_SANDBOX))
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=0">';
print img_picto($langs->trans("Activated"),'switch_on');
}
else
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=setlive&value=1">';
print img_picto($langs->trans("Disabled"),'switch_off');
}
print '</td></tr>'; print '</td></tr>';
print '<tr class="oddeven"><td class="fieldrequired">'; print '<tr class="oddeven"><td class="fieldrequired">';
print $langs->trans("PAYPAL_API_USER").'</td><td>'; print $langs->trans("PAYPAL_API_USER").'</td><td>';
print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.$conf->global->PAYPAL_API_USER.'">'; print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.$conf->global->PAYPAL_API_USER.'">';

View File

@ -265,7 +265,7 @@ $conf->dol_hide_leftmenu=1;
llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody');
if (! empty($PAYPAL_API_SANDBOX)) if (! empty($conf->global->PAYPAL_API_SANDBOX))
{ {
dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning');
} }

View File

@ -49,6 +49,7 @@ $langs->load("main");
$langs->load("companies"); $langs->load("companies");
$langs->load("other"); $langs->load("other");
$langs->load("paybox"); // File with generic data $langs->load("paybox"); // File with generic data
$langs->load("paypal");
$langs->load("stripe"); $langs->load("stripe");
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
@ -300,12 +301,12 @@ if ($action == 'charge')
if ($error) if ($error)
{ {
header("Location: ".DOL_URL_ROOT.'/public/stripe/paymentko.php?FULLTAG='.urlencode($FULLTAG)); header("Location: ".$urlko);
exit; exit;
} }
else else
{ {
header("Location: ".DOL_URL_ROOT.'/public/stripe/paymentok.php?FULLTAG='.urlencode($FULLTAG)); header("Location: ".$urlok);
exit; exit;
} }
@ -324,7 +325,7 @@ $conf->dol_hide_leftmenu=1;
llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody'); llxHeader($head, $langs->trans("PaymentForm"), '', '', 0, 0, '', '', '', 'onlinepaymentbody');
if (! empty($STRIPE_API_SANDBOX)) if (empty($conf->global->STRIPE_LIVE))
{ {
dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning'); dol_htmloutput_mesg($langs->trans('YouAreCurrentlyInSandboxMode'),'','warning');
} }

View File

@ -93,6 +93,7 @@ if ($action=="setlive")
} }
} }
/* /*
* View * View
*/ */