From: eileen Date: Sun, 20 Sep 2020 23:13:50 +0000 (+1200) Subject: Follow up fix on paypal redirect X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=67a10cc49c42784bea65585264e1e6a7c837badd;p=civicrm-core.git Follow up fix on paypal redirect Turns out we did some function renaming & missed a spot before merge. As an aside I fixed Paypal to call CRM_Core_Config::singleton()->userSystem->prePostRedirect() directly rather than via system. I'm tempted to take the System function back out again - I don't think it offers a better one-liner --- diff --git a/CRM/Core/Exception/PrematureExitException.php b/CRM/Core/Exception/PrematureExitException.php index e0eee738b9..f46bbfff8e 100644 --- a/CRM/Core/Exception/PrematureExitException.php +++ b/CRM/Core/Exception/PrematureExitException.php @@ -25,6 +25,13 @@ */ class CRM_Core_Exception_PrematureExitException extends RuntimeException { + /** + * Contextual data. + * + * @var array + */ + public $errorData; + /** * Construct the exception. Note: The message is NOT binary safe. * diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index a1002fe925..16526443bd 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -972,7 +972,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $paypalURL = "{$url}{$sub}?$uri"; // Allow each CMS to do a pre-flight check before redirecting to PayPal. - CRM_Utils_System::prePostRedirect(); + CRM_Core_Config::singleton()->userSystem->prePostRedirect(); CRM_Utils_System::redirect($paypalURL); } diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 6af92e60ca..51ba3572d4 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -511,7 +511,7 @@ class CRM_Utils_System { } self::setHttpHeader('Location', $url); - self::civiExit(); + self::civiExit(0, ['url' => $url, 'context' => 'redirect']); } /** @@ -1919,8 +1919,7 @@ class CRM_Utils_System { * Perform any necessary actions prior to redirecting via POST. */ public static function prePostRedirect() { - $config = CRM_Core_Config::singleton(); - $config->userSystem->paypalBeforeRedirect(); + CRM_Core_Config::singleton()->userSystem->prePostRedirect(); } } diff --git a/tests/phpunit/CRM/Core/Payment/PaypalStdTest.php b/tests/phpunit/CRM/Core/Payment/PaypalStdTest.php new file mode 100644 index 0000000000..92a28eb376 --- /dev/null +++ b/tests/phpunit/CRM/Core/Payment/PaypalStdTest.php @@ -0,0 +1,76 @@ +processorCreate([ + 'payment_processor_type_id' => 'PayPal_Standard', + 'is_recur' => TRUE, + 'billing_mode' => 4, + 'url_site' => 'https://www.paypal.com/', + 'url_recur' => 'https://www.paypal.com/', + 'class_name' => 'Payment_PayPalImpl', + ]); + + $this->processor = Civi\Payment\System::singleton()->getById($processorID); + } + + /** + * @throws \CRM_Core_Exception + */ + public function tearDown() { + $this->quickCleanUpFinancialEntities(); + parent::tearDown(); + } + + /** + * Test doing a one-off payment. + * + * @throws \Civi\Payment\Exception\PaymentProcessorException + */ + public function testSinglePayment() { + $params = []; + $params['amount'] = 5.24; + $params['currency'] = 'USD'; + $params['invoiceID'] = 'xyz'; + $params['ip_address'] = '127.0.0.1'; + $params['qfKey'] = 'w'; + $params['currencyID'] = 'USD'; + try { + $this->processor->doPayment($params); + } + catch (CRM_Core_Exception_PrematureExitException $e) { + $redirectValues = parse_url($e->errorData['url']); + $this->assertEquals('https', $redirectValues['scheme']); + $this->assertEquals('www.paypal.com', $redirectValues['host']); + $this->assertEquals('/cgi-bin/webscr', $redirectValues['path']); + $query = []; + parse_str($redirectValues['query'], $query); + $this->assertEquals(5.24, $query['amount']); + $this->assertEquals('CiviCRM_SP', $query['bn']); + } + } + +}