/** * Add payment fields depending on payment processor. The payment processor can implement the following functions to override the built in fields. * * - getPaymentFormFields() * - getPaymentFormFieldsMetadata() * (planned - getBillingDetailsFormFields(), getBillingDetailsFormFieldsMetadata() * * Note that this code is written to accommodate the possibility CiviCRM will switch to implementing pay later as a manual processor in future * * @param CRM_Contribute_Form_AbstractEditPayment|CRM_Contribute_Form_Contribution_Main $form * @param array $processor * Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors. * @param bool $forceBillingFieldsForPayLater * Display billing fields even for pay later. */ public static function setPaymentFieldsByProcessor(&$form, $processor, $forceBillingFieldsForPayLater = FALSE) { $form->billingFieldSets = array(); if ($processor != NULL) { // ie it is pay later $paymentFields = self::getPaymentFields($processor); $paymentTypeName = self::getPaymentTypeName($processor); $paymentTypeLabel = self::getPaymentTypeLabel($processor); //@todo if we switch to iterating through $form->billingFieldSets we won't need to assign these directly $form->assign('paymentTypeName', $paymentTypeName); $form->assign('paymentTypeLabel', $paymentTypeLabel); $form->billingFieldSets[$paymentTypeName]['fields'] = $form->_paymentFields = array_intersect_key(self::getPaymentFieldMetadata($processor), array_flip($paymentFields)); $form->billingPane = array($paymentTypeName => $paymentTypeLabel); $form->assign('paymentFields', $paymentFields); } // @todo - replace this section with one similar to above per discussion - probably use a manual processor shell class to stand in for that capability //return without adding billing fields if billing_mode = 4 (@todo - more the ability to set that to the payment processor) // or payment processor is NULL (pay later) if ($processor == NULL && !$forceBillingFieldsForPayLater || CRM_Utils_Array::value('billing_mode', $processor) == 4) { return; } //@todo setPaymentFields defines the billing fields - this should be moved to the processor class & renamed getBillingFields // potentially pay later would also be a payment processor //also set the billingFieldSet to hold all the details required to render the fieldset so we can iterate through the fieldset - making // it easier to re-order in hooks etc. The billingFieldSets param is used to determine whether to show the billing pane CRM_Core_Payment_Form::setBillingDetailsFields($form); $form->billingFieldSets['billing_name_address-group']['fields'] = array(); }
/** * Set billing fields for pay later. * * This is considered hacky because pay later has basically been cludged onto the payment processor form. * * See notes on the deprecated function as to how this could be restructured. Alternatively this pay later * handling could be moved out of the payment processor form all together. * * @param CRM_Core_Form $form * @param int $forceBillingFieldsForPayLater */ protected static function hackyHandlePayLaterInPaymentProcessorFunction(&$form, $forceBillingFieldsForPayLater) { if ($forceBillingFieldsForPayLater) { CRM_Core_Payment_Form::setBillingDetailsFields($form); $form->billingFieldSets['billing_name_address-group']['fields'] = array(); } }