本文整理汇总了PHP中CRM_Contribute_BAO_Contribution::createAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contribute_BAO_Contribution::createAddress方法的具体用法?PHP CRM_Contribute_BAO_Contribution::createAddress怎么用?PHP CRM_Contribute_BAO_Contribution::createAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contribute_BAO_Contribution
的用法示例。
在下文中一共展示了CRM_Contribute_BAO_Contribution::createAddress方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processContribution
//.........这里部分代码省略.........
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
}
// first create the contribution record
$contribParams = array('contact_id' => $contactID, 'financial_type_id' => $contributionType->id, 'contribution_page_id' => $contributionPageId, 'receive_date' => CRM_Utils_Array::value('receive_date', $params) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || !empty($params['source']) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, 'campaign_id' => $campaignId);
if (!$online && isset($params['thankyou_date'])) {
$contribParams['thankyou_date'] = $params['thankyou_date'];
}
if (!$online || $form->_values['is_monetary']) {
if (empty($params['is_pay_later'])) {
$contribParams['payment_instrument_id'] = 1;
}
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $result), 'payment_processor' => CRM_Utils_Array::value('payment_processor', $result));
}
if ($recurringContributionID) {
$contribParams['contribution_recur_id'] = $recurringContributionID;
}
$contribParams['contribution_status_id'] = $pending ? 2 : 1;
$contribParams['is_test'] = 0;
if ($form->_mode == 'test') {
$contribParams['is_test'] = 1;
}
$ids = array();
if (isset($contribParams['invoice_id'])) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
if (isset($contribID)) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
}
//create an contribution address
if ($form->_contributeMode != 'notify' && empty($params['is_pay_later']) && !empty($form->_values['is_monetary'])) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
// CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
$contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
$contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
// Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
// if its due to pcp
if (!empty($params['pcp_made_through_id'])) {
$contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $params['pcp_made_through_id'], 'contact_id');
} else {
$contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
}
// Pass these details onto with the contribution to make them
// available at hook_post_process, CRM-8908
$contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
}
if (isset($params['amount'])) {
$contribParams['line_item'] = $form->_lineItem;
//add contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contact_Form_ProfileContact::postProcess($form);
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
//handle pledge stuff.
示例2: processFormContribution
/**
* Process the contribution.
*
* @param CRM_Core_Form $form
* @param array $params
* @param array $result
* @param array $contributionParams
* Parameters to be passed to contribution create action.
* This differs from params in that we are currently adding params to it and 1) ensuring they are being
* passed consistently & 2) documenting them here.
* - contact_id
* - line_item
* - is_test
* - campaign_id
* - contribution_page_id
* - source
* - payment_type_id
* - thankyou_date (not all forms will set this)
*
* @param CRM_Financial_DAO_FinancialType $financialType
* @param bool $online
* Is the form a front end form? If so set a bunch of unpredictable things that should be passed in from the form.
*
* @param int $billingLocationID
* ID of billing location type.
* @param bool $isRecur
* Is this recurring?
*
* @return \CRM_Contribute_DAO_Contribution
* @throws \Exception
*/
public static function processFormContribution(&$form, $params, $result, $contributionParams, $financialType, $online, $billingLocationID, $isRecur)
{
$transaction = new CRM_Core_Transaction();
$contactID = $contributionParams['contact_id'];
$isEmailReceipt = !empty($form->_values['is_email_receipt']);
$isSeparateMembershipPayment = empty($params['separate_membership_payment']) ? FALSE : TRUE;
$pledgeID = !empty($params['pledge_id']) ? $params['pledge_id'] : CRM_Utils_Array::value('pledge_id', $form->_values);
if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) && (!empty($params['is_pledge']) || $pledgeID)) {
$isPledge = TRUE;
} else {
$isPledge = FALSE;
}
// add these values for the recurringContrib function ,CRM-10188
$params['financial_type_id'] = $financialType->id;
$contributionParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $billingLocationID);
//@todo - this is being set from the form to resolve CRM-10188 - an
// eNotice caused by it not being set @ the front end
// however, we then get it being over-written with null for backend contributions
// a better fix would be to set the values in the respective forms rather than require
// a function being shared by two forms to deal with their respective values
// moving it to the BAO & not taking the $form as a param would make sense here.
if (!isset($params['is_email_receipt']) && $isEmailReceipt) {
$params['is_email_receipt'] = $isEmailReceipt;
}
$params['is_recur'] = $isRecur;
$recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType);
$nonDeductibleAmount = self::getNonDeductibleAmount($params, $financialType, $online);
$now = date('YmdHis');
$receiptDate = CRM_Utils_Array::value('receipt_date', $params);
if ($isEmailReceipt) {
$receiptDate = $now;
}
if (isset($params['amount'])) {
$contributionParams = array_merge(self::getContributionParams($params, $financialType->id, $nonDeductibleAmount, TRUE, $result, $receiptDate, $recurringContributionID), $contributionParams);
$contribution = CRM_Contribute_BAO_Contribution::add($contributionParams);
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
if ($invoicing) {
$dataArray = array();
// @todo - interrogate the line items passed in on the params array.
// No reason to assume line items will be set on the form.
foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
foreach ($lineItemValue as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
} else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
}
}
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('dataArray', $dataArray);
$smarty->assign('totalTaxAmount', $params['tax_amount']);
}
if (is_a($contribution, 'CRM_Core_Error')) {
$message = CRM_Core_Error::getMessages($contribution);
CRM_Core_Error::fatal($message);
}
// lets store it in the form variable so postProcess hook can get to this and use it
$form->_contributionID = $contribution->id;
}
// process soft credit / pcp params first
CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
//CRM-13981, processing honor contact into soft-credit contribution
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
//handle pledge stuff.
if ($isPledge) {
//.........这里部分代码省略.........
示例3: processContribution
/**
* Process the contribution
*
* @return void
* @access public
*/
static function processContribution(&$form, $params, $result, $contactID, $contributionType, $deductibleMode = true, $pending = false, $online = true)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$honorCId = $recurringContributionID = null;
if ($online) {
if ($form->get('honor_block_is_active')) {
$honorCId = $form->createHonorContact();
}
$recurringContributionID = $form->processRecurringContribution($params, $contactID);
} else {
if (!$online && isset($params['honor_contact_id'])) {
$honorCId = $params['honor_contact_id'];
}
}
$config =& CRM_Core_Config::singleton();
if (!$online && isset($params['non_deductible_amount'])) {
$nonDeductibleAmount = $params['non_deductible_amount'];
} else {
$nonDeductibleAmount = $params['amount'];
}
if ($online && $contributionType->is_deductible && $deductibleMode) {
$selectProduct = CRM_Utils_Array::value('selectProduct', $premiumParams);
if ($selectProduct && $selectProduct != 'no_thanks') {
require_once 'CRM/Contribute/DAO/Product.php';
$productDAO =& new CRM_Contribute_DAO_Product();
$productDAO->id = $selectProduct;
$productDAO->find(true);
if ($params['amount'] < $productDAO->price) {
$nonDeductibleAmount = $params['amount'];
} else {
$nonDeductibleAmount = $productDAO->price;
}
} else {
$nonDeductibleAmount = '0.00';
}
}
$now = date('YmdHis');
$receiptDate = CRM_Utils_Array::value('receipt_date', $params);
if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
$receiptDate = $now;
}
// check contribution Type
// first create the contribution record
$contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $contributionType->id, 'contribution_page_id' => $online ? $form->_id : null, 'receive_date' => $now, 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || CRM_Utils_Array::value('source', $params) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : null, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : null);
if (!$online && isset($params['thankyou_date'])) {
$contribParams['thankyou_date'] = $params['thankyou_date'];
}
if (!$online || $form->_values['is_monetary']) {
if (!CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['payment_instrument_id'] = 1;
}
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => $result['trxn_result_code'], 'payment_processor' => $result['payment_processor']);
}
if (isset($honorCId)) {
$contribParams["honor_contact_id"] = $honorCId;
$contribParams["honor_type_id"] = $params['honor_type_id'];
}
if ($recurringContributionID) {
$contribParams['contribution_recur_id'] = $recurringContributionID;
}
$contribParams["contribution_status_id"] = $pending ? 2 : 1;
if ($form->_mode == 'test') {
$contribParams["is_test"] = 1;
}
$ids = array();
if (isset($contribParams['invoice_id'])) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
if (isset($contribID)) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
}
foreach (array('pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
if (CRM_Utils_Array::value($val, $params)) {
$contribSoftParams[$val] = $params[$val];
}
}
require_once 'CRM/Contribute/BAO/Contribution.php';
//create an contribution address
if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
// CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
require_once 'CRM/Utils/Money.php';
$contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
$contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
//add contribution record
$contribution =& CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
// process price set, CRM-5095
if ($contribution->id && $form->_priceSetId) {
require_once 'CRM/Contribute/Form/AdditionalInfo.php';
//.........这里部分代码省略.........
示例4: processContribution
/**
* Process the contribution.
*
* @param CRM_Core_Form $form
* @param array $params
* @param array $result
* @param int $contactID
* @param bool $pending
* @param bool $isAdditionalAmount
*
* @return \CRM_Contribute_BAO_Contribution
*/
public static function processContribution(&$form, $params, $result, $contactID, $pending = FALSE, $isAdditionalAmount = FALSE)
{
$transaction = new CRM_Core_Transaction();
$now = date('YmdHis');
$receiptDate = NULL;
if (!empty($form->_values['event']['is_email_confirm'])) {
$receiptDate = $now;
}
//CRM-4196
if ($isAdditionalAmount) {
$params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO::VALUE_SEPARATOR;
}
$contribParams = array('contact_id' => $contactID, 'financial_type_id' => !empty($form->_values['event']['financial_type_id']) ? $form->_values['event']['financial_type_id'] : $params['financial_type_id'], 'receive_date' => $now, 'total_amount' => $params['amount'], 'tax_amount' => $params['tax_amount'], 'amount_level' => $params['amount_level'], 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !empty($params['participant_source']) ? $params['participant_source'] : $params['description'], 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
if (empty($params['is_pay_later'])) {
$contribParams['payment_instrument_id'] = 1;
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate);
}
$allStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
if ($pending) {
$contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
}
$contribParams['is_test'] = 0;
if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
$contribParams['is_test'] = 1;
}
$contribID = NULL;
if (!empty($contribParams['invoice_id'])) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
}
$ids = array();
if ($contribID) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
$eventStartDate = CRM_Utils_Array::value('start_date', CRM_Utils_Array::value('event', $form->_values));
if ($eventStartDate) {
$contribParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
}
}
//create an contribution address
// The concept of contributeMode is deprecated. Elsewhere we use the function processBillingAddress() - although
// currently that is only inherited by back-office forms.
if ($form->_contributeMode != 'notify' && empty($params['is_pay_later'])) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
$contribParams['payment_processor'] = CRM_Utils_Array::value('payment_processor', $params);
$contribParams['skipLineItem'] = 1;
// create contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
// CRM-11124
CRM_Event_BAO_Participant::createDiscountTrxn($form->_eventId, $contribParams, NULL, CRM_Price_BAO_PriceSet::parseFirstPriceSetValueIDFromParams($params));
// process soft credit / pcp pages
if (!empty($params['pcp_made_through_id'])) {
CRM_Contribute_BAO_ContributionSoft::formatSoftCreditParams($params, $form);
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
}
$transaction->commit();
return $contribution;
}
示例5: processContribution
/**
* Process the contribution
*
* @return void
* @access public
*/
static function processContribution(&$form, $params, $result, $contactID, $pending = false, $isAdditionalAmount = false)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$config =& CRM_Core_Config::singleton();
$now = date('YmdHis');
$receiptDate = null;
if ($form->_values['event']['is_email_confirm']) {
$receiptDate = $now;
}
//CRM-4196
if ($isAdditionalAmount) {
$params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR;
}
$contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $form->_values['event']['contribution_type_id'] ? $form->_values['event']['contribution_type_id'] : $params['contribution_type_id'], 'receive_date' => $now, 'total_amount' => $params['amount'], 'amount_level' => $params['amount_level'], 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => $params['description'], 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0));
if (!CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['payment_instrument_id'] = 1;
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate);
}
require_once 'CRM/Contribute/PseudoConstant.php';
$allStatuses = CRM_Contribute_PseudoConstant::contributionStatus();
$contribParams["contribution_status_id"] = array_search('Completed', $allStatuses);
if ($pending) {
$contribParams["contribution_status_id"] = array_search('Pending', $allStatuses);
}
$contribParams["is_test"] = 0;
if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
$contribParams["is_test"] = 1;
}
$contribID = null;
if (CRM_Utils_Array::value('invoice_id', $contribParams)) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
}
$ids = array();
if ($contribID) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
require_once 'CRM/Contribute/BAO/Contribution.php';
//create an contribution address
if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
// create contribution record
$contribution =& CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
// return if pending
if ($pending || $contribution->total_amount == 0) {
$transaction->commit();
return $contribution;
}
// next create the transaction record
$trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $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' => $params['currencyID'], 'payment_processor' => $form->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']);
require_once 'CRM/Contribute/BAO/FinancialTrxn.php';
$trxn =& CRM_Contribute_BAO_FinancialTrxn::create($trxnParams);
$transaction->commit();
return $contribution;
}
示例6: processContribution
/**
* Process the contribution
*
* @return void
* @access public
*/
static function processContribution(&$form, $params, $result, $contactID, $pending = FALSE, $isAdditionalAmount = FALSE)
{
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
$config = CRM_Core_Config::singleton();
$now = date('YmdHis');
$receiptDate = NULL;
if ($form->_values['event']['is_email_confirm']) {
$receiptDate = $now;
}
//CRM-4196
if ($isAdditionalAmount) {
$params['amount_level'] = $params['amount_level'] . ts(' (multiple participants)') . CRM_Core_DAO::VALUE_SEPARATOR;
}
$contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $form->_values['event']['contribution_type_id'] ? $form->_values['event']['contribution_type_id'] : $params['contribution_type_id'], 'receive_date' => $now, 'total_amount' => $params['amount'], 'amount_level' => $params['amount_level'], 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => $params['description'], 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
if (!CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['payment_instrument_id'] = 1;
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate);
}
$allStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$contribParams['contribution_status_id'] = array_search('Completed', $allStatuses);
if ($pending) {
$contribParams['contribution_status_id'] = array_search('Pending', $allStatuses);
}
$contribParams['is_test'] = 0;
if ($form->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
$contribParams['is_test'] = 1;
}
$contribID = NULL;
if (CRM_Utils_Array::value('invoice_id', $contribParams)) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
}
$ids = array();
if ($contribID) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
//create an contribution address
if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
// Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
if (CRM_Utils_Array::value('pcp_made_through_id', $params) || CRM_Utils_Array::value('soft_credit_to', $params)) {
// if its due to pcp
if (CRM_Utils_Array::value('pcp_made_through_id', $params)) {
$contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $params['pcp_made_through_id'], 'contact_id');
} else {
$contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
}
// Pass these details onto with the contribution to make them
// available at hook_post_process, CRM-8908
$contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
}
// create contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
// process soft credit / pcp pages
CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
// return if pending
if ($pending || $contribution->total_amount == 0) {
$transaction->commit();
return $contribution;
}
// next create the transaction record
$trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $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' => $params['currencyID'], 'payment_processor' => $form->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']);
$trxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
$transaction->commit();
return $contribution;
}
示例7: saveBillingAddressIfRequired
/**
* Core specifically won't save billing address if you use notify mode so we make up for that here.
*
* For example a transparent Redirect (POST credit card form off-site) processor has some features of each.
*
* Rather than try to categorise the processor we say 'if a contribution exists and it does not have a billing address but we have billing
* fields in our form we will create a billing address for the payment
*
* @param array $params
*/
private function saveBillingAddressIfRequired($params)
{
if (!empty($params['contributionID']) && $this->hasBillingAddressFields($params)) {
$contribution = civicrm_api3('contribution', 'getsingle', array('id' => $params['contributionID'], 'return' => 'address_id, contribution_status_id'));
if (empty($contribution['address_id'])) {
civicrm_api3('contribution', 'create', array('id' => $params['contributionID'], 'contribution_status_id' => $contribution['contribution_status_id'], 'address_id' => CRM_Contribute_BAO_Contribution::createAddress($params, CRM_Core_BAO_LocationType::getBilling())));
}
}
}
示例8: processContribution
/**
* Process the contribution
*
* @return void
* @access public
*/
static function processContribution(&$form, $params, $result, $contactID, $contributionType, $deductibleMode = TRUE, $pending = FALSE, $online = TRUE)
{
$transaction = new CRM_Core_Transaction();
$className = get_class($form);
$honorCId = $recurringContributionID = NULL;
if ($online && $form->get('honor_block_is_active')) {
$honorCId = $form->createHonorContact();
}
// add these values for the recurringContrib function ,CRM-10188
$params['contribution_type_id'] = $contributionType->id;
$params['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $form->_values);
$recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $contributionType, $online);
if (!$online && isset($params['honor_contact_id'])) {
$honorCId = $params['honor_contact_id'];
}
$config = CRM_Core_Config::singleton();
if (!$online && isset($params['non_deductible_amount'])) {
$nonDeductibleAmount = $params['non_deductible_amount'];
} else {
$nonDeductibleAmount = $params['amount'];
}
if ($online && $contributionType->is_deductible && $deductibleMode) {
$selectProduct = CRM_Utils_Array::value('selectProduct', $params);
if ($selectProduct && $selectProduct != 'no_thanks') {
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $selectProduct;
$productDAO->find(TRUE);
if ($params['amount'] < $productDAO->price) {
$nonDeductibleAmount = $params['amount'];
} else {
$nonDeductibleAmount = $productDAO->price;
}
} else {
$nonDeductibleAmount = '0.00';
}
}
$now = date('YmdHis');
$receiptDate = CRM_Utils_Array::value('receipt_date', $params);
if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
$receiptDate = $now;
}
//get the contrib page id.
$campaignId = $contributionPageId = NULL;
if ($online) {
$contributionPageId = $form->_id;
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
if (!array_key_exists('campaign_id', $params)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
}
} else {
//also for offline we do support - CRM-7290
$contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
}
// first create the contribution record
$contribParams = array('contact_id' => $contactID, 'contribution_type_id' => $contributionType->id, 'contribution_page_id' => $contributionPageId, 'receive_date' => CRM_Utils_Array::value('receive_date', $params) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'), 'non_deductible_amount' => $nonDeductibleAmount, 'total_amount' => $params['amount'], 'amount_level' => CRM_Utils_Array::value('amount_level', $params), 'invoice_id' => $params['invoiceID'], 'currency' => $params['currencyID'], 'source' => !$online || CRM_Utils_Array::value('source', $params) ? CRM_Utils_Array::value('source', $params) : CRM_Utils_Array::value('description', $params), 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0), 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0), 'cancel_date' => isset($params['cancel_date']) ? CRM_Utils_Date::format($params['cancel_date']) : NULL, 'thankyou_date' => isset($params['thankyou_date']) ? CRM_Utils_Date::format($params['thankyou_date']) : NULL, 'campaign_id' => $campaignId);
if (!$online && isset($params['thankyou_date'])) {
$contribParams['thankyou_date'] = $params['thankyou_date'];
}
if (!$online || $form->_values['is_monetary']) {
if (!CRM_Utils_Array::value('is_pay_later', $params)) {
$contribParams['payment_instrument_id'] = 1;
}
}
if (!$pending && $result) {
$contribParams += array('fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']), 'trxn_id' => $result['trxn_id'], 'receipt_date' => $receiptDate, 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $result), 'payment_processor' => CRM_Utils_Array::value('payment_processor', $result));
}
if (isset($honorCId)) {
$contribParams['honor_contact_id'] = $honorCId;
$contribParams['honor_type_id'] = $params['honor_type_id'];
}
if ($recurringContributionID) {
$contribParams['contribution_recur_id'] = $recurringContributionID;
}
$contribParams['contribution_status_id'] = $pending ? 2 : 1;
$contribParams['is_test'] = 0;
if ($form->_mode == 'test') {
$contribParams['is_test'] = 1;
}
$ids = array();
if (isset($contribParams['invoice_id'])) {
$contribID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribParams['invoice_id'], 'id', 'invoice_id');
if (isset($contribID)) {
$ids['contribution'] = $contribID;
$contribParams['id'] = $contribID;
}
}
//create an contribution address
if ($form->_contributeMode != 'notify' && !CRM_Utils_Array::value('is_pay_later', $params) && CRM_Utils_Array::value('is_monetary', $form->_values)) {
$contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
}
// CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
$contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
$contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
//.........这里部分代码省略.........
示例9: processFormContribution
/**
* Process the contribution.
*
* @param CRM_Core_Form $form
* @param array $params
* @param array $result
* @param int $contactID
* @param CRM_Financial_DAO_FinancialType $financialType
* @param bool $pending
* @param bool $online
*
* @param bool $isTest
* @param array $lineItems
*
* @param int $billingLocationID
* ID of billing location type.
*
* @return \CRM_Contribute_DAO_Contribution
* @throws \Exception
*/
public static function processFormContribution(&$form, $params, $result, $contactID, $financialType, $pending, $online, $isTest, $lineItems, $billingLocationID)
{
$transaction = new CRM_Core_Transaction();
$contribSoftContactId = $addressID = NULL;
$contributeMode = $form->_contributeMode;
$isMonetary = !empty($form->_values['is_monetary']);
$isEmailReceipt = !empty($form->_values['is_email_receipt']);
// How do these vary from params? These are currently passed to
// - custom data function....
$formParams = $form->_params;
$isSeparateMembershipPayment = empty($formParams['separate_membership_payment']) ? FALSE : TRUE;
$pledgeID = empty($formParams['pledge_id']) ? NULL : $formParams['pledge_id'];
if (!$isSeparateMembershipPayment && !empty($form->_values['pledge_block_id']) && (!empty($formParams['is_pledge']) || $pledgeID)) {
$isPledge = TRUE;
} else {
$isPledge = FALSE;
}
// add these values for the recurringContrib function ,CRM-10188
$params['financial_type_id'] = $financialType->id;
//create an contribution address
if ($contributeMode != 'notify' && empty($params['is_pay_later']) && $isMonetary) {
$addressID = CRM_Contribute_BAO_Contribution::createAddress($params, $billingLocationID);
}
//@todo - this is being set from the form to resolve CRM-10188 - an
// eNotice caused by it not being set @ the front end
// however, we then get it being over-written with null for backend contributions
// a better fix would be to set the values in the respective forms rather than require
// a function being shared by two forms to deal with their respective values
// moving it to the BAO & not taking the $form as a param would make sense here.
if (!isset($params['is_email_receipt']) && $isEmailReceipt) {
$params['is_email_receipt'] = $isEmailReceipt;
}
$recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $financialType, $online);
$nonDeductibleAmount = self::getNonDeductibleAmount($params, $financialType, $online);
$now = date('YmdHis');
$receiptDate = CRM_Utils_Array::value('receipt_date', $params);
if ($isEmailReceipt) {
$receiptDate = $now;
}
//get the contrib page id.
$contributionPageId = NULL;
if ($online) {
$contributionPageId = $form->_id;
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
if (!array_key_exists('campaign_id', $params)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
}
} else {
//also for offline we do support - CRM-7290
$contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
}
// Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
if (!empty($params['pcp_made_through_id']) || !empty($params['soft_credit_to'])) {
// if its due to pcp
if (!empty($params['pcp_made_through_id'])) {
$contribSoftContactId = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $params['pcp_made_through_id'], 'contact_id');
} else {
$contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
}
// Pass these details onto with the contribution to make them
// available at hook_post_process, CRM-8908
$params['soft_credit_to'] = $contribSoftContactId;
}
if (isset($params['amount'])) {
$contribParams = self::getContributionParams($params, $contactID, $financialType->id, $online, $contributionPageId, $nonDeductibleAmount, $campaignId, $isMonetary, $pending, $result, $receiptDate, $recurringContributionID, $isTest, $addressID, $contribSoftContactId, $lineItems);
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams);
$invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
if ($invoicing) {
$dataArray = array();
foreach ($form->_lineItem as $lineItemKey => $lineItemValue) {
foreach ($lineItemValue as $key => $value) {
if (isset($value['tax_amount']) && isset($value['tax_rate'])) {
if (isset($dataArray[$value['tax_rate']])) {
$dataArray[$value['tax_rate']] = $dataArray[$value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
} else {
$dataArray[$value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
}
}
//.........这里部分代码省略.........