Merge remote branch 'canonical/master' into merge-forward
[civicrm-core.git] / CRM / Contribute / BAO / Contribution / Utils.php
index 94f44b1729c7c9cec7c78e42999218671fb2b6d2..f4b958f98d16d21531112566da4de6fae9fe3dfe 100644 (file)
@@ -37,14 +37,16 @@ class CRM_Contribute_BAO_Contribution_Utils {
   /**
    * Function to process payment after confirmation
    *
-   * @param object  $form   form object
-   * @param array   $paymentParams   array with payment related key
+   * @param object $form form object
+   * @param array $paymentParams array with payment related key
    * value pairs
-   * @param array   $premiumParams   array with premium related key
+   * @param array $premiumParams array with premium related key
    * value pairs
-   * @param int     $contactID       contact id
-     * @param int     $contributionTypeId   financial type id
-   * @param int     $component   component id
+   * @param int $contactID contact id
+   * @param int $contributionTypeId financial type id
+   * @param int|string $component component id
+   *
+   * @param null $fieldTypes
    *
    * @return array associated array
    *
@@ -60,6 +62,8 @@ class CRM_Contribute_BAO_Contribution_Utils {
     $fieldTypes = NULL
   ) {
     CRM_Core_Payment_Form::mapParams($form->_bltID, $form->_params, $paymentParams, TRUE);
+    $isTest = ($form->_mode == 'test') ? 1 : 0;
+    $lineItems = $form->_lineItem;
 
     $contributionType = new CRM_Financial_DAO_FinancialType();
     if (isset($paymentParams['financial_type'])) {
@@ -109,7 +113,9 @@ class CRM_Contribute_BAO_Contribution_Utils {
         NULL,
         $contactID,
         $contributionType,
-        TRUE, TRUE, TRUE
+        TRUE, TRUE,
+        $isTest,
+        $lineItems
       );
 
       if ($contribution) {
@@ -228,7 +234,9 @@ class CRM_Contribute_BAO_Contribution_Utils {
           NULL,
           $contactID,
           $contributionType,
-          TRUE, TRUE, TRUE
+          TRUE, TRUE,
+          $isTest,
+          $lineItems
         );
 
         // restore cached values (part of fix for CRM-14354)
@@ -298,15 +306,16 @@ class CRM_Contribute_BAO_Contribution_Utils {
 
       // check if pending was set to true by payment processor
       $pending = FALSE;
-      if (!empty($form->_params
-['contribution_status_pending'])) {
+      if (!empty($form->_params['contribution_status_pending'])) {
         $pending = TRUE;
       }
       if (!(!empty($paymentParams['is_recur']) && $form->_contributeMode == 'direct')) {
         $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($form,
           $form->_params, $result,
           $contactID, $contributionType,
-          TRUE, $pending, TRUE
+          $pending, TRUE,
+          $isTest,
+          $lineItems
         );
       }
       $form->postProcessPremium($premiumParams, $contribution);
@@ -427,6 +436,11 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     return $params;
   }
 
+  /**
+   * @param $params
+   * @param $contactID
+   * @param $mail
+   */
   static function createCMSUser(&$params, $contactID, $mail) {
     // lets ensure we only create one CMS user
     static $created = FALSE;
@@ -444,6 +458,12 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     }
   }
 
+  /**
+   * @param $params
+   * @param string $type
+   *
+   * @return bool
+   */
   static function _fillCommonParams(&$params, $type = 'paypal') {
     if (array_key_exists('transaction', $params)) {
       $transaction = &$params['transaction'];
@@ -508,6 +528,14 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     return TRUE;
   }
 
+  /**
+   * @param $apiParams
+   * @param $mapper
+   * @param string $type
+   * @param bool $category
+   *
+   * @return array
+   */
   static function formatAPIParams($apiParams, $mapper, $type = 'paypal', $category = TRUE) {
     $type = strtolower($type);
 
@@ -701,6 +729,11 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     }
   }
 
+  /**
+   * @param $params
+   *
+   * @return bool
+   */
   static function processAPIContribution($params) {
     if (empty($params) || array_key_exists('error', $params)) {
       return FALSE;
@@ -779,6 +812,11 @@ INNER JOIN   civicrm_contact contact ON ( contact.id = contrib.contact_id )
     return TRUE;
   }
 
+  /**
+   * @param $contactID
+   *
+   * @return mixed
+   */
   static function getFirstLastDetails($contactID) {
     static $_cache;
 
@@ -822,5 +860,24 @@ LIMIT 1
     }
     return $_cache[$contactID];
   }
+
+  /**
+   * Calculate the tax amount based on given tax rate.
+   *
+   * @param float $amount amount of field.
+   * @param float $taxRate tax rate of selected financial account for field.
+   *
+   * @return array array of tax amount
+   *
+   * @access public
+   * @static
+   *
+   */
+  public static function calculateTaxAmount($amount, $taxRate) {
+    $taxAmount = array();
+    $taxAmount['tax_amount'] = ($taxRate/100) * $amount;
+
+    return $taxAmount;
+  }
 }