PageRenderTime 53ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/paypal/admin/paypal.php

https://github.com/asterix14/dolibarr
PHP | 374 lines | 287 code | 53 blank | 34 comment | 35 complexity | 111ebd1e6256f06033a58f4384c8fd97 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.org>
  4. * Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
  5. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/paypal/admin/paypal.php
  22. * \ingroup paypal
  23. * \brief Page to setup paypal module
  24. */
  25. require("../../main.inc.php");
  26. require_once(DOL_DOCUMENT_ROOT."/paypal/lib/paypal.lib.php");
  27. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  28. require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php");
  29. $servicename='PayPal';
  30. $langs->load("admin");
  31. $langs->load("other");
  32. $langs->load("paypal");
  33. $langs->load("paybox");
  34. if (!$user->admin)
  35. accessforbidden();
  36. $action = GETPOST("action");
  37. if ($action == 'setvalue' && $user->admin)
  38. {
  39. $db->begin();
  40. $result=dolibarr_set_const($db, "PAYPAL_API_SANDBOX",GETPOST("PAYPAL_API_SANDBOX"),'chaine',0,'',$conf->entity);
  41. if (! $result > 0) $error++;
  42. $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST("PAYPAL_API_USER"),'chaine',0,'',$conf->entity);
  43. if (! $result > 0) $error++;
  44. $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST("PAYPAL_API_PASSWORD"),'chaine',0,'',$conf->entity);
  45. if (! $result > 0) $error++;
  46. $result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",GETPOST("PAYPAL_API_SIGNATURE"),'chaine',0,'',$conf->entity);
  47. if (! $result > 0) $error++;
  48. $result=dolibarr_set_const($db, "PAYPAL_CREDITOR",GETPOST("PAYPAL_CREDITOR"),'chaine',0,'',$conf->entity);
  49. if (! $result > 0) $error++;
  50. $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",GETPOST("PAYPAL_API_INTEGRAL_OR_PAYPALONLY"),'chaine',0,'',$conf->entity);
  51. if (! $result > 0) $error++;
  52. $result=dolibarr_set_const($db, "PAYPAL_CSS_URL",GETPOST("PAYPAL_CSS_URL"),'chaine',0,'',$conf->entity);
  53. if (! $result > 0) $error++;
  54. $result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN",GETPOST("PAYPAL_SECURITY_TOKEN"),'chaine',0,'',$conf->entity);
  55. if (! $result > 0) $error++;
  56. $result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN_UNIQUE",GETPOST("PAYPAL_SECURITY_TOKEN_UNIQUE"),'chaine',0,'',$conf->entity);
  57. if (! $result > 0) $error++;
  58. $result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",GETPOST("PAYPAL_ADD_PAYMENT_URL"),'chaine',0,'',$conf->entity);
  59. if (! $result > 0) $error++;
  60. $result=dolibarr_set_const($db, "PAYPAL_MESSAGE_OK",GETPOST("PAYPAL_MESSAGE_OK"),'chaine',0,'',$conf->entity);
  61. if (! $result > 0) $error++;
  62. $result=dolibarr_set_const($db, "PAYPAL_MESSAGE_KO",GETPOST("PAYPAL_MESSAGE_KO"),'chaine',0,'',$conf->entity);
  63. if (! $result > 0) $error++;
  64. if (! $error)
  65. {
  66. $db->commit();
  67. $mesg='<div class="ok">'.$langs->trans("SetupSaved").'</div>';
  68. }
  69. else
  70. {
  71. $db->rollback();
  72. dol_print_error($db);
  73. }
  74. }
  75. /*
  76. * View
  77. */
  78. $form=new Form($db);
  79. llxHeader('',$langs->trans("PaypalSetup"));
  80. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  81. print_fiche_titre(' - '.$langs->trans("ModuleSetup"),$linkback,'paypal_logo@paypal');
  82. print '<br>';
  83. $head=paypaladmin_prepare_head();
  84. dol_fiche_head($head, 'paypalaccount', $langs->trans("ModuleSetup"));
  85. print $langs->trans("PaypalDesc")."<br>\n";
  86. if ($conf->use_javascript_ajax)
  87. {
  88. print "\n".'<script type="text/javascript" language="javascript">';
  89. print '$(document).ready(function () {
  90. $("#apidoc").hide();
  91. $("#apidoca").click(function() {
  92. $("#apidoca").hide();
  93. $("#apidoc").show();
  94. });
  95. $("#generate_token").click(function() {
  96. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  97. action: \'getrandompassword\',
  98. generic: true
  99. },
  100. function(token) {
  101. $("#PAYPAL_SECURITY_TOKEN").val(token);
  102. });
  103. });
  104. });';
  105. print '</script>';
  106. }
  107. dol_htmloutput_mesg($mesg);
  108. print '<br>';
  109. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  110. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  111. print '<input type="hidden" name="action" value="setvalue">';
  112. print '<table class="nobordernopadding" width="100%">';
  113. $var=true;
  114. print '<tr class="liste_titre">';
  115. print '<td>'.$langs->trans("AccountParameter").'</td>';
  116. print '<td>'.$langs->trans("Value").'</td>';
  117. print "</tr>\n";
  118. $var=!$var;
  119. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  120. print $langs->trans("PAYPAL_API_SANDBOX").'</td><td>';
  121. print $form->selectyesno("PAYPAL_API_SANDBOX",$conf->global->PAYPAL_API_SANDBOX,1);
  122. print '</td></tr>';
  123. $var=!$var;
  124. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  125. print $langs->trans("PAYPAL_API_USER").'</td><td>';
  126. print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.$conf->global->PAYPAL_API_USER.'">';
  127. print ' &nbsp; '.$langs->trans("Example").': paypal_api1.mywebsite.com';
  128. print '</td></tr>';
  129. $var=!$var;
  130. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  131. print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
  132. print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.$conf->global->PAYPAL_API_PASSWORD.'">';
  133. print '</td></tr>';
  134. $var=!$var;
  135. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  136. print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
  137. print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.$conf->global->PAYPAL_API_SIGNATURE.'">';
  138. print '<br>'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF';
  139. print '</td></tr>';
  140. $var=true;
  141. print '<tr class="liste_titre">';
  142. print '<td>'.$langs->trans("UsageParameter").'</td>';
  143. print '<td>'.$langs->trans("Value").'</td>';
  144. print "</tr>\n";
  145. $var=!$var;
  146. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  147. print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
  148. print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY",array('integral'=>'Integral','paypalonly'=>'Paypal only'),$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
  149. print '</td></tr>';
  150. /*$var=!$var;
  151. print '<tr '.$bc[$var].'><td>';
  152. print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
  153. print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
  154. print '</td></tr>';
  155. */
  156. $var=!$var;
  157. print '<tr '.$bc[$var].'><td>';
  158. print $langs->trans("VendorName").'</td><td>';
  159. print '<input size="64" type="text" name="PAYPAL_CREDITOR" value="'.$conf->global->PAYPAL_CREDITOR.'">';
  160. print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
  161. print '</td></tr>';
  162. $var=!$var;
  163. print '<tr '.$bc[$var].'><td>';
  164. print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
  165. print '<input size="64" type="text" name="PAYPAL_CSS_URL" value="'.$conf->global->PAYPAL_CSS_URL.'">';
  166. print ' &nbsp; '.$langs->trans("Example").': http://mysite/mycss.css';
  167. print '</td></tr>';
  168. $var=!$var;
  169. print '<tr '.$bc[$var].'><td>';
  170. print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
  171. print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL",$conf->global->PAYPAL_ADD_PAYMENT_URL,1);
  172. print '</td></tr>';
  173. $var=!$var;
  174. print '<tr '.$bc[$var].'><td>';
  175. print $langs->trans("MessageOK").'</td><td>';
  176. $doleditor=new DolEditor('PAYPAL_MESSAGE_OK',$conf->global->PAYPAL_MESSAGE_OK,'',100,'dolibarr_details','In',false,true,true,ROWS_4,60);
  177. $doleditor->Create();
  178. print '</td></tr>';
  179. $var=!$var;
  180. print '<tr '.$bc[$var].'><td>';
  181. print $langs->trans("MessageKO").'</td><td>';
  182. $doleditor=new DolEditor('PAYPAL_MESSAGE_KO',$conf->global->PAYPAL_MESSAGE_KO,'',100,'dolibarr_details','In',false,true,true,ROWS_4,60);
  183. $doleditor->Create();
  184. print '</td></tr>';
  185. $var=true;
  186. print '<tr class="liste_titre">';
  187. print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
  188. print '<td>'.$langs->trans("Value").'</td>';
  189. print "</tr>\n";
  190. $var=!$var;
  191. print '<tr '.$bc[$var].'><td>';
  192. print $langs->trans("SecurityToken").'</td><td>';
  193. print '<input size="48" type="text" id="PAYPAL_SECURITY_TOKEN" name="PAYPAL_SECURITY_TOKEN" value="'.$conf->global->PAYPAL_SECURITY_TOKEN.'">';
  194. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  195. print '</td></tr>';
  196. $var=!$var;
  197. print '<tr '.$bc[$var].'><td>';
  198. print $langs->trans("SecurityTokenIsUnique").'</td><td>';
  199. print $form->selectyesno("PAYPAL_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYPAL_SECURITY_TOKEN)?0:$conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE),1);
  200. print '</td></tr>';
  201. print '<tr><td colspan="2" align="center"><br><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td></tr>';
  202. print '</table>';
  203. print '</form>';
  204. dol_fiche_end();
  205. print '<br><br>';
  206. // Help doc
  207. print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
  208. if ($conf->use_javascript_ajax) print '<a href="#" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
  209. $realpaypalurl='www.paypal.com';
  210. $sandboxpaypalurl='developer.paypal.com';
  211. print '<div id="apidoc">';
  212. print 'Your API authentication information can be found with following steps. We recommend that you open a separate Web browser session when carrying out this procedure.<br>
  213. 1. Log in to your PayPal Premier or Business account (on real paypal <a href="https://'.$realpaypalurl.'" target="_blank">'.$realpaypalurl.'</a> (or sandbox <a href="https://'.$sandboxpaypalurl.'" target="_blank">'.$sandboxpaypalurl.'</a>).<br>
  214. 2. Click the Profile subtab located under the My Account heading.<br>
  215. 3. Click the API Access link under the Account Information header.<br>
  216. 4. Click the View API Certificate link in the right column.<br>
  217. 5. Click the Request API signature radio button on the Request API Credentials page.<br>
  218. 6. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
  219. 7. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
  220. 8. Click the "Modify" button after copying your API Username, Password, and Signature.
  221. ';
  222. print '</div>';
  223. print '<br><br>';
  224. $token='';
  225. // Url list
  226. print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br>';
  227. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount",$servicename).':<br>';
  228. print '<strong>'.getPaypalPaymentUrl(1,'free')."</strong><br><br>\n";
  229. if ($conf->commande->enabled)
  230. {
  231. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':<br>';
  232. print '<strong>'.getPaypalPaymentUrl(1,'order')."</strong><br>\n";
  233. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  234. {
  235. $langs->load("orders");
  236. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  237. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Order")).': ';
  238. print '<input type="text class="flat" id="generate_order_ref" name="generate_order_ref" value="'.GETPOST('generate_order_ref').'" size="10">';
  239. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  240. if (GETPOST('generate_order_ref'))
  241. {
  242. print '<br> -> <strong>';
  243. $url=getPaypalPaymentUrl(0,'order',GETPOST('generate_order_ref'));
  244. print $url;
  245. print "</strong><br>\n";
  246. }
  247. print '</form>';
  248. }
  249. print '<br>';
  250. }
  251. if ($conf->facture->enabled)
  252. {
  253. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':<br>';
  254. print '<strong>'.getPaypalPaymentUrl(1,'invoice')."</strong><br>\n";
  255. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  256. {
  257. $langs->load("bills");
  258. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  259. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Invoice")).': ';
  260. print '<input type="text class="flat" id="generate_invoice_ref" name="generate_invoice_ref" value="'.GETPOST('generate_invoice_ref').'" size="10">';
  261. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  262. if (GETPOST('generate_invoice_ref'))
  263. {
  264. print '<br> -> <strong>';
  265. $url=getPaypalPaymentUrl(0,'invoice',GETPOST('generate_invoice_ref'));
  266. print $url;
  267. print "</strong><br>\n";
  268. }
  269. print '</form>';
  270. }
  271. print '<br>';
  272. }
  273. if ($conf->contrat->enabled)
  274. {
  275. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':<br>';
  276. print '<strong>'.getPaypalPaymentUrl(1,'contractline')."</strong><br>\n";
  277. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  278. {
  279. $langs->load("contract");
  280. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  281. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Contract")).': ';
  282. print '<input type="text class="flat" id="generate_contract_ref" name="generate_contract_ref" value="'.GETPOST('generate_contract_ref').'" size="10">';
  283. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  284. if (GETPOST('generate_contract_ref'))
  285. {
  286. print '<br> -> <strong>';
  287. $url=getPaypalPaymentUrl(0,'contractline',GETPOST('generate_contract_ref'));
  288. print $url;
  289. print "</strong><br>\n";
  290. }
  291. print '</form>';
  292. }
  293. print '<br>';
  294. }
  295. if ($conf->adherent->enabled)
  296. {
  297. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':<br>';
  298. print '<strong>'.getPaypalPaymentUrl(1,'membersubscription')."</strong><br>\n";
  299. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  300. {
  301. $langs->load("members");
  302. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  303. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Member")).': ';
  304. print '<input type="text class="flat" id="generate_member_ref" name="generate_member_ref" value="'.GETPOST('generate_member_ref').'" size="10">';
  305. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  306. if (GETPOST('generate_member_ref'))
  307. {
  308. print '<br> -> <strong>';
  309. $url=getPaypalPaymentUrl(0,'membersubscription',GETPOST('generate_member_ref'));
  310. print $url;
  311. print "</strong><br>\n";
  312. }
  313. print '</form>';
  314. }
  315. }
  316. print "<br>";
  317. print info_admin($langs->trans("YouCanAddTagOnUrl"));
  318. $db->close();
  319. llxFooter();
  320. ?>