paypal.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2013 Laurent Destailleur <eldy@users.sourceforge.org>
  4. * Copyright (C) 2011-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2011-2012 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 3 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) accessforbidden();
  35. $action = GETPOST('action','alpha');
  36. if ($action == 'setvalue' && $user->admin)
  37. {
  38. $db->begin();
  39. $result=dolibarr_set_const($db, "PAYPAL_API_SANDBOX",GETPOST('PAYPAL_API_SANDBOX','alpha'),'chaine',0,'',$conf->entity);
  40. if (! $result > 0) $error++;
  41. $result=dolibarr_set_const($db, "PAYPAL_API_USER",GETPOST('PAYPAL_API_USER','alpha'),'chaine',0,'',$conf->entity);
  42. if (! $result > 0) $error++;
  43. $result=dolibarr_set_const($db, "PAYPAL_API_PASSWORD",GETPOST('PAYPAL_API_PASSWORD','alpha'),'chaine',0,'',$conf->entity);
  44. if (! $result > 0) $error++;
  45. $result=dolibarr_set_const($db, "PAYPAL_API_SIGNATURE",GETPOST('PAYPAL_API_SIGNATURE','alpha'),'chaine',0,'',$conf->entity);
  46. if (! $result > 0) $error++;
  47. $result=dolibarr_set_const($db, "PAYPAL_CREDITOR",GETPOST('PAYPAL_CREDITOR','alpha'),'chaine',0,'',$conf->entity);
  48. if (! $result > 0) $error++;
  49. $result=dolibarr_set_const($db, "PAYPAL_API_INTEGRAL_OR_PAYPALONLY",GETPOST('PAYPAL_API_INTEGRAL_OR_PAYPALONLY','alpha'),'chaine',0,'',$conf->entity);
  50. if (! $result > 0) $error++;
  51. $result=dolibarr_set_const($db, "PAYPAL_CSS_URL",GETPOST('PAYPAL_CSS_URL','alpha'),'chaine',0,'',$conf->entity);
  52. if (! $result > 0) $error++;
  53. $result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN",GETPOST('PAYPAL_SECURITY_TOKEN','alpha'),'chaine',0,'',$conf->entity);
  54. if (! $result > 0) $error++;
  55. $result=dolibarr_set_const($db, "PAYPAL_SECURITY_TOKEN_UNIQUE",GETPOST('PAYPAL_SECURITY_TOKEN_UNIQUE','alpha'),'chaine',0,'',$conf->entity);
  56. if (! $result > 0) $error++;
  57. $result=dolibarr_set_const($db, "PAYPAL_ADD_PAYMENT_URL",GETPOST('PAYPAL_ADD_PAYMENT_URL','alpha'),'chaine',0,'',$conf->entity);
  58. if (! $result > 0) $error++;
  59. $result=dolibarr_set_const($db, "PAYPAL_MESSAGE_OK",GETPOST('PAYPAL_MESSAGE_OK'),'chaine',0,'',$conf->entity);
  60. if (! $result > 0) $error++;
  61. $result=dolibarr_set_const($db, "PAYPAL_MESSAGE_KO",GETPOST('PAYPAL_MESSAGE_KO'),'chaine',0,'',$conf->entity);
  62. if (! $result > 0) $error++;
  63. $result=dolibarr_set_const($db, "PAYPAL_PAYONLINE_SENDEMAIL",GETPOST('PAYPAL_PAYONLINE_SENDEMAIL'),'chaine',0,'',$conf->entity);
  64. if (! $result > 0) $error++;
  65. if (! $error)
  66. {
  67. $db->commit();
  68. setEventMessage($langs->trans("SetupSaved"));
  69. }
  70. else
  71. {
  72. $db->rollback();
  73. dol_print_error($db);
  74. }
  75. }
  76. /*
  77. * View
  78. */
  79. $form=new Form($db);
  80. llxHeader('',$langs->trans("PaypalSetup"));
  81. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  82. print_fiche_titre(' - '.$langs->trans("ModuleSetup"),$linkback,'paypal_logo@paypal');
  83. print '<br>';
  84. $head=paypaladmin_prepare_head();
  85. dol_fiche_head($head, 'paypalaccount', '');
  86. print $langs->trans("PaypalDesc")."<br>\n";
  87. // Test if php curl exist
  88. if (! function_exists('curl_version'))
  89. {
  90. $langs->load("errors");
  91. setEventMessage($langs->trans("ErrorPhpCurlNotInstalled"), 'errors');
  92. }
  93. print '<br>';
  94. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  95. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  96. print '<input type="hidden" name="action" value="setvalue">';
  97. print '<table class="noborder" width="100%">';
  98. $var=true;
  99. print '<tr class="liste_titre">';
  100. print '<td>'.$langs->trans("AccountParameter").'</td>';
  101. print '<td>'.$langs->trans("Value").'</td>';
  102. print "</tr>\n";
  103. $var=!$var;
  104. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  105. print $langs->trans("PAYPAL_API_SANDBOX").'</td><td>';
  106. print $form->selectyesno("PAYPAL_API_SANDBOX",$conf->global->PAYPAL_API_SANDBOX,1);
  107. print '</td></tr>';
  108. $var=!$var;
  109. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  110. print $langs->trans("PAYPAL_API_USER").'</td><td>';
  111. print '<input size="32" type="text" name="PAYPAL_API_USER" value="'.$conf->global->PAYPAL_API_USER.'">';
  112. print ' &nbsp; '.$langs->trans("Example").': paypal_api1.mywebsite.com';
  113. print '</td></tr>';
  114. $var=!$var;
  115. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  116. print $langs->trans("PAYPAL_API_PASSWORD").'</td><td>';
  117. print '<input size="32" type="text" name="PAYPAL_API_PASSWORD" value="'.$conf->global->PAYPAL_API_PASSWORD.'">';
  118. print '</td></tr>';
  119. $var=!$var;
  120. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  121. print $langs->trans("PAYPAL_API_SIGNATURE").'</td><td>';
  122. print '<input size="64" type="text" name="PAYPAL_API_SIGNATURE" value="'.$conf->global->PAYPAL_API_SIGNATURE.'">';
  123. print '<br>'.$langs->trans("Example").': ASsqXEmw4KzmX-CPChWSVDNCNfd.A3YNR7uz-VncXXAERFDFDFDF';
  124. print '</td></tr>';
  125. $var=true;
  126. print '<tr class="liste_titre">';
  127. print '<td>'.$langs->trans("UsageParameter").'</td>';
  128. print '<td>'.$langs->trans("Value").'</td>';
  129. print "</tr>\n";
  130. $var=!$var;
  131. print '<tr '.$bc[$var].'><td class="fieldrequired">';
  132. print $langs->trans("PAYPAL_API_INTEGRAL_OR_PAYPALONLY").'</td><td>';
  133. print $form->selectarray("PAYPAL_API_INTEGRAL_OR_PAYPALONLY",array('integral'=> $langs->trans('PaypalModeIntegral'),'paypalonly'=> $langs->trans('PaypalModeOnlyPaypal')),$conf->global->PAYPAL_API_INTEGRAL_OR_PAYPALONLY);
  134. print '</td></tr>';
  135. /*$var=!$var;
  136. print '<tr '.$bc[$var].'><td>';
  137. print '<span class="fieldrequired">'.$langs->trans("PAYPAL_API_EXPRESS").'</span></td><td>';
  138. print $form->selectyesno("PAYPAL_API_EXPRESS",$conf->global->PAYPAL_API_EXPRESS);
  139. print '</td></tr>';
  140. */
  141. $var=!$var;
  142. print '<tr '.$bc[$var].'><td>';
  143. print $langs->trans("VendorName").'</td><td>';
  144. print '<input size="64" type="text" name="PAYPAL_CREDITOR" value="'.$conf->global->PAYPAL_CREDITOR.'">';
  145. print ' &nbsp; '.$langs->trans("Example").': '.$mysoc->name;
  146. print '</td></tr>';
  147. $var=!$var;
  148. print '<tr '.$bc[$var].'><td>';
  149. print $langs->trans("CSSUrlForPaymentForm").'</td><td>';
  150. print '<input size="64" type="text" name="PAYPAL_CSS_URL" value="'.$conf->global->PAYPAL_CSS_URL.'">';
  151. print ' &nbsp; '.$langs->trans("Example").': http://mysite/mycss.css';
  152. print '</td></tr>';
  153. $var=!$var;
  154. print '<tr '.$bc[$var].'><td>';
  155. print $langs->trans("PAYPAL_ADD_PAYMENT_URL").'</td><td>';
  156. print $form->selectyesno("PAYPAL_ADD_PAYMENT_URL",$conf->global->PAYPAL_ADD_PAYMENT_URL,1);
  157. print '</td></tr>';
  158. $var=!$var;
  159. print '<tr '.$bc[$var].'><td>';
  160. print $langs->trans("MessageOK").'</td><td>';
  161. $doleditor=new DolEditor('PAYPAL_MESSAGE_OK',$conf->global->PAYPAL_MESSAGE_OK,'',100,'dolibarr_details','In',false,true,true,ROWS_4,60);
  162. $doleditor->Create();
  163. print '</td></tr>';
  164. $var=!$var;
  165. print '<tr '.$bc[$var].'><td>';
  166. print $langs->trans("MessageKO").'</td><td>';
  167. $doleditor=new DolEditor('PAYPAL_MESSAGE_KO',$conf->global->PAYPAL_MESSAGE_KO,'',100,'dolibarr_details','In',false,true,true,ROWS_4,60);
  168. $doleditor->Create();
  169. print '</td></tr>';
  170. $var=!$var;
  171. print '<tr '.$bc[$var].'><td>';
  172. print $langs->trans("PAYPAL_PAYONLINE_SENDEMAIL").'</td><td>';
  173. print '<input size="32" type="email" name="PAYPAL_PAYONLINE_SENDEMAIL" value="'.$conf->global->PAYPAL_PAYONLINE_SENDEMAIL.'">';
  174. print ' &nbsp; '.$langs->trans("Example").': myemail@myserver.com';
  175. print '</td></tr>';
  176. $var=true;
  177. print '<tr class="liste_titre">';
  178. print '<td>'.$langs->trans("UrlGenerationParameters").'</td>';
  179. print '<td>'.$langs->trans("Value").'</td>';
  180. print "</tr>\n";
  181. $var=!$var;
  182. print '<tr '.$bc[$var].'><td>';
  183. print $langs->trans("SecurityToken").'</td><td>';
  184. print '<input size="48" type="text" id="PAYPAL_SECURITY_TOKEN" name="PAYPAL_SECURITY_TOKEN" value="'.$conf->global->PAYPAL_SECURITY_TOKEN.'">';
  185. if (! empty($conf->use_javascript_ajax))
  186. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"');
  187. print '</td></tr>';
  188. $var=!$var;
  189. print '<tr '.$bc[$var].'><td>';
  190. print $langs->trans("SecurityTokenIsUnique").'</td><td>';
  191. print $form->selectyesno("PAYPAL_SECURITY_TOKEN_UNIQUE",(empty($conf->global->PAYPAL_SECURITY_TOKEN)?0:$conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE),1);
  192. print '</td></tr>';
  193. print '</table>';
  194. print '<br><center><input type="submit" class="button" value="'.$langs->trans("Modify").'"></center>';
  195. print '</form>';
  196. dol_fiche_end();
  197. print '<br><br>';
  198. // Help doc
  199. print '<u>'.$langs->trans("InformationToFindParameters","Paypal").'</u>:<br>';
  200. if (! empty($conf->use_javascript_ajax))
  201. print '<a href="#" id="apidoca">'.$langs->trans("ClickHere").'...</a>';
  202. $realpaypalurl='www.paypal.com';
  203. $sandboxpaypalurl='developer.paypal.com';
  204. print '<div id="apidoc">';
  205. 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>
  206. 1. Log in to your PayPal account (on real paypal <a href="https://'.$realpaypalurl.'" target="_blank">'.$realpaypalurl.'</a> (or sandbox <a href="https://'.$sandboxpaypalurl.'" target="_blank">'.$sandboxpaypalurl.'</a>).<br>
  207. 2. Click the "Profile" or "Preferencies" subtab located under the My Account heading.<br>
  208. 3. Click the link "API Access".<br>
  209. 4. Click the View API Certificate link in the right column.<br>
  210. 5. Click the Request API signature radio button on the Request API Credentials page.<br>
  211. 6. Complete the Request API Credential Request form by clicking the agreement checkbox and clicking Submit.<br>
  212. 7. Save the values for API Username, Password and Signature (make sure this long character signature is copied).<br>
  213. 8. Click the "Modify" button after copying your API Username, Password, and Signature.
  214. ';
  215. print '</div>';
  216. print '<br><br>';
  217. $token='';
  218. // Url list
  219. print '<u>'.$langs->trans("FollowingUrlAreAvailableToMakePayments").':</u><br>';
  220. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnFreeAmount",$servicename).':<br>';
  221. print '<strong>'.getPaypalPaymentUrl(1,'free')."</strong><br><br>\n";
  222. if (! empty($conf->commande->enabled))
  223. {
  224. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnOrder",$servicename).':<br>';
  225. print '<strong>'.getPaypalPaymentUrl(1,'order')."</strong><br>\n";
  226. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  227. {
  228. $langs->load("orders");
  229. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  230. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Order")).': ';
  231. print '<input type="text class="flat" id="generate_order_ref" name="generate_order_ref" value="'.GETPOST('generate_order_ref','alpha').'" size="10">';
  232. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  233. if (GETPOST('generate_order_ref','alpha'))
  234. {
  235. print '<br> -> <strong>';
  236. $url=getPaypalPaymentUrl(0,'order',GETPOST('generate_order_ref','alpha'));
  237. print $url;
  238. print "</strong><br>\n";
  239. }
  240. print '</form>';
  241. }
  242. print '<br>';
  243. }
  244. if (! empty($conf->facture->enabled))
  245. {
  246. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnInvoice",$servicename).':<br>';
  247. print '<strong>'.getPaypalPaymentUrl(1,'invoice')."</strong><br>\n";
  248. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  249. {
  250. $langs->load("bills");
  251. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  252. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Invoice")).': ';
  253. print '<input type="text class="flat" id="generate_invoice_ref" name="generate_invoice_ref" value="'.GETPOST('generate_invoice_ref','alpha').'" size="10">';
  254. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  255. if (GETPOST('generate_invoice_ref','alpha'))
  256. {
  257. print '<br> -> <strong>';
  258. $url=getPaypalPaymentUrl(0,'invoice',GETPOST('generate_invoice_ref','alpha'));
  259. print $url;
  260. print "</strong><br>\n";
  261. }
  262. print '</form>';
  263. }
  264. print '<br>';
  265. }
  266. if (! empty($conf->contrat->enabled))
  267. {
  268. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnContractLine",$servicename).':<br>';
  269. print '<strong>'.getPaypalPaymentUrl(1,'contractline')."</strong><br>\n";
  270. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  271. {
  272. $langs->load("contract");
  273. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  274. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Contract")).': ';
  275. print '<input type="text class="flat" id="generate_contract_ref" name="generate_contract_ref" value="'.GETPOST('generate_contract_ref','alpha').'" size="10">';
  276. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  277. if (GETPOST('generate_contract_ref'))
  278. {
  279. print '<br> -> <strong>';
  280. $url=getPaypalPaymentUrl(0,'contractline',GETPOST('generate_contract_ref','alpha'));
  281. print $url;
  282. print "</strong><br>\n";
  283. }
  284. print '</form>';
  285. }
  286. print '<br>';
  287. }
  288. if (! empty($conf->adherent->enabled))
  289. {
  290. print img_picto('','object_globe.png').' '.$langs->trans("ToOfferALinkForOnlinePaymentOnMemberSubscription",$servicename).':<br>';
  291. print '<strong>'.getPaypalPaymentUrl(1,'membersubscription')."</strong><br>\n";
  292. if (! empty($conf->global->PAYPAL_SECURITY_TOKEN) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE))
  293. {
  294. $langs->load("members");
  295. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  296. print $langs->trans("EnterRefToBuildUrl",$langs->transnoentitiesnoconv("Member")).': ';
  297. print '<input type="text class="flat" id="generate_member_ref" name="generate_member_ref" value="'.GETPOST('generate_member_ref','alpha').'" size="10">';
  298. print '<input type="submit" class="none" value="'.$langs->trans("GetSecuredUrl").'">';
  299. if (GETPOST('generate_member_ref'))
  300. {
  301. print '<br> -> <strong>';
  302. $url=getPaypalPaymentUrl(0,'membersubscription',GETPOST('generate_member_ref','alpha'));
  303. print $url;
  304. print "</strong><br>\n";
  305. }
  306. print '</form>';
  307. }
  308. }
  309. print "<br>";
  310. print info_admin($langs->trans("YouCanAddTagOnUrl"));
  311. if (! empty($conf->use_javascript_ajax))
  312. {
  313. print "\n".'<script type="text/javascript">';
  314. print '$(document).ready(function () {
  315. $("#apidoc").hide();
  316. $("#apidoca").click(function() {
  317. $("#apidoca").hide();
  318. $("#apidoc").show();
  319. });
  320. $("#generate_token").click(function() {
  321. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  322. action: \'getrandompassword\',
  323. generic: true
  324. },
  325. function(token) {
  326. $("#PAYPAL_SECURITY_TOKEN").val(token);
  327. });
  328. });
  329. });';
  330. print '</script>';
  331. }
  332. llxFooter();
  333. $db->close();