Merge pull request #21965 from civicrm/5.43
[civicrm-core.git] / CRM / Core / Payment.php
index e19da90c3a5e19e2617fef8ac78cf0a21befb0e5..16f4691d06e630a79115ec12df758c96b221ccc1 100644 (file)
@@ -1166,9 +1166,9 @@ abstract class CRM_Core_Payment {
   protected function getAmount($params = []) {
     if (!CRM_Utils_Rule::numeric($params['amount'])) {
       CRM_Core_Error::deprecatedWarning('Passing Amount value that is not numeric is deprecated please report this in gitlab');
-      return filter_var($params['amount'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
+      return CRM_Utils_Money::formatUSLocaleNumericRounded(filter_var($params['amount'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION), 2);
     }
-    return $params['amount'];
+    return CRM_Utils_Money::formatUSLocaleNumericRounded($params['amount'], 2);
   }
 
   /**
@@ -1279,7 +1279,7 @@ abstract class CRM_Core_Payment {
    *   URL to notify outcome of transaction.
    */
   protected function getNotifyUrl() {
-    $url = CRM_Utils_System::url(
+    $url = CRM_Utils_System::getNotifyUrl(
       'civicrm/payment/ipn/' . $this->_paymentProcessor['id'],
       [],
       TRUE,
@@ -1302,6 +1302,23 @@ abstract class CRM_Core_Payment {
    *   the result in an nice formatted array (or an error object - but throwing exceptions is preferred)
    */
   protected function doDirectPayment(&$params) {
+    CRM_Core_Error::deprecatedFunctionWarning('doPayment');
+    return $params;
+  }
+
+  /**
+   * Calling this from outside the payment subsystem is deprecated - use doPayment.
+   * @deprecated
+   *
+   * @param array $params
+   *   Assoc array of input parameters for this transaction.
+   * @param string $component
+   *
+   * @return array
+   *   the result in an nice formatted array (or an error object - but throwing exceptions is preferred)
+   */
+  protected function doTransferCheckout(&$params, $component = 'contribute') {
+    CRM_Core_Error::deprecatedFunctionWarning('doPayment');
     return $params;
   }
 
@@ -1347,32 +1364,39 @@ abstract class CRM_Core_Payment {
    * @throws \Civi\Payment\Exception\PaymentProcessorException
    */
   public function doPayment(&$params, $component = 'contribute') {
+    $propertyBag = \Civi\Payment\PropertyBag::cast($params);
     $this->_component = $component;
     $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) {
+    // have an example of that at the moment.
+    if ($propertyBag->getAmount() == 0) {
       $result['payment_status_id'] = array_search('Completed', $statuses);
+      $result['payment_status'] = 'Completed';
       return $result;
     }
 
     if ($this->_paymentProcessor['billing_mode'] == 4) {
+      CRM_Core_Error::deprecatedFunctionWarning('doPayment', 'doTransferCheckout');
       $result = $this->doTransferCheckout($params, $component);
       if (is_array($result) && !isset($result['payment_status_id'])) {
         $result['payment_status_id'] = array_search('Pending', $statuses);
+        $result['payment_status'] = 'Pending';
       }
     }
     else {
+      CRM_Core_Error::deprecatedFunctionWarning('doPayment', 'doDirectPayment');
       $result = $this->doDirectPayment($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';
         }
       }
     }