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

Cleanup variable assigns in ContributionPage confirm #22902

Merged
merged 1 commit into from
Mar 19, 2022
Merged
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
10 changes: 3 additions & 7 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2752,13 +2752,9 @@ public function processConfirm(
}
$result = $payment->doPayment($paymentParams);
$form->_params = array_merge($form->_params, $result);
$form->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $result));
if (!empty($result['trxn_id'])) {
$contribution->trxn_id = $result['trxn_id'];
}
if (!empty($result['payment_status_id'])) {
$contribution->payment_status_id = $result['payment_status_id'];
}
$form->assign('trxn_id', $result['trxn_id'] ?? '');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simpler to use NULL coalescing operator here.

$contribution->trxn_id = $result['trxn_id'] ?? $contribution->trxn_id ?? '';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather than checking if return value from doPayment is empty we assign via a hierarchy which clearly shows priority

$contribution->payment_status_id = $result['payment_status_id'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any payment processor that does not return payment_status_id is going to be broken in multiple ways because it is the only way to check if payment was successful..

$result['contribution'] = $contribution;
if ($result['payment_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending')
&& $payment->isSendReceiptForPending()) {
Expand Down