Merge pull request #17526 from mattwire/frontendrequiredpaymentfrequency
[civicrm-core.git] / extern / ipn.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
6b7eb9df 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
6b7eb9df
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 * @package CRM
ca5cec67 14 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035 15 * $Id$
35eab129
RL
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.
6a488035
TO
39 */
40
ba1e1ab6 41if (defined('PANTHEON_ENVIRONMENT')) {
2af2cd60 42 ini_set('session.save_handler', 'files');
43}
6a488035
TO
44session_start();
45
46require_once '../civicrm.config.php';
47
48/* Cache the real UF, override it with the SOAP environment */
49
d523d24a 50CRM_Core_Config::singleton();
414e3596 51$log = new CRM_Utils_SystemLogger();
6a488035 52if (empty($_GET)) {
6c8d1617 53 $log->alert('payment_notification processor_name=PayPal', $_REQUEST);
c8aa607b 54 $paypalIPN = new CRM_Core_Payment_PayPalProIPN($_REQUEST);
6a488035
TO
55}
56else {
6c8d1617 57 $log->alert('payment_notification PayPal_Standard', $_REQUEST);
f78c9258 58 $paypalIPN = new CRM_Core_Payment_PayPalIPN($_REQUEST);
c8aa607b 59 // @todo upgrade standard per Pro
60}
92e4c2a5 61try {
35eab129
RL
62 switch ($config->userFramework) {
63 case 'Joomla':
64 // CRM-18245
65 CRM_Utils_System::loadBootStrap();
66 break;
67
7aca4a01
FW
68 default:
69 // Gitlab issues: #973, #1017
35eab129
RL
70 CRM_Utils_System::loadBootStrap([], FALSE);
71 break;
72
6ad50bf5 73 }
c8aa607b 74 $paypalIPN->main();
75}
56fdfc52 76catch (CRM_Core_Exception $e) {
c8aa607b 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";
6a488035 82}