PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/public/paypal/paymentok.php

https://bitbucket.org/speedealing/speedealing
PHP | 199 lines | 122 code | 33 blank | 44 comment | 21 complexity | 74a8165f276eb936aa7b5ed2ef96da0d MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/public/paypal/paymentok.php
  21. * \ingroup paypal
  22. * \brief File to show page after a successful payment
  23. * This page is called by paypal with url provided to payal competed with parameter TOKEN=xxx
  24. * This token can be used to get more informations.
  25. * \author Laurent Destailleur
  26. */
  27. define("NOLOGIN",1); // This means this output page does not require to be logged.
  28. define("NOCSRFCHECK",1); // We accept to go on this page from external web site.
  29. // For MultiCompany module
  30. $entity=(! empty($_GET['entity']) ? (int) $_GET['entity'] : (! empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
  31. if (is_int($entity))
  32. {
  33. define("DOLENTITY", $entity);
  34. }
  35. require '../../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypal.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/paypal/lib/paypalfunctions.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  39. // Security check
  40. if (empty($conf->paypal->enabled)) accessforbidden('',1,1,1);
  41. $langs->load("main");
  42. $langs->load("other");
  43. $langs->load("dict");
  44. $langs->load("bills");
  45. $langs->load("companies");
  46. $langs->load("paybox");
  47. $langs->load("paypal");
  48. // Clean parameters
  49. $PAYPAL_API_USER="";
  50. if (! empty($conf->global->PAYPAL_API_USER)) $PAYPAL_API_USER=$conf->global->PAYPAL_API_USER;
  51. $PAYPAL_API_PASSWORD="";
  52. if (! empty($conf->global->PAYPAL_API_PASSWORD)) $PAYPAL_API_PASSWORD=$conf->global->PAYPAL_API_PASSWORD;
  53. $PAYPAL_API_SIGNATURE="";
  54. if (! empty($conf->global->PAYPAL_API_SIGNATURE)) $PAYPAL_API_SIGNATURE=$conf->global->PAYPAL_API_SIGNATURE;
  55. $PAYPAL_API_SANDBOX="";
  56. if (! empty($conf->global->PAYPAL_API_SANDBOX)) $PAYPAL_API_SANDBOX=$conf->global->PAYPAL_API_SANDBOX;
  57. $PAYPAL_API_OK="";
  58. if ($urlok) $PAYPAL_API_OK=$urlok;
  59. $PAYPAL_API_KO="";
  60. if ($urlko) $PAYPAL_API_KO=$urlko;
  61. if (empty($PAYPAL_API_USER))
  62. {
  63. dol_print_error('',"Paypal setup param PAYPAL_API_USER not defined");
  64. return -1;
  65. }
  66. if (empty($PAYPAL_API_PASSWORD))
  67. {
  68. dol_print_error('',"Paypal setup param PAYPAL_API_PASSWORD not defined");
  69. return -1;
  70. }
  71. if (empty($PAYPAL_API_SIGNATURE))
  72. {
  73. dol_print_error('',"Paypal setup param PAYPAL_API_SIGNATURE not defined");
  74. return -1;
  75. }
  76. /*
  77. * Actions
  78. */
  79. /*
  80. * View
  81. */
  82. dol_syslog("Callback url when a PayPal payment was done. query_string=".$_SERVER["QUERY_STRING"]);
  83. llxHeaderPaypal($langs->trans("PaymentForm"));
  84. print '<span id="dolpaymentspan"></span>'."\n";
  85. print '<div id="dolpaymentdiv" align="center">'."\n";
  86. $source=GETPOST('source');
  87. $ref=GETPOST('ref');
  88. $PAYPALTOKEN=GETPOST('TOKEN');
  89. if (empty($PAYPALTOKEN)) $PAYPALTOKEN=GETPOST('token');
  90. $PAYPALPAYERID=GETPOST('PAYERID');
  91. if (empty($PAYPALPAYERID)) $PAYPALPAYERID=GETPOST('PayerID');
  92. $PAYPALFULLTAG=GETPOST('FULLTAG');
  93. if (empty($PAYPALFULLTAG)) $PAYPALFULLTAG=GETPOST('fulltag');
  94. if ($PAYPALTOKEN)
  95. {
  96. // Get on url call
  97. $token = $PAYPALTOKEN;
  98. $fulltag = $PAYPALFULLTAG;
  99. $payerID = $PAYPALPAYERID;
  100. // Set by newpayment.php
  101. $paymentType = $_SESSION['PaymentType'];
  102. $currencyCodeType = $_SESSION['currencyCodeType'];
  103. $FinalPaymentAmt = $_SESSION["Payment_Amount"];
  104. // From env
  105. $ipaddress = $_SESSION['ipaddress'];
  106. if (! empty($paymentType))
  107. {
  108. dol_syslog("We call GetExpressCheckoutDetails");
  109. $resArray=getDetails($token);
  110. //var_dump($resarray);
  111. dol_syslog("We call DoExpressCheckoutPayment token=".$token." paymentType=".$paymentType." currencyCodeType=".$currencyCodeType." payerID=".$payerID." ipaddress=".$ipaddress." FinalPaymentAmt=".$FinalPaymentAmt." fulltag=".$fulltag);
  112. $resArray=confirmPayment($token, $paymentType, $currencyCodeType, $payerID, $ipaddress, $FinalPaymentAmt, $fulltag);
  113. $ack = strtoupper($resArray["ACK"]);
  114. if($ack=="SUCCESS" || $ack=="SUCCESSWITHWARNING")
  115. {
  116. $object = (object) 'paypal';
  117. $object->source = $source;
  118. $object->ref = $ref;
  119. $object->payerID = $payerID;
  120. $object->fulltag = $fulltag;
  121. $object->resArray = $resArray;
  122. // resArray was built from a string like that
  123. // TOKEN=EC%2d1NJ057703V9359028&TIMESTAMP=2010%2d11%2d01T11%3a40%3a13Z&CORRELATIONID=1efa8c6a36bd8&ACK=Success&VERSION=56&BUILD=1553277&TRANSACTIONID=9B994597K9921420R&TRANSACTIONTYPE=expresscheckout&PAYMENTTYPE=instant&ORDERTIME=2010%2d11%2d01T11%3a40%3a12Z&AMT=155%2e57&FEEAMT=5%2e54&TAXAMT=0%2e00&CURRENCYCODE=EUR&PAYMENTSTATUS=Completed&PENDINGREASON=None&REASONCODE=None
  124. $PAYMENTSTATUS=urldecode($resArray["PAYMENTSTATUS"]); // Should contains 'Completed'
  125. $TRANSACTIONID=urldecode($resArray["TRANSACTIONID"]);
  126. $NOTE=urldecode($resArray["NOTE"]);
  127. print $langs->trans("YourPaymentHasBeenRecorded")."<br>\n";
  128. print $langs->trans("ThisIsTransactionId",$TRANSACTIONID)."<br>\n";
  129. if (! empty($conf->global->PAYPAL_MESSAGE_OK)) print $conf->global->PAYPAL_MESSAGE_OK;
  130. // Appel des triggers
  131. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  132. $interface=new Interfaces($db);
  133. $result=$interface->run_triggers('PAYPAL_PAYMENT_OK',$object,$user,$langs,$conf);
  134. if ($result < 0) { $error++; $errors=$interface->errors; }
  135. // Fin appel triggers
  136. }
  137. else
  138. {
  139. //Display a user friendly Error on the page using any of the following error information returned by PayPal
  140. $ErrorCode = urldecode($resArray["L_ERRORCODE0"]);
  141. $ErrorShortMsg = urldecode($resArray["L_SHORTMESSAGE0"]);
  142. $ErrorLongMsg = urldecode($resArray["L_LONGMESSAGE0"]);
  143. $ErrorSeverityCode = urldecode($resArray["L_SEVERITYCODE0"]);
  144. echo "DoExpressCheckoutPayment API call failed. ";
  145. echo "Detailed Error Message: " . $ErrorLongMsg;
  146. echo "Short Error Message: " . $ErrorShortMsg;
  147. echo "Error Code: " . $ErrorCode;
  148. echo "Error Severity Code: " . $ErrorSeverityCode;
  149. if ($mysoc->email) echo "\nPlease, send a screenshot of this page to ".$mysoc->email;
  150. }
  151. }
  152. else
  153. {
  154. dol_print_error('','Session expired');
  155. }
  156. }
  157. else
  158. {
  159. // No TOKEN parameter in URL
  160. dol_print_error('','No TOKEN parameter in URL');
  161. }
  162. print "\n</div>\n";
  163. html_print_paypal_footer($mysoc,$langs);
  164. $db->close();
  165. llxFooterPaypal();
  166. ?>