Skip to content

Commit

Permalink
Replace CRM_Utils_Array::value in CRM_Contribute_Form_Contribution_Co…
Browse files Browse the repository at this point in the history
…nfirm
  • Loading branch information
mattwire committed Aug 15, 2020
1 parent fa1fd85 commit cbbbf0e
Showing 1 changed file with 42 additions and 54 deletions.
96 changes: 42 additions & 54 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function handlePledge(&$form, $params, $contributionParams, $pledg
$pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
if (!empty($params['start_date'])) {
$pledgeParams['frequency_day'] = intval(date("d", strtotime($params['start_date'])));
$pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date('Ymd', strtotime(CRM_Utils_Array::value('start_date', $params)));
$pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date('Ymd', strtotime($params['start_date']));
}
$pledgeParams['status_id'] = $contribution->contribution_status_id;
$pledgeParams['max_reminders'] = $form->_values['max_reminders'];
Expand Down Expand Up @@ -155,19 +155,19 @@ public static function getContributionParams(
$paymentProcessorOutcome, $receiptDate, $recurringContributionID) {
$contributionParams = [
'financial_type_id' => $financialTypeID,
'receive_date' => (CRM_Utils_Array::value('receive_date', $params)) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'),
'receive_date' => isset($params['receive_date']) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'),
'tax_amount' => $params['tax_amount'] ?? NULL,
'amount_level' => $params['amount_level'] ?? NULL,
'invoice_id' => $params['invoiceID'],
'currency' => $params['currencyID'],
'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
'is_pay_later' => $params['is_pay_later'] ?? 0,
//configure cancel reason, cancel date and thankyou date
//from 'contribution' type profile if included
'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0),
'cancel_reason' => $params['cancel_reason'] ?? 0,
'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL,
'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL,
//setting to make available to hook - although seems wrong to set on form for BAO hook availability
'skipLineItem' => CRM_Utils_Array::value('skipLineItem', $params, 0),
'skipLineItem' => $params['skipLineItem'] ?? 0,
];

if ($paymentProcessorOutcome) {
Expand Down Expand Up @@ -301,7 +301,7 @@ public function preProcess() {
$this->_params['is_pay_later'] = $this->get('is_pay_later');
$this->assign('is_pay_later', $this->_params['is_pay_later']);
if ($this->_params['is_pay_later']) {
$this->assign('pay_later_receipt', CRM_Utils_Array::value('pay_later_receipt', $this->_values));
$this->assign('pay_later_receipt', $this->_values['pay_later_receipt'] ?? NULL);
}
// if onbehalf-of-organization
if (!empty($this->_values['onbehalf_profile_id']) && !empty($this->_params['onbehalf']['organization_name'])) {
Expand Down Expand Up @@ -460,7 +460,7 @@ public function preProcess() {

// assign contribution page id to the template so we can add css class for it
$this->assign('contributionPageID', $this->_id);
$this->assign('is_for_organization', CRM_Utils_Array::value('is_for_organization', $this->_params));
$this->assign('is_for_organization', $this->_params['is_for_organization'] ?? NULL);

$this->set('params', $this->_params);
}
Expand All @@ -485,7 +485,7 @@ public function buildQuickForm() {
$fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']);
$this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
}
$this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
$this->assign('receiptFromEmail', $this->_values['receipt_from_email']);
$amount_block_is_active = $this->get('amount_block_is_active');
$this->assign('amount_block_is_active', $amount_block_is_active);

Expand Down Expand Up @@ -738,7 +738,7 @@ protected function postProcessPremium($premiumParams, $contribution) {
$this->assign('product_name', $productDAO->name);
$this->assign('price', $productDAO->price);
$this->assign('sku', $productDAO->sku);
$this->assign('option', CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams));
$this->assign('option', $premiumParams['options_' . $premiumParams['selectProduct']] ?? NULL);

$periodType = $productDAO->period_type;

Expand Down Expand Up @@ -887,7 +887,7 @@ public static function processFormContribution(

$isEmailReceipt = !empty($form->_values['is_email_receipt']);
$isSeparateMembershipPayment = !empty($params['separate_membership_payment']);
$pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : CRM_Utils_Array::value('pledge_id', $form->_values);
$pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : $form->_values['pledge_id'] ?? NULL;
if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) &&
(!empty($params['is_pledge']) || $pledgeID)) {
$isPledge = TRUE;
Expand Down Expand Up @@ -1089,10 +1089,10 @@ public static function processRecurringContribution(&$form, &$params, $contactID
$recurParams['is_email_receipt'] = $params['is_email_receipt'] ?? NULL;
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
$recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];
$recurParams['financial_type_id'] = $contributionType->id;

$campaignId = CRM_Utils_Array::value('campaign_id', $params, CRM_Utils_Array::value('campaign_id', $form->_values));
$campaignId = $params['campaign_id'] ?? $form->_values['campaign_id'] ?? NULL;
$recurParams['campaign_id'] = $campaignId;
$recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
if (is_a($recurring, 'CRM_Core_Error')) {
Expand Down Expand Up @@ -1343,7 +1343,7 @@ protected function processMembership($membershipParams, $contactID, $customField
$membershipTypes = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $membershipTypeIDs);
$membershipType = empty($membershipTypes) ? [] : reset($membershipTypes);

$this->assign('membership_name', CRM_Utils_Array::value('name', $membershipType));
$this->assign('membership_name', $membershipType['name']);
$this->_values['membership_name'] = $membershipType['name'] ?? NULL;

$isPaidMembership = FALSE;
Expand All @@ -1360,7 +1360,7 @@ protected function processMembership($membershipParams, $contactID, $customField
$financialTypeID = $this->_values['financial_type_id'];
}
else {
$financialTypeID = CRM_Utils_Array::value('financial_type_id', $membershipType, CRM_Utils_Array::value('financial_type_id', $membershipParams));
$financialTypeID = $membershipType['financial_type_id'] ?? $membershipParams['financial_type_id'] ?? NULL;
}

if (!empty($this->_params['membership_source'])) {
Expand Down Expand Up @@ -1412,10 +1412,10 @@ protected function postProcessMembership(
$isProcessSeparateMembershipTransaction, $financialTypeID, $unprocessedLineItems) {

$membershipContribution = NULL;
$isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE);
$isTest = $membershipParams['is_test'] ?? FALSE;
$errors = $paymentResults = [];
$form->_values['isMembership'] = TRUE;
$isRecurForFirstTransaction = CRM_Utils_Array::value('is_recur', $form->_params, CRM_Utils_Array::value('is_recur', $membershipParams));
$isRecurForFirstTransaction = $form->_params['is_recur'] ?? $membershipParams['is_recur'] ?? NULL;

$totalAmount = $membershipParams['amount'];

Expand Down Expand Up @@ -1465,7 +1465,7 @@ protected function postProcessMembership(
unset($membershipParams['is_recur']);
}
list($membershipContribution, $secondPaymentResult) = $this->processSecondaryFinancialTransaction($contactID, $form, array_merge($membershipParams, ['skipLineItem' => 1]),
$isTest, $unprocessedLineItems, CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0), CRM_Utils_Array::value('financial_type_id', $membershipDetails));
$isTest, $unprocessedLineItems, $membershipDetails['minimum_fee'] ?? 0, $membershipDetails['financial_type_id'] ?? NULL);
$paymentResults[] = ['contribution_id' => $membershipContribution->id, 'result' => $secondPaymentResult];
$totalAmount = $membershipContribution->total_amount;
}
Expand All @@ -1486,7 +1486,7 @@ protected function postProcessMembership(
}
//@todo it should no longer be possible for it to get to this point & membership to not be an array
if (is_array($membershipTypeIDs) && !empty($membershipContributionID)) {
$typesTerms = CRM_Utils_Array::value('types_terms', $membershipParams, []);
$typesTerms = $membershipParams['types_terms'] ?? [];

$membershipLines = $nonMembershipLines = [];
foreach ($unprocessedLineItems as $priceSetID => $lines) {
Expand All @@ -1509,7 +1509,7 @@ protected function postProcessMembership(
$membershipLineItems = $unprocessedLineItems;
}
$i++;
$numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1);
$numTerms = $typesTerms[$memType] ?? 1;
$contributionRecurID = $form->_params['contributionRecurID'] ?? NULL;

$membershipSource = NULL;
Expand Down Expand Up @@ -1537,11 +1537,21 @@ protected function postProcessMembership(
$pending = $membershipContribution->contribution_status_id == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
}
else {
$pending = $this->getIsPending();
// The concept of contributeMode is deprecated.
// the is_monetary concept probably should be too as it can be calculated from
// the existence of 'amount' & seems fragile.
if (((isset($this->_contributeMode)) || !empty($this->_params['is_pay_later'])
) &&
(($this->_values['is_monetary'] && $this->_amount > 0.0))
) {
$pending = TRUE;
}
$pending = FALSE;
}

list($membership, $renewalMode, $dates) = CRM_Member_BAO_Membership::processMembership(
$contactID, $memType, $isTest,
date('YmdHis'), CRM_Utils_Array::value('cms_contactID', $membershipParams),
date('YmdHis'), $membershipParams['cms_contactID'] ?? NULL,
$customFieldsFormatted,
$numTerms, $membershipID, $pending,
$contributionRecurID, $membershipSource, $isPayLater, $campaignId, [], $membershipContribution,
Expand Down Expand Up @@ -1648,7 +1658,7 @@ protected function postProcessMembership(
if (!empty($membershipContribution) && !is_a($membershipContribution, 'CRM_Core_Error')) {
if (empty($form->_paymentProcessor)) {
// @todo this can maybe go now we are setting payment_processor_id = 0 more reliably.
$paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor', $this->_values));
$paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_values['payment_processor'] ?? NULL);
$this->_paymentProcessor['id'] = $paymentProcessorIDs[0];
}
$result = ['payment_status_id' => 1, 'contribution' => $membershipContribution];
Expand Down Expand Up @@ -1731,10 +1741,9 @@ protected function processSecondaryFinancialTransaction($contactID, &$form, $tem
'contact_id' => $contactID,
'line_item' => $lineItems,
'is_test' => $isTest,
'campaign_id' => CRM_Utils_Array::value('campaign_id', $tempParams, CRM_Utils_Array::value('campaign_id',
$form->_values)),
'campaign_id' => $tempParams['campaign_id'] ?? $form->_values['campaign_id'] ?? NULL,
'contribution_page_id' => $form->_id,
'source' => CRM_Utils_Array::value('source', $tempParams, CRM_Utils_Array::value('description', $tempParams)),
'source' => $tempParams['source'] ?? $tempParams['description'] ?? NULL,
];
$isMonetary = !empty($form->_values['is_monetary']);
if ($isMonetary) {
Expand Down Expand Up @@ -1787,27 +1796,6 @@ protected function processSecondaryFinancialTransaction($contactID, &$form, $tem
return [$membershipContribution, $result];
}

/**
* Is the payment a pending payment.
*
* We are moving towards always creating as pending and updating at the end (based on payment), so this should be
* an interim refactoring. It was shared with another unrelated form & some parameters may not apply to this form.
*
* @return bool
*/
protected function getIsPending() {
// The concept of contributeMode is deprecated.
// the is_monetary concept probably should be too as it can be calculated from
// the existence of 'amount' & seems fragile.
if (((isset($this->_contributeMode)) || !empty($this->_params['is_pay_later'])
) &&
(($this->_values['is_monetary'] && $this->_amount > 0.0))
) {
return TRUE;
}
return FALSE;
}

/**
* Are we going to do 2 financial transactions.
*
Expand Down Expand Up @@ -1875,7 +1863,7 @@ public function setFormAmountFields($priceSetID) {
!empty($this->_membershipBlock['is_separate_payment'])
&& !empty($this->_values['fee'][$priceField->id])
&& ($this->_values['fee'][$priceField->id]['name'] == "other_amount")
&& CRM_Utils_Array::value("price_{$paramWeDoNotUnderstand}", $this->_params) < 1
&& ($this->_params["price_{$paramWeDoNotUnderstand}"] ?? NULL) < 1
&& empty($this->_params["price_{$priceField->id}"])
) {
$this->_params['amount'] = NULL;
Expand All @@ -1888,8 +1876,8 @@ public function setFormAmountFields($priceSetID) {
//@todo - merge with section above
if (!empty($this->_membershipBlock['is_separate_payment'])
&& !empty($this->_values['fee'][$priceField->id])
&& CRM_Utils_Array::value('name', $this->_values['fee'][$priceField->id]) == 'contribution_amount'
&& CRM_Utils_Array::value("price_{$priceField->id}", $this->_params) == '-1'
&& ($this->_values['fee'][$priceField->id]['name'] ?? NULL) == 'contribution_amount'
&& ($this->_params["price_{$priceField->id}"] ?? NULL) == '-1'
) {
$this->_params['amount'] = NULL;
}
Expand Down Expand Up @@ -1976,7 +1964,7 @@ public static function submit($params) {
}
$form->set('memberPriceFieldIDS', $membershipPriceFieldIDs);
$form->setRecurringMembershipParams();
$form->processFormSubmission(CRM_Utils_Array::value('contact_id', $params));
$form->processFormSubmission($params['contact_id'] ?? NULL);
}

/**
Expand Down Expand Up @@ -2208,7 +2196,7 @@ protected function processFormSubmission($contactID) {
$this->_contactID = $contactID;

//get email primary first if exist
$subscriptionEmail = ['email' => CRM_Utils_Array::value('email-Primary', $params)];
$subscriptionEmail = ['email' => $params['email-Primary'] ?? NULL];
if (!$subscriptionEmail['email']) {
$subscriptionEmail['email'] = $params["email-{$this->_bltID}"] ?? NULL;
}
Expand Down Expand Up @@ -2305,7 +2293,7 @@ protected function processFormSubmission($contactID) {
$contactID,
$this->wrangleFinancialTypeID($this->_values['financial_type_id']),
($this->_mode == 'test') ? 1 : 0,
CRM_Utils_Array::value('is_recur', $paymentParams)
$paymentParams['is_recur'] ?? NULL
);

if (empty($result['is_payment_failure'])) {
Expand Down Expand Up @@ -2471,12 +2459,12 @@ protected function doMembershipProcessing($contactID, $membershipParams, $premiu
* @throws \Exception
*/
protected function completeTransaction($result, $contributionID) {
if (CRM_Utils_Array::value('payment_status_id', $result) == 1) {
if (($result['payment_status_id'] ?? NULL) == 1) {
try {
civicrm_api3('contribution', 'completetransaction', [
'id' => $contributionID,
'trxn_id' => $result['trxn_id'] ?? NULL,
'payment_processor_id' => CRM_Utils_Array::value('payment_processor_id', $result, $this->_paymentProcessor['id']),
'payment_processor_id' => $result['payment_processor_id'] ?? $this->_paymentProcessor['id'],
'is_transactional' => FALSE,
'fee_amount' => $result['fee_amount'] ?? NULL,
'receive_date' => $result['receive_date'] ?? NULL,
Expand Down

0 comments on commit cbbbf0e

Please sign in to comment.