Skip to content

Commit

Permalink
Merge pull request #18534 from eileenmcnaughton/5.30
Browse files Browse the repository at this point in the history
Follow up fix on paypal redirect
  • Loading branch information
seamuslee001 authored Sep 22, 2020
2 parents fbfa0bf + 67a10cc commit 9920a68
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CRM/Core/Exception/PrematureExitException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Payment/PayPalImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ public function doTransferCheckout(&$params, $component = 'contribute') {
$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);
}
Expand Down
5 changes: 2 additions & 3 deletions CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public static function redirect($url = NULL, $context = []) {
}

self::setHttpHeader('Location', $url);
self::civiExit();
self::civiExit(0, ['url' => $url, 'context' => 'redirect']);
}

/**
Expand Down Expand Up @@ -1919,8 +1919,7 @@ public static function sendResponse(\Psr\Http\Message\ResponseInterface $respons
* 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();
}

}
76 changes: 76 additions & 0 deletions tests/phpunit/CRM/Core/Payment/PaypalStdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Class CRM_Core_Payment_PaypalPro
* @group headless
*/
class CRM_Core_Payment_PaypalStdTest extends CiviUnitTestCase {

/**
* @var \CRM_Core_Payment_PayPalImpl
*/
protected $processor;

/**
* @throws \CiviCRM_API3_Exception
*/
public function setUp() {
parent::setUp();
$processorID = $this->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']);
}
}

}

0 comments on commit 9920a68

Please sign in to comment.