-
-
Notifications
You must be signed in to change notification settings - Fork 817
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
CRM-20610: Handle payment instrument change on Payment Edit form #10814
CRM-20610: Handle payment instrument change on Payment Edit form #10814
Conversation
86c5fb5
to
e3a78cb
Compare
@eileenmcnaughton can you please check now? I have mentioned the changes in PR description. |
Jenkin test this please |
CRM/Contribute/BAO/Contribution.php
Outdated
@@ -4186,11 +4186,13 @@ public static function getPaymentInfo($id, $component, $getTrxnInfo = FALSE, $us | |||
CRM_Core_Action::mask(array(CRM_Core_Permission::EDIT)), | |||
array( | |||
'id' => $resultDAO->id, | |||
'contri_id' => $contributionId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to use this abbreviation - what is so long about the word contribution that we have to abbreviate it into something hard to read?
CRM/Core/BAO/FinancialTrxn.php
Outdated
elseif (!empty($params['entity_id']) && !empty($params['entity_table'])) { | ||
$entityFinancialTrxnParams['entity_table'] = $params['entity_table']; | ||
$entityFinancialTrxnParams['entity_id'] = $params['entity_id']; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about changing this function to this -
/**
* Create a financial transaction object.
*
* @param array $params
* Values relating to the transaction..
*
* @param array $trxnEntityTable
* Deprecated: array of entity_id & entity_table. Put
* these in params instead.
*
* @return CRM_Core_BAO_FinancialTrxn
*/
public static function create($params, $trxnEntityTable = array()) {
$trxn = new CRM_Financial_DBO_FinancialTrxn();
$trxn->copyValues($params);
if (!CRM_Utils_Rule::currencyCode($trxn->currency)) {
$trxn->currency = CRM_Core_Config::singleton()->defaultCurrency;
}
$trxn->save();
// save to entity_financial_trxn table
$entityFinancialTrxnParams
= array_merge(array(
'entity_table' => "civicrm_contribution",
'financial_trxn_id' => $trxn->id,
'amount' => $params['total_amount'],
), $trxnEntityTable, $params);
if (empty($entityFinancialTrxnParams['entity_id'])) {
$entityFinancialTrxnParams['entity_id'] = $params['contribution_id'];
}
$entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
$entityTrxn->copyValues($entityFinancialTrxnParams);
$entityTrxn->save();
return $trxn;
}
I could only find two instances where $trxnEntityTable was passed in
BAO_LineItem
$trxnTable = array(
'entity_id' => $newFinancialItem->id,
'entity_table' => 'civicrm_financial_item',
);
$reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues['financialTrxn'], $trxnTable);
&&
FinancialTrxn::createPremiumTrxn (function looks a bit broken to me but that is by the by)
$trxnEntityTable['entity_table'] = 'civicrm_contribution';
$trxnEntityTable['entity_id'] = $params['contributionId'];
CRM_Core_BAO_FinancialTrxn::create($financialtrxn, $trxnEntityTable);
api/v3/FinancialTrxn.php
Outdated
@@ -39,7 +39,10 @@ | |||
* @return array | |||
*/ | |||
function civicrm_api3_financial_trxn_create($params) { | |||
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |||
if (empty($params['contribution_id']) && (empty($params['entity_table']) && empty($params['entity_id']))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this be
civicrm_api3_verify_mandatory($params, NULL, array(array('contribution_id', array('entity_table', 'entity_id')));
verify_mandatory can do OR - I Think I got that right for this OR this AND that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the big difference between what you did, functionally, and verify_mandatory is that if id is passed in verify_mandatory passes it through. The BAO function doesn't seem to handle passing in id well. I don't think the change proposed makes it worse though.
@monishdeb I'm mostly OK with this - I had some suggestions. I can't do a reviewer's Pr due to the temporary rules which make it harder to collaborate so have posted comments on here. I'm tempted to add a return after $trxn->save() if (!empty($params['id') but I guess that would be a change & it seems to be currently not broken - perhaps it's worth commenting that code at least to point out that it is weird in that scenario |
a10a382
to
b928d3b
Compare
@@ -39,7 +39,11 @@ | |||
* @return array | |||
*/ | |||
function civicrm_api3_financial_trxn_create($params) { | |||
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |||
if (empty($params['id']) && empty($params['contribution_id']) && empty($params['entity_id'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton actually civicrm_api3_verify_mandatory(...)
perform OR operation between keys but here we need AND. I changed it to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can do a combo of AND + OR ie
array('x', 'y') is x +y
array (('x', 'y') is x OR y
array (('x', array('y', 'z') ) is x AND y or Z
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can use verify_one_mandatory as a clearing way of doing x or y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still it does x OR y check and we need x AND y here :(
b928d3b
to
50f8ceb
Compare
@eileenmcnaughton I have made the additional fixes you mentioned - 50f8ceb. Also added concatenation fix and added unit-test - 650b79b Can you please check now? |
9dc9fd0
to
650b79b
Compare
CRM/Core/BAO/FinancialTrxn.php
Outdated
@@ -50,37 +50,38 @@ public function __construct() { | |||
* @param array $params | |||
* (reference ) an assoc array of name/value pairs. | |||
* | |||
* @param string $trxnEntityTable | |||
* Entity_table. | |||
* @param array $ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not actually $ids - it's just a deprecated parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
($ids is generally deprecated on create too but this doesn't hold ids)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On re-reading, it looks like $ids should just be removed as a parameter as you are altering the places that use it
CRM/Core/BAO/FinancialTrxn.php
Outdated
$trxn = new CRM_Financial_DAO_FinancialTrxn(); | ||
$trxn->copyValues($params); | ||
|
||
if (!CRM_Utils_Rule::currencyCode($trxn->currency)) { | ||
$trxn->currency = CRM_Core_Config::singleton()->defaultCurrency; | ||
} | ||
|
||
$trxn->save(); | ||
//per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array | ||
$financialTrxnID = CRM_Utils_Array::value('FinancialTrxn', $ids, CRM_Utils_Array::value('id', $params)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We aren't passing in 'id' as a field anywhere so we shouldn't start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ie. just CRM_Utils_Array::value('id', $params)) is fine & we don't need to specially set it - copyValues will do that
CRM/Price/BAO/LineItem.php
Outdated
); | ||
$reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues['financialTrxn'], $trxnTable); | ||
)); | ||
$reverseTrxn = CRM_Core_BAO_FinancialTrxn::create($updateFinancialItemInfoValues['financialTrxn']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue here - ie. you are passing in $updateFinancialItemInfoValues['financialTrxn'] but it should be $updateFinancialItemInfoValues
CRM/Core/BAO/FinancialTrxn.php
Outdated
); | ||
$trxnEntityTable['entity_table'] = 'civicrm_contribution'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better practice to explicitly state the table?
CRM/Core/BAO/FinancialTrxn.php
Outdated
} | ||
|
||
// save to entity_financial_trxn table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick - whitespace std should use capital letter & full stop
CRM/Core/BAO/FinancialTrxn.php
Outdated
$trxn->save(); | ||
//per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array | ||
$financialTrxnID = CRM_Utils_Array::value('FinancialTrxn', $ids, CRM_Utils_Array::value('id', $params)); | ||
$trxn->id = $financialTrxnID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done by copyValues
@@ -897,7 +897,6 @@ public function callAPISuccessGetValue($entity, $params, $type = NULL) { | |||
public function callAPISuccessGetSingle($entity, $params, $checkAgainst = NULL) { | |||
$params += array( | |||
'version' => $this->_apiversion, | |||
'debug' => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because passing this attribute add xdebug properties in the array, which later impacts checkArrayEquals
where it only concern about matching the values of the array, the reason why allowing this attribute mismatches with expected array and leads to test failures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - it also improves test information available I think - I know the getAndCheck function handles this parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton in fact getAndCheck
doesn't pass this parameter debug
as in here and for API's result array comparison, this extraneous information are avoided while checking:
public function assertAPIArrayComparison($result, $expected, $valuesToExclude = array(), $prefix = '') {
$valuesToExclude = array_merge($valuesToExclude, array('debug', 'xdebug', 'sequential'));
...
271a7e0
to
7e3c9a6
Compare
@eileenmcnaughton I have updated the PR can you please check now? |
7e3c9a6
to
3137781
Compare
@eileenmcnaughton is it ok to merge? |
@monishdeb I think we should still not be removing debug & the verify_mandatory can do what we are after. However, those are non functional & I think merging this into the rc should have some priority so I will merge now & try to pick that up against master |
Overview
CRM_Core_BAO_FinancialTrxn::create(...)
Screencast