+
+ $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate');
+
+ // If we have a $0 amount, skip call to processor and set payment_status to Completed.
+ // Conceivably a processor might override this - perhaps for setting up a token - but we don't
+ // have an example of that at the mome.
+ if ($params['amount'] == 0) {
+ $result['payment_status_id'] = array_search('Completed', $statuses);
+ $result['payment_status'] = 'Completed';
+ return $result;
+ }
+
+ if ($this->_paymentProcessor['billing_mode'] == 4) {
+ $this->doPaymentRedirectToPayPal($params, $component);
+ // redirect calls CiviExit() so execution is stopped
+ }
+ else {
+ $result = $this->doPaymentPayPalButton($params, $component);
+ if (is_array($result) && !isset($result['payment_status_id'])) {
+ if (!empty($params['is_recur'])) {
+ // See comment block.
+ $result['payment_status_id'] = array_search('Pending', $statuses);
+ $result['payment_status'] = 'Pending';
+ }
+ else {
+ $result['payment_status_id'] = array_search('Completed', $statuses);
+ $result['payment_status'] = 'Completed';
+ }
+ }
+ }
+ if (is_a($result, 'CRM_Core_Error')) {
+ CRM_Core_Error::deprecatedFunctionWarning('payment processors should throw exceptions rather than return errors');
+ throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
+ }
+ return $result;
+ }
+
+ /**
+ * Temporary function to catch transition to doPaymentPayPalButton()
+ * @deprecated
+ */
+ public function doDirectPayment(&$params) {
+ CRM_Core_Error::deprecatedFunctionWarning('doPayment');
+ return $this->doPaymentPayPalButton($params);