$partialAmtPay = $params['partial_amount_pay'];
$params['total_amount'] = $partialAmtTotal;
if ($partialAmtPay < $partialAmtTotal) {
- $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name');
+ $params['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid');
$params['is_pay_later'] = 0;
$setPrevContribution = FALSE;
}
'payment_instrument_id' => key(CRM_Core_OptionGroup::values('payment_instrument',
FALSE, FALSE, FALSE, 'AND is_default = 1')
),
- 'contribution_status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'),
+ 'contribution_status_id' => CRM_Core_Pseudoconstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'),
);
}
$partialAmtTotal = CRM_Utils_Rule::cleanMoney($params['partial_payment_total']);
$fromFinancialAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($params['financial_type_id'], 'Accounts Receivable Account is');
- $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
+ $statusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$params['total_amount'] = $partialAmtPay;
$balanceTrxnInfo = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($params['contribution']->id, $params['financial_type_id']);
$balanceTrxnParams['status_id'] = $statusId;
$balanceTrxnParams['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
$balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params);
+ $balanceTrxnParams['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $params);
+ $balanceTrxnParams['card_type_id'] = CRM_Utils_Array::value('card_type_id', $params);
if (!empty($balanceTrxnParams['from_financial_account_id']) &&
($statusId == array_search('Completed', $contributionStatuses) || $statusId == array_search('Partially paid', $contributionStatuses))
) {
);
}
elseif (!empty($params['payment_processor'])) {
- $params['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($params['payment_processor'], 'civicrm_payment_processor', 'financial_account_id');
+ $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($params['payment_processor'], NULL, 'civicrm_payment_processor');
$params['payment_instrument_id'] = civicrm_api3('PaymentProcessor', 'getvalue', array(
'id' => $params['payment_processor'],
'return' => 'payment_instrument_id',
'status_id' => $statusId,
'payment_instrument_id' => CRM_Utils_Array::value('payment_instrument_id', $params, $params['contribution']->payment_instrument_id),
'check_number' => CRM_Utils_Array::value('check_number', $params),
+ 'pan_truncation' => CRM_Utils_Array::value('pan_truncation', $params),
+ 'card_type_id' => CRM_Utils_Array::value('card_type_id', $params),
);
if ($contributionStatus == 'Refunded' || $contributionStatus == 'Chargeback' || $contributionStatus == 'Cancelled') {
$trxnParams['trxn_date'] = !empty($params['contribution']->cancel_date) ? $params['contribution']->cancel_date : date('YmdHis');
if (!empty($financialTrxnValues)) {
$trxnParams = array_merge($trxnParams, $financialTrxnValues);
}
+ if (empty($trxnParams['payment_processor_id'])) {
+ unset($trxnParams['payment_processor_id']);
+ }
$params['trxnParams'] = $trxnParams;
// records finanical trxn and entity financial trxn
// also make it available as return value
self::recordAlwaysAccountsReceivable($trxnParams, $params);
+ $trxnParams['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $params);
+ $trxnParams['card_type_id'] = CRM_Utils_Array::value('card_type_id', $params);
$return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
$params['entity_id'] = $financialTxn->id;
if (empty($params['partial_payment_total']) && empty($params['partial_amount_pay'])) {
return;
}
}
+
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$params['entity_id'] = $trxn->id;
if ($context != 'changePaymentInstrument') {
* @return null|object
*/
public static function recordAdditionalPayment($contributionId, $trxnsData, $paymentType = 'owed', $participantId = NULL, $updateStatus = TRUE) {
- $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
+ $statusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$getInfoOf['id'] = $contributionId;
$defaults = array();
$contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults, CRM_Core_DAO::$_nullArray);
$params['partial_payment_total'] = $contributionDAO->total_amount;
$params['partial_amount_pay'] = $trxnsData['total_amount'];
$trxnsData['net_amount'] = !empty($trxnsData['net_amount']) ? $trxnsData['net_amount'] : $trxnsData['total_amount'];
+ $params['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $trxnsData);
+ $params['card_type_id'] = CRM_Utils_Array::value('card_type_id', $trxnsData);
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
elseif ($paymentType == 'refund') {
$trxnsData['total_amount'] = -$trxnsData['total_amount'];
$trxnsData['from_financial_account_id'] = $arAccountId;
- $trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name');
+ $trxnsData['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded');
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
$activityType = ($paymentType == 'refund') ? 'Refund' : 'Payment';
self::addActivityForPayment($entityObj, $financialTrxn, $activityType, $component, $contributionId);
+ return $financialTrxn;
}
- return $financialTrxn;
+
}
/**
* @param CRM_Core_Transaction $transaction
* @param int $recur
* @param CRM_Contribute_BAO_Contribution $contribution
- * @param bool $isRecurring
- * Duplication of param needs review. Only used by AuthorizeNetIPN
- * @param int $isFirstOrLastRecurringPayment
- * Deprecated param only used by AuthorizeNetIPN.
*
* @return array
*/
- public static function completeOrder(&$input, &$ids, $objects, $transaction, $recur, $contribution, $isRecurring, $isFirstOrLastRecurringPayment) {
+ public static function completeOrder(&$input, &$ids, $objects, $transaction, $recur, $contribution) {
$primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
// The previous details are used when calculating line items so keep it before any code that 'does something'
if (!empty($contribution->id)) {
'receive_date',
'receipt_date',
'contribution_status_id',
+ 'card_type_id',
+ 'pan_truncation',
);
if (self::isSingleLineItem($primaryContributionID)) {
$inputContributionWhiteList[] = 'financial_type_id';
}
$dao->free();
- $membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
- $membershipParams['membership_type_id'],
- $primaryContributionID
- );
- $dates = array_fill_keys(array('join_date', 'start_date', 'end_date'), NULL);
- if ($currentMembership) {
- /*
- * Fixed FOR CRM-4433
- * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
- * when Contribution mode is notify and membership is for renewal )
- */
- CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);
-
- // @todo - we should pass membership_type_id instead of null here but not
- // adding as not sure of testing
- $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
- $changeDate, NULL, $membershipParams['num_terms']
- );
-
- $dates['join_date'] = $currentMembership['join_date'];
+ if (CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $input)) === 'Pending') {
+ $membershipParams['num_terms'] = 0;
}
+ else {
+ $membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
+ $membershipParams['membership_type_id'],
+ $primaryContributionID
+ );
+ // @todo remove all this stuff in favour of letting the api call further down handle in
+ // (it is a duplication of what the api does).
+ $dates = array_fill_keys(array('join_date', 'start_date', 'end_date'), NULL);
+ if ($currentMembership) {
+ /*
+ * Fixed FOR CRM-4433
+ * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
+ * when Contribution mode is notify and membership is for renewal )
+ */
+ CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);
+
+ // @todo - we should pass membership_type_id instead of null here but not
+ // adding as not sure of testing
+ $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
+ $changeDate, NULL, $membershipParams['num_terms']
+ );
+
+ $dates['join_date'] = $currentMembership['join_date'];
+ }
- //get the status for membership.
- $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
- $dates['end_date'],
- $dates['join_date'],
- 'today',
- TRUE,
- $membershipParams['membership_type_id'],
- $membershipParams
- );
+ //get the status for membership.
+ $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
+ $dates['end_date'],
+ $dates['join_date'],
+ 'today',
+ TRUE,
+ $membershipParams['membership_type_id'],
+ $membershipParams
+ );
- $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
- //we might be renewing membership,
- //so make status override false.
- $membershipParams['is_override'] = FALSE;
+ unset($dates['end_date']);
+ $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
+ //we might be renewing membership,
+ //so make status override false.
+ $membershipParams['is_override'] = FALSE;
+ }
//CRM-17723 - reset static $relatedContactIds array()
+ // @todo move it to Civi Statics.
$var = TRUE;
CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
civicrm_api3('Membership', 'create', $membershipParams);
}
CRM_Core_Error::debug_log_message("Success: Database updated");
- if ($isRecurring) {
- CRM_Contribute_BAO_ContributionRecur::sendRecurringStartOrEndNotification($ids, $recur,
- $isFirstOrLastRecurringPayment);
- }
return $contributionResult;
}
$balanceTrxnParams['to_financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['financial_type_id'], 'Accounts Receivable Account is');
}
elseif (!empty($params['payment_processor'])) {
- $balanceTrxnParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getFinancialAccount($contribution['payment_processor'], 'civicrm_payment_processor', 'financial_account_id');
+ $balanceTrxnParams['to_financial_account_id'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['payment_processor'], NULL, 'civicrm_payment_processor');
}
elseif (!empty($params['payment_instrument_id'])) {
$balanceTrxnParams['to_financial_account_id'] = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($contribution['payment_instrument_id']);