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#2577 Fix regression - payment edit to new type failing #20195

Merged
merged 1 commit into from
May 2, 2021
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
26 changes: 19 additions & 7 deletions CRM/Financial/Form/PaymentEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class CRM_Financial_Form_PaymentEdit extends CRM_Core_Form {
*/
protected $_contributionID;

/**
* Get the related contribution id.
*
* @return int
*/
public function getContributionID(): int {
return $this->_contributionID;
}

/**
* The variable which holds the information of a financial transaction
*
Expand Down Expand Up @@ -129,7 +138,7 @@ public static function formRule($fields, $files, $self) {
$errors = [];

// if Credit Card is chosen and pan_truncation is not NULL ensure that it's value is numeric else throw validation error
if (CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $fields['payment_instrument_id']) == 'Credit Card' &&
if (CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $fields['payment_instrument_id']) === 'Credit Card' &&
!empty($fields['pan_truncation']) &&
!CRM_Utils_Rule::numeric($fields['pan_truncation'])
) {
Expand All @@ -141,8 +150,10 @@ public static function formRule($fields, $files, $self) {

/**
* Process the form submission.
*
* @throws \CiviCRM_API3_Exception
*/
public function postProcess() {
public function postProcess(): void {
$params = [
'id' => $this->_id,
'payment_instrument_id' => $this->_submitValues['payment_instrument_id'],
Expand All @@ -151,20 +162,20 @@ public function postProcess() {
];

$paymentInstrumentName = CRM_Core_PseudoConstant::getName('CRM_Financial_DAO_FinancialTrxn', 'payment_instrument_id', $params['payment_instrument_id']);
if ($paymentInstrumentName == 'Credit Card') {
if ($paymentInstrumentName === 'Credit Card') {
$params['card_type_id'] = $this->_submitValues['card_type_id'] ?? NULL;
$params['pan_truncation'] = $this->_submitValues['pan_truncation'] ?? NULL;
}
elseif ($paymentInstrumentName == 'Check') {
elseif ($paymentInstrumentName === 'Check') {
$params['check_number'] = $this->_submitValues['check_number'] ?? NULL;
}

$this->submit($params);

$contactId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_contributionID, 'contact_id');
$contactId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->getContributionID(), 'contact_id');
$url = CRM_Utils_System::url(
"civicrm/contact/view/contribution",
"reset=1&action=update&id={$this->_contributionID}&cid={$contactId}&context=contribution"
"reset=1&action=update&id={" . $this->getContributionID() . "}&cid={$contactId}&context=contribution"
);
CRM_Core_Session::singleton()->pushUserContext($url);
}
Expand Down Expand Up @@ -192,14 +203,15 @@ protected function submit($submittedValues) {
$newFinancialTrxn['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($submittedValues['payment_instrument_id']);
$newFinancialTrxn['total_amount'] = $this->_values['total_amount'];
$newFinancialTrxn['currency'] = $this->_values['currency'];
$newFinancialTrxn['contribution_id'] = $this->getContributionID();
civicrm_api3('Payment', 'create', $newFinancialTrxn);
}
else {
// simply update the financial trxn
civicrm_api3('FinancialTrxn', 'create', $submittedValues);
}

CRM_Financial_BAO_Payment::updateRelatedContribution($submittedValues, $this->_contributionID);
CRM_Financial_BAO_Payment::updateRelatedContribution($submittedValues, $this->getContributionID());
}

/**
Expand Down