Merge pull request #17526 from mattwire/frontendrequiredpaymentfrequency
[civicrm-core.git] / extern / ipn.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * @package CRM
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
15 * $Id$
16 *
17 * This script processes "Instant Payment Notifications" (IPNs). Modern
18 * Payment Processors use the /civicrm/payment/ipn/123 endpoint instead (where
19 * 123 is the payment processor ID), however a quirk in the way PayPal works
20 * means that we need to maintain this script.
21 *
22 * Note on PayPal.
23 *
24 * Using PayPal Website Standard (which uses the old PayPal button API) the IPN
25 * endpoint is passed to PayPal with every transaction, and it is then stored
26 * by PayPal who unhelpfully do not give you any way to retrieve or change
27 * this.
28 *
29 * This means that if you provide URL1 when setting up a recurring
30 * contribution, then you will always need to maintain URL1 because all
31 * recurring payments against that will be sent to URL1.
32 *
33 * Note that this also affects you if you were to move your CiviCRM instance to
34 * another domain (if you do, get the webserver at the original domain to emit
35 * a 307 redirect to the new one, PayPal will re-send).
36 *
37 * Therefore, for the sake of these old recurring contributions, CiviCRM should
38 * maintain this script as part of core.
39 */
40
41 if (defined('PANTHEON_ENVIRONMENT')) {
42 ini_set('session.save_handler', 'files');
43 }
44 session_start();
45
46 require_once '../civicrm.config.php';
47
48 /* Cache the real UF, override it with the SOAP environment */
49
50 CRM_Core_Config::singleton();
51 $log = new CRM_Utils_SystemLogger();
52 if (empty($_GET)) {
53 $log->alert('payment_notification processor_name=PayPal', $_REQUEST);
54 $paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST);
55 }
56 else {
57 $log->alert('payment_notification PayPal_Standard', $_REQUEST);
58 $paypalIPN = new CRM_Core_Payment_PayPalIPN($_REQUEST);
59 // @todo upgrade standard per Pro
60 }
61 try {
62 switch ($config->userFramework) {
63 case 'Joomla':
64 // CRM-18245
65 CRM_Utils_System::loadBootStrap();
66 break;
67
68 default:
69 // Gitlab issues: #973, #1017
70 CRM_Utils_System::loadBootStrap([], FALSE);
71 break;
72
73 }
74 $paypalIPN->main();
75 }
76 catch (CRM_Core_Exception $e) {
77 CRM_Core_Error::debug_log_message($e->getMessage());
78 CRM_Core_Error::debug_var('error data', $e->getErrorData(), TRUE, TRUE);
79 CRM_Core_Error::debug_var('REQUEST', $_REQUEST, TRUE, TRUE);
80 //@todo give better info to logged in user - ie dev
81 echo "The transaction has failed. Please review the log for more detail";
82 }