瀏覽代碼

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

Laurent Destailleur 8 年之前
父節點
當前提交
caae7e4171

+ 2 - 1
htdocs/langs/en_US/paypal.lang

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

+ 1 - 1
htdocs/langs/en_US/stripe.lang

@@ -39,4 +39,4 @@ 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
-StripeLiveEnabled=Stripe live enabled
+StripeLiveEnabled=Stripe live enabled (otherwise test/sandbox mode)

+ 28 - 7
htdocs/paypal/admin/paypal.php

@@ -44,8 +44,6 @@ if ($action == 'setvalue' && $user->admin)
 {
 	$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);
     if (! $result > 0) $error++;
     $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
@@ -127,13 +140,21 @@ print '<td>'.$langs->trans("AccountParameter").'</td>';
 print '<td>'.$langs->trans("Value").'</td>';
 print "</tr>\n";
 
-
-print '<tr class="oddeven"><td class="fieldrequired">';
-print $langs->trans("PAYPAL_API_SANDBOX").'</td><td>';
-print $form->selectyesno("PAYPAL_API_SANDBOX",$conf->global->PAYPAL_API_SANDBOX,1);
+print '<tr class="oddeven">';
+print '<td class="titlefield fieldrequired">';
+print $langs->trans("PaypalLiveEnabled").'</td><td>';
+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 '<tr class="oddeven"><td class="fieldrequired">';
 print $langs->trans("PAYPAL_API_USER").'</td><td>';
 print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.$conf->global->PAYPAL_API_USER.'">';

+ 1 - 1
htdocs/public/paypal/newpayment.php

@@ -265,7 +265,7 @@ $conf->dol_hide_leftmenu=1;
 
 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');
 }

+ 4 - 3
htdocs/public/stripe/newpayment.php

@@ -49,6 +49,7 @@ $langs->load("main");
 $langs->load("companies");
 $langs->load("other");
 $langs->load("paybox");     // File with generic data
+$langs->load("paypal");
 $langs->load("stripe");
 
 $action=GETPOST('action','alpha');
@@ -300,12 +301,12 @@ if ($action == 'charge')
     
     if ($error)
     {
-        header("Location: ".DOL_URL_ROOT.'/public/stripe/paymentko.php?FULLTAG='.urlencode($FULLTAG));
+        header("Location: ".$urlko);
         exit;
     }
     else
     {
-        header("Location: ".DOL_URL_ROOT.'/public/stripe/paymentok.php?FULLTAG='.urlencode($FULLTAG));
+        header("Location: ".$urlok);
         exit;
     }
     
@@ -324,7 +325,7 @@ $conf->dol_hide_leftmenu=1;
 
 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');
 }

+ 1 - 0
htdocs/stripe/admin/stripe.php

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