From 9e3bf561d5b210cc6f8e3974afb24313ec9aa817 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 18 Mar 2019 10:41:41 +1300 Subject: [PATCH] [NFC] code formatting only IDE reformatting to fix array formats --- CRM/Core/Payment.php | 284 +++++++++++++++++++++++-------------------- 1 file changed, 155 insertions(+), 129 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index e88c11c660..f21aeec500 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -413,7 +413,8 @@ abstract class CRM_Core_Payment { * - pre_approval_parameters (this will be stored on the calling form & available later) * - redirect_url (if set the browser will be redirected to this. */ - public function doPreApproval(&$params) {} + public function doPreApproval(&$params) { + } /** * Get any details that may be available to the payment processor due to an approval process having happened. @@ -426,7 +427,7 @@ abstract class CRM_Core_Payment { * @return array */ public function getPreApprovalDetails($storedDetails) { - return array(); + return []; } /** @@ -509,7 +510,10 @@ abstract class CRM_Core_Payment { switch ($context) { case 'contributionPageRecurringHelp': // require exactly two parameters - if (array_keys($params) == array('is_recur_installments', 'is_email_receipt')) { + if (array_keys($params) == [ + 'is_recur_installments', + 'is_email_receipt', + ]) { $gotText = ts('Your recurring contribution will be processed automatically.'); if ($params['is_recur_installments']) { $gotText .= ' ' . ts('You can specify the number of installments, or you can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time.'); @@ -571,7 +575,7 @@ abstract class CRM_Core_Payment { */ public function getPaymentFormFields() { if ($this->_paymentProcessor['billing_mode'] == 4) { - return array(); + return []; } return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields(); } @@ -603,7 +607,7 @@ abstract class CRM_Core_Payment { */ public function getEditableRecurringScheduleFields() { if ($this->supports('changeSubscriptionAmount')) { - return array('amount'); + return ['amount']; } } @@ -627,7 +631,7 @@ abstract class CRM_Core_Payment { * @return array; */ protected function getMandatoryFields() { - $mandatoryFields = array(); + $mandatoryFields = []; foreach ($this->getAllFields() as $field_name => $field_spec) { if (!empty($field_spec['is_required'])) { $mandatoryFields[$field_name] = $field_spec; @@ -646,18 +650,19 @@ abstract class CRM_Core_Payment { $billingFields = array_intersect_key($this->getBillingAddressFieldsMetadata(), array_flip($this->getBillingAddressFields())); return array_merge($paymentFields, $billingFields); } + /** * Get array of fields that should be displayed on the payment form for credit cards. * * @return array */ protected function getCreditCardFormFields() { - return array( + return [ 'credit_card_type', 'credit_card_number', 'cvv2', 'credit_card_exp_date', - ); + ]; } /** @@ -666,12 +671,12 @@ abstract class CRM_Core_Payment { * @return array */ protected function getDirectDebitFormFields() { - return array( + return [ 'account_holder', 'bank_account_number', 'bank_identification_number', 'bank_name', - ); + ]; } /** @@ -684,160 +689,164 @@ abstract class CRM_Core_Payment { */ public function getPaymentFormFieldsMetadata() { //@todo convert credit card type into an option value - $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard(); + $creditCardType = ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::creditCard(); $isCVVRequired = Civi::settings()->get('cvv_backoffice_required'); if (!$this->isBackOffice()) { $isCVVRequired = TRUE; } - return array( - 'credit_card_number' => array( + return [ + 'credit_card_number' => [ 'htmlType' => 'text', 'name' => 'credit_card_number', 'title' => ts('Card Number'), - 'attributes' => array( + 'attributes' => [ 'size' => 20, 'maxlength' => 20, 'autocomplete' => 'off', 'class' => 'creditcard', - ), + ], 'is_required' => TRUE, // 'description' => '16 digit card number', // If you enable a description field it will be shown below the field on the form - ), - 'cvv2' => array( + ], + 'cvv2' => [ 'htmlType' => 'text', 'name' => 'cvv2', 'title' => ts('Security Code'), - 'attributes' => array( + 'attributes' => [ 'size' => 5, 'maxlength' => 10, 'autocomplete' => 'off', - ), + ], 'is_required' => $isCVVRequired, - 'rules' => array( - array( + 'rules' => [ + [ 'rule_message' => ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'), 'rule_name' => 'integer', 'rule_parameters' => NULL, - ), - ), - ), - 'credit_card_exp_date' => array( + ], + ], + ], + 'credit_card_exp_date' => [ 'htmlType' => 'date', 'name' => 'credit_card_exp_date', 'title' => ts('Expiration Date'), 'attributes' => CRM_Core_SelectValues::date('creditCard'), 'is_required' => TRUE, - 'rules' => array( - array( + 'rules' => [ + [ 'rule_message' => ts('Card expiration date cannot be a past date.'), 'rule_name' => 'currentDate', 'rule_parameters' => TRUE, - ), - ), + ], + ], 'extra' => ['class' => 'crm-form-select'], - ), - 'credit_card_type' => array( + ], + 'credit_card_type' => [ 'htmlType' => 'select', 'name' => 'credit_card_type', 'title' => ts('Card Type'), 'attributes' => $creditCardType, 'is_required' => FALSE, - ), - 'account_holder' => array( + ], + 'account_holder' => [ 'htmlType' => 'text', 'name' => 'account_holder', 'title' => ts('Account Holder'), - 'attributes' => array( + 'attributes' => [ 'size' => 20, 'maxlength' => 34, 'autocomplete' => 'on', - ), + ], 'is_required' => TRUE, - ), + ], //e.g. IBAN can have maxlength of 34 digits - 'bank_account_number' => array( + 'bank_account_number' => [ 'htmlType' => 'text', 'name' => 'bank_account_number', 'title' => ts('Bank Account Number'), - 'attributes' => array( + 'attributes' => [ 'size' => 20, 'maxlength' => 34, 'autocomplete' => 'off', - ), - 'rules' => array( - array( + ], + 'rules' => [ + [ 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), 'rule_name' => 'nopunctuation', 'rule_parameters' => NULL, - ), - ), + ], + ], 'is_required' => TRUE, - ), + ], //e.g. SWIFT-BIC can have maxlength of 11 digits - 'bank_identification_number' => array( + 'bank_identification_number' => [ 'htmlType' => 'text', 'name' => 'bank_identification_number', 'title' => ts('Bank Identification Number'), - 'attributes' => array( + 'attributes' => [ 'size' => 20, 'maxlength' => 11, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - 'rules' => array( - array( + 'rules' => [ + [ 'rule_message' => ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'), 'rule_name' => 'nopunctuation', 'rule_parameters' => NULL, - ), - ), - ), - 'bank_name' => array( + ], + ], + ], + 'bank_name' => [ 'htmlType' => 'text', 'name' => 'bank_name', 'title' => ts('Bank Name'), - 'attributes' => array( + 'attributes' => [ 'size' => 20, 'maxlength' => 64, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - ), - 'check_number' => array( + ], + 'check_number' => [ 'htmlType' => 'text', 'name' => 'check_number', 'title' => ts('Check Number'), 'is_required' => FALSE, 'attributes' => NULL, - ), - 'pan_truncation' => array( + ], + 'pan_truncation' => [ 'htmlType' => 'text', 'name' => 'pan_truncation', 'title' => ts('Last 4 digits of the card'), 'is_required' => FALSE, - 'attributes' => array( + 'attributes' => [ 'size' => 4, 'maxlength' => 4, 'minlength' => 4, 'autocomplete' => 'off', - ), - 'rules' => array( - array( + ], + 'rules' => [ + [ 'rule_message' => ts('Please enter valid last 4 digit card number.'), 'rule_name' => 'numeric', 'rule_parameters' => NULL, - ), - ), - ), - 'payment_token' => array( + ], + ], + ], + 'payment_token' => [ 'htmlType' => 'hidden', 'name' => 'payment_token', 'title' => ts('Authorization token'), 'is_required' => FALSE, - 'attributes' => ['size' => 10, 'autocomplete' => 'off', 'id' => 'payment_token'], - ), - ); + 'attributes' => [ + 'size' => 10, + 'autocomplete' => 'off', + 'id' => 'payment_token', + ], + ], + ]; } /** @@ -858,9 +867,9 @@ abstract class CRM_Core_Payment { $billingLocationID = CRM_Core_BAO_LocationType::getBilling(); } if ($this->_paymentProcessor['billing_mode'] != 1 && $this->_paymentProcessor['billing_mode'] != 3) { - return array(); + return []; } - return array( + return [ 'first_name' => 'billing_first_name', 'middle_name' => 'billing_middle_name', 'last_name' => 'billing_last_name', @@ -869,7 +878,7 @@ abstract class CRM_Core_Payment { 'country' => "billing_country_id-{$billingLocationID}", 'state_province' => "billing_state_province_id-{$billingLocationID}", 'postal_code' => "billing_postal_code-{$billingLocationID}", - ); + ]; } /** @@ -887,103 +896,103 @@ abstract class CRM_Core_Payment { // So taking this as a param is possibly something to be removed in favour of the standard default. $billingLocationID = CRM_Core_BAO_LocationType::getBilling(); } - $metadata = array(); - $metadata['billing_first_name'] = array( + $metadata = []; + $metadata['billing_first_name'] = [ 'htmlType' => 'text', 'name' => 'billing_first_name', 'title' => ts('Billing First Name'), 'cc_field' => TRUE, - 'attributes' => array( + 'attributes' => [ 'size' => 30, 'maxlength' => 60, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - ); + ]; - $metadata['billing_middle_name'] = array( + $metadata['billing_middle_name'] = [ 'htmlType' => 'text', 'name' => 'billing_middle_name', 'title' => ts('Billing Middle Name'), 'cc_field' => TRUE, - 'attributes' => array( + 'attributes' => [ 'size' => 30, 'maxlength' => 60, 'autocomplete' => 'off', - ), + ], 'is_required' => FALSE, - ); + ]; - $metadata['billing_last_name'] = array( + $metadata['billing_last_name'] = [ 'htmlType' => 'text', 'name' => 'billing_last_name', 'title' => ts('Billing Last Name'), 'cc_field' => TRUE, - 'attributes' => array( + 'attributes' => [ 'size' => 30, 'maxlength' => 60, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - ); + ]; - $metadata["billing_street_address-{$billingLocationID}"] = array( + $metadata["billing_street_address-{$billingLocationID}"] = [ 'htmlType' => 'text', 'name' => "billing_street_address-{$billingLocationID}", 'title' => ts('Street Address'), 'cc_field' => TRUE, - 'attributes' => array( + 'attributes' => [ 'size' => 30, 'maxlength' => 60, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - ); + ]; - $metadata["billing_city-{$billingLocationID}"] = array( + $metadata["billing_city-{$billingLocationID}"] = [ 'htmlType' => 'text', 'name' => "billing_city-{$billingLocationID}", 'title' => ts('City'), 'cc_field' => TRUE, - 'attributes' => array( + 'attributes' => [ 'size' => 30, 'maxlength' => 60, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - ); + ]; - $metadata["billing_state_province_id-{$billingLocationID}"] = array( + $metadata["billing_state_province_id-{$billingLocationID}"] = [ 'htmlType' => 'chainSelect', 'title' => ts('State/Province'), 'name' => "billing_state_province_id-{$billingLocationID}", 'cc_field' => TRUE, 'is_required' => TRUE, - ); + ]; - $metadata["billing_postal_code-{$billingLocationID}"] = array( + $metadata["billing_postal_code-{$billingLocationID}"] = [ 'htmlType' => 'text', 'name' => "billing_postal_code-{$billingLocationID}", 'title' => ts('Postal Code'), 'cc_field' => TRUE, - 'attributes' => array( + 'attributes' => [ 'size' => 30, 'maxlength' => 60, 'autocomplete' => 'off', - ), + ], 'is_required' => TRUE, - ); + ]; - $metadata["billing_country_id-{$billingLocationID}"] = array( + $metadata["billing_country_id-{$billingLocationID}"] = [ 'htmlType' => 'select', 'name' => "billing_country_id-{$billingLocationID}", 'title' => ts('Country'), 'cc_field' => TRUE, - 'attributes' => array( - '' => ts('- select -'), - ) + CRM_Core_PseudoConstant::country(), + 'attributes' => [ + '' => ts('- select -'), + ] + CRM_Core_PseudoConstant::country(), 'is_required' => TRUE, - ); + ]; return $metadata; } @@ -1047,20 +1056,20 @@ abstract class CRM_Core_Payment { } if ($this->_component == 'event') { - return CRM_Utils_System::url($this->getBaseReturnUrl(), array( + return CRM_Utils_System::url($this->getBaseReturnUrl(), [ 'reset' => 1, 'cc' => 'fail', 'participantId' => $participantID, - ), + ], TRUE, NULL, FALSE ); } - return CRM_Utils_System::url($this->getBaseReturnUrl(), array( + return CRM_Utils_System::url($this->getBaseReturnUrl(), [ '_qf_Main_display' => 1, 'qfKey' => $qfKey, 'cancel' => 1, - ), + ], TRUE, NULL, FALSE ); } @@ -1077,10 +1086,10 @@ abstract class CRM_Core_Payment { return $this->successUrl; } - return CRM_Utils_System::url($this->getBaseReturnUrl(), array( + return CRM_Utils_System::url($this->getBaseReturnUrl(), [ '_qf_ThankYou_display' => 1, 'qfKey' => $qfKey, - ), + ], TRUE, NULL, FALSE ); } @@ -1123,10 +1132,10 @@ abstract class CRM_Core_Payment { * @return string url */ protected function getGoBackUrl($qfKey) { - return CRM_Utils_System::url($this->getBaseReturnUrl(), array( + return CRM_Utils_System::url($this->getBaseReturnUrl(), [ '_qf_Confirm_display' => 'true', 'qfKey' => $qfKey, - ), + ], TRUE, NULL, FALSE ); } @@ -1143,7 +1152,7 @@ abstract class CRM_Core_Payment { protected function getNotifyUrl() { $url = CRM_Utils_System::url( 'civicrm/payment/ipn/' . $this->_paymentProcessor['id'], - array(), + [], TRUE, NULL, FALSE, @@ -1250,7 +1259,7 @@ abstract class CRM_Core_Payment { * - fee_amount Amount of fee paid */ public function doQuery($params) { - return array(); + return []; } /** @@ -1309,7 +1318,7 @@ abstract class CRM_Core_Payment { Civi::log()->error('ipn_payment_callback_exception', [ 'context' => [ 'backtrace' => CRM_Core_Error::formatBacktrace(debug_backtrace()), - ] + ], ]); } CRM_Utils_System::civiExit(); @@ -1332,7 +1341,7 @@ abstract class CRM_Core_Payment { * @throws \CRM_Core_Exception * @throws \Exception */ - public static function handlePaymentMethod($method, $params = array()) { + public static function handlePaymentMethod($method, $params = []) { if (!isset($params['processor_id']) && !isset($params['processor_name'])) { $q = explode('/', CRM_Utils_Array::value(CRM_Core_Config::singleton()->userFrameworkURLVar, $_GET, '')); $lastParam = array_pop($q); @@ -1355,18 +1364,18 @@ abstract class CRM_Core_Payment { if (isset($params['processor_id'])) { $sql .= " WHERE pp.id = %2"; - $args[2] = array($params['processor_id'], 'Integer'); - $notFound = ts("No active instances of payment processor %1 were found.", array(1 => $params['processor_id'])); + $args[2] = [$params['processor_id'], 'Integer']; + $notFound = ts("No active instances of payment processor %1 were found.", [1 => $params['processor_id']]); } else { // This is called when processor_name is passed - passing processor_id instead is recommended. $sql .= " WHERE ppt.name = %2 AND pp.is_test = %1"; - $args[1] = array( + $args[1] = [ (CRM_Utils_Array::value('mode', $params) == 'test') ? 1 : 0, 'Integer', - ); - $args[2] = array($params['processor_name'], 'String'); - $notFound = ts("No active instances of payment processor '%1' were found.", array(1 => $params['processor_name'])); + ]; + $args[2] = [$params['processor_name'], 'String']; + $notFound = ts("No active instances of payment processor '%1' were found.", [1 => $params['processor_name']]); } $dao = CRM_Core_DAO::executeQuery($sql, $args); @@ -1399,7 +1408,7 @@ abstract class CRM_Core_Payment { // Does PP implement this method, and can we call it? if (!method_exists($processorInstance, $method) || - !is_callable(array($processorInstance, $method)) + !is_callable([$processorInstance, $method]) ) { // on the off chance there is a double implementation of this processor we should keep looking for another // note that passing processor_id is more reliable & we should work to deprecate processor_name @@ -1417,7 +1426,10 @@ abstract class CRM_Core_Payment { if (!$extension_instance_found) { $message = "No extension instances of the '%1' payment processor were found.
" . "%2 method is unsupported in legacy payment processors."; - throw new CRM_Core_Exception(ts($message, [1 => $params['processor_name'], 2 => $method])); + throw new CRM_Core_Exception(ts($message, [ + 1 => $params['processor_name'], + 2 => $method, + ])); } } @@ -1528,7 +1540,12 @@ abstract class CRM_Core_Payment { FROM civicrm_contribution_recur rec INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) WHERE rec.id = %1"; - $contactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($entityID, 'Integer'))); + $contactID = CRM_Core_DAO::singleValueQuery($sql, [ + 1 => [ + $entityID, + 'Integer', + ], + ]); $entityArg = 'crid'; break; } @@ -1567,10 +1584,19 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) * @return string */ protected function getPaymentDescription($params, $length = 24) { - $parts = array('contactID', 'contributionID', 'description', 'billing_first_name', 'billing_last_name'); - $validParts = array(); + $parts = [ + 'contactID', + 'contributionID', + 'description', + 'billing_first_name', + 'billing_last_name', + ]; + $validParts = []; if (isset($params['description'])) { - $uninformativeStrings = array(ts('Online Event Registration: '), ts('Online Contribution: ')); + $uninformativeStrings = [ + ts('Online Event Registration: '), + ts('Online Contribution: '), + ]; $params['description'] = str_replace($uninformativeStrings, '', $params['description']); } foreach ($parts as $part) { -- 2.25.1