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

fix parameters in Payment.get #26356

Merged
merged 1 commit into from
Jun 7, 2023
Merged

Conversation

MegaphoneJon
Copy link
Contributor

Overview

There's a bug in how financial transaction IDs are searched in APIv3 Payment.get.

Technical Details

The old code produced a malformed parameter such that Payment.get with a contribution ID specified never returned a value. Since this hasn't been caught be tests, I don't think this is very serious - I came across it while testing something that turned out to be unrelated.

Comments

Since tests are passing and no one has reported an issue here, any test failures this provokes should be indications of a deeper bug elsewhere.

@civibot
Copy link

civibot bot commented May 26, 2023

(Standard links)

@civibot civibot bot added the master label May 26, 2023
@MegaphoneJon MegaphoneJon changed the title [do not merge] fix parameters in Payment.get fix parameters in Payment.get May 26, 2023
@MegaphoneJon
Copy link
Contributor Author

OK - this passed all tests, and meanwhile I decided to do a git blame and found that the last edit to these lines was a refactor - and before the refactor, something very similar to my code exists. Feeling much more confident about this as a solution.

@colemanw
Copy link
Member

@MegaphoneJon I just stared at this PR diff for 5 minutes and I still don't see the functional difference between the two. They both look like they'd produce the same thing, an array like

$params['financial_trxn_id'] = ['IN' => [1,2,3]]

What am I missing?

@mlutfy
Copy link
Member

mlutfy commented Jun 7, 2023

I tried testing before/after and it also seems to give the same result.

I like the shorter syntax though, and the correctly-initialized array.

I tested this on PHP 8.2, in case it was a PHP version issue:

$eft = [];
$eft[] = ['financial_trxn_id' => 1];
$eft[] = ['financial_trxn_id' => 2];
$eft[] = ['financial_trxn_id' => 3];

$params = [];
foreach ($eft as $entityFinancialTrxn) {
  $params['financial_trxn_id']['IN'][] = $entityFinancialTrxn['financial_trxn_id'];
}
print_r($params);

$params = [];
$ftIds = array_column($eft, 'financial_trxn_id');
$params['financial_trxn_id'] = ['IN' => $ftIds];
print_r($params);

Output:

Array
(
    [financial_trxn_id] => Array
        (
            [IN] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)
Array
(
    [financial_trxn_id] => Array
        (
            [IN] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)

@colemanw
Copy link
Member

colemanw commented Jun 7, 2023

I agree Civi code tends to overuse the foreach loop when there are cleverer methods available, I'm not against merging this on those grounds... but what of the bug @MegaphoneJon ?

@mattwire mattwire merged commit f616e5d into civicrm:master Jun 7, 2023
@mattwire
Copy link
Contributor

mattwire commented Jun 7, 2023

Merging since before/after seems to be the same but it's obviously caused something buggy for @MegaphoneJon. Also using array_column is more performant than foreach. @MegaphoneJon be good if you can comment on the bug per @colemanw comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants