Merge pull request #15773 from civicrm/5.20
[civicrm-core.git] / extern / ipn.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2020
31 * $Id$
32 *
33 * This script processes "Instant Payment Notifications" (IPNs). Modern
34 * Payment Processors use the /civicrm/payment/ipn/123 endpoint instead (where
35 * 123 is the payment processor ID), however a quirk in the way PayPal works
36 * means that we need to maintain this script.
37 *
38 * Note on PayPal.
39 *
40 * Using PayPal Website Standard (which uses the old PayPal button API) the IPN
41 * endpoint is passed to PayPal with every transaction, and it is then stored
42 * by PayPal who unhelpfully do not give you any way to retrieve or change
43 * this.
44 *
45 * This means that if you provide URL1 when setting up a recurring
46 * contribution, then you will always need to maintain URL1 because all
47 * recurring payments against that will be sent to URL1.
48 *
49 * Note that this also affects you if you were to move your CiviCRM instance to
50 * another domain (if you do, get the webserver at the original domain to emit
51 * a 307 redirect to the new one, PayPal will re-send).
52 *
53 * Therefore, for the sake of these old recurring contributions, CiviCRM should
54 * maintain this script as part of core.
55 */
56
57 if (defined('PANTHEON_ENVIRONMENT')) {
58 ini_set('session.save_handler', 'files');
59 }
60 session_start();
61
62 require_once '../civicrm.config.php';
63
64 /* Cache the real UF, override it with the SOAP environment */
65
66 $config = CRM_Core_Config::singleton();
67 $log = new CRM_Utils_SystemLogger();
68 if (empty($_GET)) {
69 $log->alert('payment_notification processor_name=PayPal', $_REQUEST);
70 $paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST);
71 }
72 else {
73 $log->alert('payment_notification PayPal_Standard', $_REQUEST);
74 $paypalIPN = new CRM_Core_Payment_PayPalIPN($_REQUEST);
75 // @todo upgrade standard per Pro
76 }
77 try {
78 switch ($config->userFramework) {
79 case 'Joomla':
80 // CRM-18245
81 CRM_Utils_System::loadBootStrap();
82 break;
83
84 default:
85 // Gitlab issues: #973, #1017
86 CRM_Utils_System::loadBootStrap([], FALSE);
87 break;
88
89 }
90 $paypalIPN->main();
91 }
92 catch (CRM_Core_Exception $e) {
93 CRM_Core_Error::debug_log_message($e->getMessage());
94 CRM_Core_Error::debug_var('error data', $e->getErrorData(), TRUE, TRUE);
95 CRM_Core_Error::debug_var('REQUEST', $_REQUEST, TRUE, TRUE);
96 //@todo give better info to logged in user - ie dev
97 echo "The transaction has failed. Please review the log for more detail";
98 }