Ejemplo n.º 1
0
 /**
  * Takes a bunch of params that are needed to match certain criteria and
  * retrieves the relevant objects. Typically the valid params are only
  * contact_id. We'll tweak this function to be more full featured over a period
  * of time. This is the inverse function of create. It also stores all the retrieved
  * values in the default array
  *
  * @param array $params   (reference ) an assoc array of name/value pairs
  * @param array $defaults (reference ) an assoc array to hold the flattened values
  *
  * @return object CRM_Contribute_BAO_ContributionType object
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     $financialItem = new CRM_Financial_DAO_FinancialTrxn();
     $financialItem->copyValues($params);
     if ($financialItem->find(true)) {
         CRM_Core_DAO::storeValues($financialItem, $defaults);
         return $financialItem;
     }
     return null;
 }
Ejemplo n.º 2
0
 /**
  * assignProportionalLineItems() method (add and edit modes of participant)
  */
 public function testAssignProportionalLineItems()
 {
     list($lineItems, $contribution) = $this->addParticipantWithContribution();
     $contributions['total_amount'] = $contribution->total_amount;
     $params = array('contribution_id' => $contribution->id, 'total_amount' => 150.0);
     $trxn = new CRM_Financial_DAO_FinancialTrxn();
     $trxn->orderBy('id DESC');
     $trxn->find(TRUE);
     CRM_Contribute_BAO_Contribution::assignProportionalLineItems($params, $trxn, $contributions);
     $this->checkItemValues($contribution);
 }
Ejemplo n.º 3
0
 /**
  * Returns the list of fields that can be exported
  *
  * @param bool $prefix
  *
  * @return array
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['financial_trxn'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 /**
  * check method del()
  */
 function testCreateEntityTrxn()
 {
     $fParams = array('name' => 'Donations' . substr(sha1(rand()), 0, 7), 'is_deductible' => 0, 'is_active' => 1);
     $amount = 200;
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($fParams, $ids);
     $financialTrxn = new CRM_Financial_DAO_FinancialTrxn();
     $financialTrxn->to_financial_account_id = $financialAccount->id;
     $financialTrxn->total_amount = $amount;
     $financialTrxn->save();
     $params = array('entity_table' => 'civicrm_contribution', 'entity_id' => 1, 'financial_trxn_id' => $financialTrxn->id, 'amount' => $amount);
     $entityTrxn = CRM_Financial_BAO_FinancialItem::createEntityTrxn($params);
     $entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $financialTrxn->id, 'amount', 'financial_trxn_id', 'Database check on added entity financial trxn record.');
     $this->assertEquals($entityResult, $amount, 'Verify Amount for Financial Item');
     return $entityTrxn;
 }
Ejemplo n.º 5
0
 function make_payment(&$params)
 {
     $config = CRM_Core_Config::singleton();
     if (isset($params["billing_state_province_id-{$this->_bltID}"]) && $params["billing_state_province_id-{$this->_bltID}"]) {
         $params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["billing_state_province_id-{$this->_bltID}"]);
     }
     if (isset($params["billing_country_id-{$this->_bltID}"]) && $params["billing_country_id-{$this->_bltID}"]) {
         $params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["billing_country_id-{$this->_bltID}"]);
     }
     $params['ip_address'] = CRM_Utils_System::ipAddress();
     $params['currencyID'] = $config->defaultCurrency;
     $params['payment_action'] = 'Sale';
     $payment =& CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
     CRM_Core_Payment_Form::mapParams($this->_bltID, $params, $params, TRUE);
     $params['month'] = $params['credit_card_exp_date']['M'];
     $params['year'] = $params['credit_card_exp_date']['Y'];
     $result =& $payment->doDirectPayment($params);
     if (is_a($result, 'CRM_Core_Error')) {
         CRM_Core_Error::displaySessionError($result);
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/cart_checkout', "_qf_Payment_display=1&qfKey={$this->controller->_key}", TRUE, NULL, FALSE));
         return;
     } elseif (!$result['trxn_id']) {
         CRM_Core_Error::fatal(ts("Financial institution didn't return a transaction id."));
     }
     $trxnParams = array('trxn_date' => $params['now'], 'trxn_type' => 'Debit', 'total_amount' => $params['amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'currency' => CRM_Utils_Array::value('currencyID', $params), 'payment_processor' => $this->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']);
     $trxn = new CRM_Financial_DAO_FinancialTrxn();
     $trxn->copyValues($trxnParams);
     if (!CRM_Utils_Rule::currencyCode($trxn->currency)) {
         $config = CRM_Core_Config::singleton();
         $trxn->currency = $config->defaultCurrency;
     }
     $trxn->save();
     return $trxn;
 }