$processor['object']->setPaymentInstrumentID($paymentInstrumentID);
$paymentTypeName = self::getPaymentTypeName($processor);
$form->assign('paymentTypeName', $paymentTypeName);
- $paymentTypeLabel = self::getPaymentTypeLabel($processor);
- $form->assign('paymentTypeLabel', $paymentTypeLabel);
+ $form->assign('paymentTypeLabel', self::getPaymentLabel($processor['object']));
$form->assign('isBackOffice', $isBackOffice);
$form->_paymentFields = $form->billingFieldSets[$paymentTypeName]['fields'] = self::getPaymentFieldMetadata($processor);
$form->_paymentFields = array_merge($form->_paymentFields, self::getBillingAddressMetadata($processor, $form->_bltID));
* Fields that are to be shown on the payment form.
*/
protected static function addCommonFields(&$form, $paymentFields) {
- $requiredPaymentFields = array();
+ $requiredPaymentFields = $paymentFieldsMetadata = [];
foreach ($paymentFields as $name => $field) {
- // @todo - remove the cc_field check - no longer useful.
- if (!empty($field['cc_field'])) {
- if ($field['htmlType'] == 'chainSelect') {
- $form->addChainSelect($field['name'], array('required' => FALSE));
- }
- else {
- $form->add($field['htmlType'],
- $field['name'],
- $field['title'],
- $field['attributes'],
- FALSE
- );
- }
+ if ($field['htmlType'] == 'chainSelect') {
+ $form->addChainSelect($field['name'], array('required' => FALSE));
+ }
+ else {
+ $form->add($field['htmlType'],
+ $field['name'],
+ $field['title'],
+ $field['attributes'],
+ FALSE
+ );
}
// This will cause the fields to be marked as required - but it is up to the payment processor to
// validate it.
$requiredPaymentFields[$field['name']] = $field['is_required'];
+ $paymentFieldsMetadata[$field['name']] = $field;
}
+
+ $form->assign('paymentFieldsMetadata', $paymentFieldsMetadata);
$form->assign('requiredPaymentFields', $requiredPaymentFields);
}
* @return string
*/
public static function getPaymentTypeLabel($paymentProcessor) {
- return ts(($paymentProcessor['object']->getPaymentTypeLabel()) . ' Information');
+ return ts('%1 Information', [$paymentProcessor->getPaymentTypeLabel()]);
}
/**
$payment->validatePaymentInstrument($values, $errors);
}
- /**
- * The credit card pseudo constant results only the CC label, not the key ID
- * So we normalize the name to use it as a CSS class.
- */
- public static function getCreditCardCSSNames($creditCards = array()) {
- $creditCardTypes = array();
- if (empty($creditCards)) {
- $creditCards = CRM_Contribute_PseudoConstant::creditCard();
- }
- foreach ($creditCards as $key => $name) {
- // Replace anything not css-friendly by an underscore
- // Non-latin names will not like this, but so many things are wrong with
- // the credit-card type configurations already.
- $key = str_replace(' ', '', $key);
- $key = preg_replace('/[^a-zA-Z0-9]/', '_', $key);
- $key = strtolower($key);
- $creditCardTypes[$key] = $name;
- }
- return $creditCardTypes;
- }
-
/**
* Set default values for the form.
*
return CRM_Utils_Array::value('Y', $src['credit_card_exp_date']);
}
+ /**
+ * Get the label for the processor.
+ *
+ * We do not use a label if there are no enterable fields.
+ *
+ * @param \CRM_Core_Payment $processor
+ *
+ * @return string
+ */
+ public static function getPaymentLabel($processor) {
+ $isVisible = FALSE;
+ $paymentTypeLabel = self::getPaymentTypeLabel($processor);
+ foreach (self::getPaymentFieldMetadata(['object' => $processor]) as $paymentField) {
+ if ($paymentField['htmlType'] !== 'hidden') {
+ $isVisible = TRUE;
+ }
+ }
+ return $isVisible ? $paymentTypeLabel : '';
+
+ }
+
}