Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#88 Make sure financial_type_id is set when contribution is created #11907

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CRM/Contribute/BAO/Contribution/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public static function processConfirm(

// add some financial type details to the params list
// if folks need to use it
//CRM-15297 deprecate contributionTypeID
$paymentParams['financial_type_id'] = $paymentParams['financialTypeID'] = $paymentParams['contributionTypeID'] = $financialType->id;
//CRM-15297 - contributionType is obsolete - pass financial type as well so people can deprecate it
$paymentParams['financialType_name'] = $paymentParams['contributionType_name'] = $form->_params['contributionType_name'] = $financialType->name;
//CRM-11456
Expand Down Expand Up @@ -154,8 +156,6 @@ public static function processConfirm(
}

$paymentParams['contributionID'] = $contribution->id;
//CRM-15297 deprecate contributionTypeID
$paymentParams['financialTypeID'] = $paymentParams['contributionTypeID'] = $contribution->financial_type_id;
$paymentParams['contributionPageID'] = $contribution->contribution_page_id;
if (isset($paymentParams['contribution_source'])) {
$paymentParams['source'] = $paymentParams['contribution_source'];
Expand Down
13 changes: 5 additions & 8 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,21 +740,18 @@ public function postProcess() {
*
* Comments from previous refactor indicate doubt as to what was going on.
*
* @param int $contributionTypeId
* @param int $financialTypeID
*
* @return null|string
*/
public function wrangleFinancialTypeID($contributionTypeId) {
if (isset($paymentParams['financial_type'])) {
$contributionTypeId = $paymentParams['financial_type'];
Copy link
Member

@monishdeb monishdeb Apr 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit strange as $paymentParams is not a parameter nor initialised inside the function yet this is in existence, seems like something to do with past refactoring. Also we should change the variable name to financialTypeId from contributionTypeId as what we all know and in past why that column was renamed :)

so changes here would be:

public function wrangleFinancialTypeID($financialTypeID) {
 if (empty($financialTypeID) && !empty($this->_values['pledge_id'])) {
   $financialTypeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge',
         $this->_values['pledge_id'],
         'financial_type_id'
       );
}
 return $financialTypeID;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@monishdeb Thanks for the review. I've updated that function to match what you suggested as that's much cleaner.

}
elseif (!empty($this->_values['pledge_id'])) {
$contributionTypeId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge',
public function wrangleFinancialTypeID($financialTypeID) {
if (empty($financialTypeID) && !empty($this->_values['pledge_id'])) {
$financialTypeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge',
$this->_values['pledge_id'],
'financial_type_id'
);
}
return $contributionTypeId;
return $financialTypeID;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions tests/phpunit/CRM/Contribute/Form/Contribution/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ public function testPaynowPayment() {
'skipLineItem' => 0,
);

$result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form,
$processConfirmResult = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form,
$form->_params,
$contactID,
$form->_values['financial_type_id'],
0, FALSE
);

// Make sure that certain parameters are set on return from processConfirm
$this->assertEquals($form->_values['financial_type_id'], $processConfirmResult['financial_type_id']);

// Based on the processed contribution, complete transaction which update the contribution status based on payment result.
if (!empty($result['contribution'])) {
if (!empty($processConfirmResult['contribution'])) {
$this->callAPISuccess('contribution', 'completetransaction', array(
'id' => $result['contribution']->id,
'id' => $processConfirmResult['contribution']->id,
'trxn_date' => date('Y-m-d'),
'payment_processor_id' => $paymentProcessorID,
));
Expand Down