+ * @param array $paymentProcessor
+ * @todo it will be necessary to set details that affect it - mostly likely take Country as a param. Should we add generic
+ * setParams on processor class or just setCountry which we know we need?
+ *
+ * @return array
+ */
+ static function getPaymentFields($paymentProcessor) {
+ $paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
+ return $paymentProcessorObject->getPaymentFormFields();
+ }
+
+ /**
+ * @param array $paymentProcessor
+ *
+ * @return array
+ */
+ static function getPaymentFieldMetadata($paymentProcessor) {
+ $paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
+ return $paymentProcessorObject->getPaymentFormFieldsMetadata();
+ }
+
+ /**
+ * @param array $paymentProcessor
+ *
+ * @return string
+ */
+ static function getPaymentTypeName($paymentProcessor) {
+ $paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
+ return $paymentProcessorObject->getPaymentTypeName();
+ }
+
+ /**
+ * @param array $paymentProcessor
+ *
+ * @return string
+ */
+ static function getPaymentTypeLabel($paymentProcessor) {
+ $paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
+ return ts(($paymentProcessorObject->getPaymentTypeLabel()) . ' Information');
+ }
+
+ /**
+ * @param CRM_Contribute_Form_Contribution| CRM_Contribute_Form_Contribution_Main|CRM_Member_Form_Membership $form
+ * @param array $processor array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors
+ * @param bool $isBillingDataOptional
+ *
+ * @return bool
+ */
+ static function buildPaymentForm($form, $processor, $isBillingDataOptional){
+ self::setPaymentFieldsByProcessor($form, $processor);
+ self::addCommonFields($form, !$isBillingDataOptional, $form->_paymentFields);
+ self::addRules($form, $form->_paymentFields);
+ self::addPaypalExpressCode($form);
+ return (!empty($form->_paymentFields));
+ }
+
+ /**
+ * @param CRM_Core_Form $form
+ * @param array $paymentFields array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors
+
+ * @param $paymentFields
+ */
+ protected static function addRules(&$form, $paymentFields) {
+ foreach ($paymentFields as $paymentField => $fieldSpecs) {
+ if (!empty($fieldSpecs['rules'])) {
+ foreach ($fieldSpecs['rules'] as $rule) {
+ $form->addRule($paymentField,
+ $rule['rule_message'],
+ $rule['rule_name'],
+ $rule['rule_parameters']
+ );
+ }
+ }
+ }
+ }
+
+ /**
+ * billing mode button is basically synonymous with paypal express - this is probably a good example of 'odds & sods' code we
+ * need to find a way for the payment processor to assign. A tricky aspect is that the payment processor may need to set the order