diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 5ae135f13d37..6b162c101ced 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1268,7 +1268,7 @@ public function extractCustomPropertiesForDoPayment(PropertyBag $propertyBag, ar * For the current status see: https://lab.civicrm.org/dev/financial/issues/53 * If we DO have a contribution ID, then the payment processor can (and should) update parameters on the contribution record as necessary. * - * @param array $params + * @param array|PropertyBag $params * * @param string $component * @@ -1278,6 +1278,7 @@ public function extractCustomPropertiesForDoPayment(PropertyBag $propertyBag, ar * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function doPayment(&$params, $component = 'contribute') { + $this->setPropertyBag($params); $this->_component = $component; $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'); @@ -1664,6 +1665,10 @@ public function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'can * @return string */ protected function getPaymentDescription($params = [], $length = 24) { + if (!$this->propertyBag) { + CRM_Core_Error::deprecatedFunctionWarning('The property bag should be early on - e.g by doPayment or the calling function'); + $this->setPropertyBag($params); + } $parts = [ 'contactID', 'contributionID', @@ -1672,17 +1677,20 @@ protected function getPaymentDescription($params = [], $length = 24) { 'billing_last_name', ]; $validParts = []; - $params['description'] = $this->getDescription(); + $params['description'] = $this->propertyBag->getDescription(); foreach ($parts as $part) { if ((!empty($params[$part]))) { $validParts[] = $params[$part]; } } + if (empty($validParts) && !empty($params['is_recur'])) { + $validParts[] = ts('Regular payment'); + } return substr(implode('-', $validParts), 0, $length); } /** - * Checks if backoffice recurring edit is allowed + * Checks if back-office recurring edit is allowed * * @return bool */ @@ -1734,4 +1742,19 @@ public function isSendReceiptForPending() { return FALSE; } + /** + * Ensure the property bag property is set. + * + * @param \Civi\Payment\PropertyBag|array $params + */ + protected function setPropertyBag(&$params) { + if (is_a($params, 'PropertyBag')) { + $this->propertyBag = $params; + } + else { + $this->propertyBag = new PropertyBag(); + $this->propertyBag->mergeLegacyInputParams($params); + } + } + } diff --git a/CRM/Core/Payment/Dummy.php b/CRM/Core/Payment/Dummy.php index 717c4f3c6fb8..b2b66125fbdd 100644 --- a/CRM/Core/Payment/Dummy.php +++ b/CRM/Core/Payment/Dummy.php @@ -128,6 +128,7 @@ public function doDirectPayment(&$params) { // Add a fee_amount so we can make sure fees are handled properly in underlying classes. $params['fee_amount'] = 1.50; $params['net_amount'] = $params['gross_amount'] - $params['fee_amount']; + $params['description'] = $this->getPaymentDescription($params); return $params; } diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php index b707f6772029..e3c8a713d72f 100644 --- a/tests/phpunit/api/v3/PaymentProcessorTest.php +++ b/tests/phpunit/api/v3/PaymentProcessorTest.php @@ -16,9 +16,13 @@ */ class api_v3_PaymentProcessorTest extends CiviUnitTestCase { protected $_paymentProcessorType; - protected $_apiversion = 3; protected $_params; + /** + * Set up class. + * + * @throws \CRM_Core_Exception + */ public function setUp() { parent::setUp(); $this->useTransaction(TRUE); @@ -42,17 +46,16 @@ public function setUp() { } /** - * Check with no name. + * Check create with no name specified. */ public function testPaymentProcessorCreateWithoutName() { - $payProcParams = [ - 'is_active' => 1, - ]; - $this->callAPIFailure('payment_processor', 'create', $payProcParams); + $this->callAPIFailure('payment_processor', 'create', ['is_active' => 1]); } /** * Create payment processor. + * + * @throws \CRM_Core_Exception */ public function testPaymentProcessorCreate() { $params = $this->_params; @@ -72,6 +75,8 @@ public function testPaymentProcessorCreate() { /** * Update payment processor. + * + * @throws \CRM_Core_Exception */ public function testPaymentProcessorUpdate() { $params = $this->_params; @@ -115,6 +120,8 @@ public function testPaymentProcessorCreateExample() { /** * Check payment processor delete. + * + * @throws \CRM_Core_Exception */ public function testPaymentProcessorDelete() { $result = $this->callAPISuccess('payment_processor', 'create', $this->_params); @@ -127,6 +134,8 @@ public function testPaymentProcessorDelete() { /** * Check with valid params array. + * + * @throws \CRM_Core_Exception */ public function testPaymentProcessorsGet() { $params = $this->_params;