PageRenderTime 2104ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/paypal/admin/paypal.php

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