本文整理汇总了PHP中CRM_Contribute_BAO_ContributionRecur::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contribute_BAO_ContributionRecur::add方法的具体用法?PHP CRM_Contribute_BAO_ContributionRecur::add怎么用?PHP CRM_Contribute_BAO_ContributionRecur::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contribute_BAO_ContributionRecur
的用法示例。
在下文中一共展示了CRM_Contribute_BAO_ContributionRecur::add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processRecurringContribution
/**
* Create the recurring contribution record.
*
* @param CRM_Core_Form $form
* @param array $params
* @param int $contactID
* @param string $contributionType
*
* @return int|null
*/
public static function processRecurringContribution(&$form, &$params, $contactID, $contributionType)
{
if (empty($params['is_recur'])) {
return NULL;
}
$recurParams = array('contact_id' => $contactID);
$recurParams['amount'] = CRM_Utils_Array::value('amount', $params);
$recurParams['auto_renew'] = CRM_Utils_Array::value('auto_renew', $params);
$recurParams['frequency_unit'] = CRM_Utils_Array::value('frequency_unit', $params);
$recurParams['frequency_interval'] = CRM_Utils_Array::value('frequency_interval', $params);
$recurParams['installments'] = CRM_Utils_Array::value('installments', $params);
$recurParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
$recurParams['currency'] = CRM_Utils_Array::value('currency', $params);
// CRM-14354: For an auto-renewing membership with an additional contribution,
// if separate payments is not enabled, make sure only the membership fee recurs
if (!empty($form->_membershipBlock) && $form->_membershipBlock['is_separate_payment'] === '0' && isset($params['selectMembership']) && $form->_values['is_allow_other_amount'] == '1' && !empty($form->_membershipTypeValues) && !empty($form->_membershipTypeValues[$params['selectMembership']]['minimum_fee'])) {
$recurParams['amount'] = $form->_membershipTypeValues[$params['selectMembership']]['minimum_fee'];
}
$recurParams['is_test'] = 0;
if ($form->_action & CRM_Core_Action::PREVIEW || isset($form->_mode) && $form->_mode == 'test') {
$recurParams['is_test'] = 1;
}
$recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
if (!empty($params['receive_date'])) {
$recurParams['start_date'] = $params['receive_date'];
}
$recurParams['invoice_id'] = CRM_Utils_Array::value('invoiceID', $params);
$recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$recurParams['payment_processor_id'] = CRM_Utils_Array::value('payment_processor_id', $params);
$recurParams['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params);
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
$recurParams['financial_type_id'] = $contributionType->id;
if ($form->_values['is_monetary']) {
$recurParams['payment_instrument_id'] = 1;
}
$campaignId = CRM_Utils_Array::value('campaign_id', $params, CRM_Utils_Array::value('campaign_id', $form->_values));
$recurParams['campaign_id'] = $campaignId;
$recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
if (is_a($recurring, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($recurring);
$urlString = 'civicrm/contribute/transact';
$urlParams = '_qf_Main_display=true';
if (get_class($form) == 'CRM_Contribute_Form_Contribution') {
$urlString = 'civicrm/contact/view/contribution';
$urlParams = "action=add&cid={$form->_contactID}";
if ($form->_mode) {
$urlParams .= "&mode={$form->_mode}";
}
}
CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
}
return $recurring->id;
}
示例2: postProcess
/**
* called after the user submits the form.
*
*
* @return void
*/
public function postProcess()
{
// store the submitted values in an array
$params = $this->exportValues();
if ($this->_selfService && $this->_donorEmail) {
// for self service force notify
$params['is_notify'] = 1;
}
// if this is an update of an existing recurring contribution, pass the ID
$params['id'] = $this->_subscriptionDetails->recur_id;
$message = '';
$params['subscriptionId'] = $this->_subscriptionDetails->subscription_id;
$updateSubscription = TRUE;
if ($this->_paymentProcessorObj->isSupported('changeSubscriptionAmount')) {
$updateSubscription = $this->_paymentProcessorObj->changeSubscriptionAmount($message, $params);
}
if (is_a($updateSubscription, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($updateSubscription);
$status = ts('Could not update the Recurring contribution details');
$msgTitle = ts('Update Error');
$msgType = 'error';
} elseif ($updateSubscription) {
// save the changes
$result = CRM_Contribute_BAO_ContributionRecur::add($params);
$status = ts('Recurring contribution has been updated to: %1, every %2 %3(s) for %4 installments.', array(1 => CRM_Utils_Money::format($params['amount'], $this->_subscriptionDetails->currency), 2 => $this->_subscriptionDetails->frequency_interval, 3 => $this->_subscriptionDetails->frequency_unit, 4 => $params['installments']));
$msgTitle = ts('Update Success');
$msgType = 'success';
$contactID = $this->_subscriptionDetails->contact_id;
if ($this->_subscriptionDetails->amount != $params['amount']) {
$message .= "<br /> " . ts("Recurring contribution amount has been updated from %1 to %2 for this subscription.", array(1 => CRM_Utils_Money::format($this->_subscriptionDetails->amount, $this->_subscriptionDetails->currency), 2 => CRM_Utils_Money::format($params['amount'], $this->_subscriptionDetails->currency))) . ' ';
}
if ($this->_subscriptionDetails->installments != $params['installments']) {
$message .= "<br /> " . ts("Recurring contribution installments have been updated from %1 to %2 for this subscription.", array(1 => $this->_subscriptionDetails->installments, 2 => $params['installments'])) . ' ';
}
$activityParams = array('source_contact_id' => $contactID, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', 'Update Recurring Contribution', 'name'), 'subject' => ts('Recurring Contribution Updated'), 'details' => $message, 'activity_date_time' => date('YmdHis'), 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'));
$session = CRM_Core_Session::singleton();
$cid = $session->get('userID');
if ($cid) {
$activityParams['target_contact_id'][] = $activityParams['source_contact_id'];
$activityParams['source_contact_id'] = $cid;
}
CRM_Activity_BAO_Activity::create($activityParams);
if (!empty($params['is_notify'])) {
// send notification
if ($this->_subscriptionDetails->contribution_page_id) {
CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $this->_subscriptionDetails->contribution_page_id, $value, array('title', 'receipt_from_name', 'receipt_from_email'));
$receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$this->_subscriptionDetails->contribution_page_id]) . '" <' . $value[$this->_subscriptionDetails->contribution_page_id]['receipt_from_email'] . '>';
} else {
$domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
$receiptFrom = "{$domainValues['0']} <{$domainValues['1']}>";
}
list($donorDisplayName, $donorEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
$tplParams = array('recur_frequency_interval' => $this->_subscriptionDetails->frequency_interval, 'recur_frequency_unit' => $this->_subscriptionDetails->frequency_unit, 'amount' => CRM_Utils_Money::format($params['amount']), 'installments' => $params['installments']);
$tplParams['contact'] = array('display_name' => $donorDisplayName);
$tplParams['receipt_from_email'] = $receiptFrom;
$sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_recurring_edit', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $this->_subscriptionDetails->is_test, 'PDFFilename' => 'receipt.pdf', 'from' => $receiptFrom, 'toName' => $donorDisplayName, 'toEmail' => $donorEmail);
list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
}
}
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
if ($userID && $status) {
CRM_Core_Session::setStatus($status, $msgTitle, $msgType);
} elseif (!$userID) {
if ($status) {
CRM_Utils_System::setUFMessage($status);
}
// keep result as 1, since we not displaying anything on the redirected page anyway
return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/subscriptionstatus', "reset=1&task=update&result=1"));
}
}
示例3: processRecurringContribution
/**
* Create the recurring contribution record
*
*/
static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE)
{
// return if this page is not set for recurring
// or the user has not chosen the recurring option
//this is online case validation.
if (empty($form->_values['is_recur']) && $online || empty($params['is_recur'])) {
return NULL;
}
$recurParams = array();
$config = CRM_Core_Config::singleton();
$recurParams['contact_id'] = $contactID;
$recurParams['amount'] = CRM_Utils_Array::value('amount', $params);
$recurParams['auto_renew'] = CRM_Utils_Array::value('auto_renew', $params);
$recurParams['frequency_unit'] = CRM_Utils_Array::value('frequency_unit', $params);
$recurParams['frequency_interval'] = CRM_Utils_Array::value('frequency_interval', $params);
$recurParams['installments'] = CRM_Utils_Array::value('installments', $params);
$recurParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
$recurParams['is_test'] = 0;
if ($form->_action & CRM_Core_Action::PREVIEW || isset($form->_mode) && $form->_mode == 'test') {
$recurParams['is_test'] = 1;
}
$recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
if (!empty($params['receive_date'])) {
$recurParams['start_date'] = $params['receive_date'];
}
$recurParams['invoice_id'] = CRM_Utils_Array::value('invoiceID', $params);
$recurParams['contribution_status_id'] = 2;
$recurParams['payment_processor_id'] = CRM_Utils_Array::value('payment_processor_id', $params);
$recurParams['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params);
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
$recurParams['financial_type_id'] = $contributionType->id;
if (!$online || $form->_values['is_monetary']) {
$recurParams['payment_instrument_id'] = 1;
}
$campaignId = CRM_Utils_Array::value('campaign_id', $params);
if ($online) {
if (!array_key_exists('campaign_id', $params)) {
$campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
}
}
$recurParams['campaign_id'] = $campaignId;
$recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
if (is_a($recurring, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
$urlString = 'civicrm/contribute/transact';
$urlParams = '_qf_Main_display=true';
if ($className == 'CRM_Contribute_Form_Contribution') {
$urlString = 'civicrm/contact/view/contribution';
$urlParams = "action=add&cid={$form->_contactID}";
if ($form->_mode) {
$urlParams .= "&mode={$form->_mode}";
}
}
CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
}
return $recurring->id;
}
示例4: processRecurringContribution
/**
* Create the recurring contribution record
*
*/
function processRecurringContribution(&$params, $contactID)
{
// return if this page is not set for recurring
// or the user has not chosen the recurring option
if (!CRM_Utils_Array::value('is_recur', $this->_values) || !CRM_Utils_Array::value('is_recur', $params)) {
return null;
}
$recurParams = array();
$config =& CRM_Core_Config::singleton();
$recurParams['contact_id'] = $contactID;
$recurParams['amount'] = $params['amount'];
$recurParams['frequency_unit'] = $params['frequency_unit'];
$recurParams['frequency_interval'] = $params['frequency_interval'];
$recurParams['installments'] = $params['installments'];
if ($this->_action & CRM_Core_Action::PREVIEW) {
$recurParams["is_test"] = 1;
}
$now = date('YmdHis');
$recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = $now;
$recurParams['invoice_id'] = $params['invoiceID'];
$recurParams['contribution_status_id'] = 2;
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
$ids = array();
require_once 'CRM/Contribute/BAO/ContributionRecur.php';
$recurring =& CRM_Contribute_BAO_ContributionRecur::add($recurParams, $ids);
if (is_a($recurring, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', '_qf_Main_display=true'));
}
return $recurring->id;
}
示例5: testCreateSinglePostDated
/**
* Create a single post dated payment as a recurring transaction.
*/
public function testCreateSinglePostDated()
{
$start_date = date('Ymd', strtotime("+ 1 week"));
$firstName = 'John_' . substr(sha1(rand()), 0, 7);
$lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
$nameParams = array('first_name' => $firstName, 'last_name' => $lastName);
$contactId = $this->individualCreate($nameParams);
$ids = array('contribution' => NULL);
$invoiceID = sha1(rand());
$amount = rand(100, 1000) . '.00';
$contributionRecurParams = array('contact_id' => $contactId, 'amount' => $amount, 'currency' => 'USD', 'frequency_unit' => 'month', 'frequency_interval' => 1, 'installments' => 3, 'start_date' => $start_date, 'create_date' => date('Ymd'), 'invoice_id' => $invoiceID, 'contribution_status_id' => 2, 'is_test' => 1, 'payment_processor_id' => $this->_paymentProcessorID);
$recur = CRM_Contribute_BAO_ContributionRecur::add($contributionRecurParams, $ids);
$contributionParams = array('contact_id' => $contactId, 'financial_type_id' => $this->_financialTypeId, 'receive_date' => $start_date, 'total_amount' => $amount, 'invoice_id' => $invoiceID, 'currency' => 'USD', 'contribution_recur_id' => $recur->id, 'is_test' => 1, 'contribution_status_id' => 2);
$contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
$params = array('qfKey' => '00ed21c7ca00a1f7d555555596ef7_4454', 'hidden_CreditCard' => 1, 'billing_first_name' => $firstName, 'billing_middle_name' => "", 'billing_last_name' => $lastName, 'billing_street_address-5' => '8 Hobbitton Road', 'billing_city-5' => 'The Shire', 'billing_state_province_id-5' => 1012, 'billing_postal_code-5' => 5010, 'billing_country_id-5' => 1228, 'credit_card_number' => '4007000000027', 'cvv2' => 123, 'credit_card_exp_date' => array('M' => 11, 'Y' => 2019), 'credit_card_type' => 'Visa', 'is_recur' => 1, 'frequency_interval' => 1, 'frequency_unit' => 'month', 'installments' => 3, 'financial_type_id' => $this->_financialTypeId, 'is_email_receipt' => 1, 'from_email_address' => "{$firstName}.{$lastName}@example.com", 'receive_date' => $start_date, 'receipt_date_time' => '', 'payment_processor_id' => $this->_paymentProcessorID, 'price_set_id' => '', 'total_amount' => $amount, 'currency' => 'USD', 'source' => "Mordor", 'soft_credit_to' => '', 'soft_contact_id' => '', 'billing_state_province-5' => 'IL', 'state_province-5' => 'IL', 'billing_country-5' => 'US', 'country-5' => 'US', 'year' => 2019, 'month' => 10, 'ip_address' => '127.0.0.1', 'amount' => 70, 'amount_level' => 0, 'currencyID' => 'USD', 'pcp_display_in_roll' => "", 'pcp_roll_nickname' => "", 'pcp_personal_note' => "", 'non_deductible_amount' => "", 'fee_amount' => "", 'net_amount' => "", 'invoice_id' => "", 'contribution_page_id' => "", 'thankyou_date' => NULL, 'honor_contact_id' => NULL, 'invoiceID' => $invoiceID, 'first_name' => $firstName, 'middle_name' => 'bob', 'last_name' => $lastName, 'street_address' => '8 Hobbiton Road', 'city' => 'The Shire', 'state_province' => 'IL', 'postal_code' => 5010, 'country' => 'US', 'contributionType_name' => 'My precious', 'contributionType_accounting_code' => '', 'contributionPageID' => '', 'email' => "{$firstName}.{$lastName}@example.com", 'contactID' => $contactId, 'contributionID' => $contribution['id'], 'contributionTypeID' => $this->_financialTypeId, 'contributionRecurID' => $recur->id);
// if cancel-subscription has been called earlier 'subscriptionType' would be set to cancel.
// to make a successful call for another trxn, we need to set it to something else.
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('subscriptionType', 'create');
// turn verifySSL off
CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
$result = $this->processor->doPayment($params);
// turn verifySSL on
CRM_Core_BAO_Setting::setItem('0', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL');
// if subscription was successful, processor_id / subscription-id must not be null
$this->assertDBNotNull('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id', 'id', 'Failed to create subscription with Authorize.');
// cancel it or the transaction will be rejected by A.net if the test is re-run
$subscriptionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionRecur', $recur->id, 'processor_id');
$message = '';
$result = $this->processor->cancelSubscription($message, array('subscriptionId' => $subscriptionID));
$this->assertTrue($result, 'Failed to cancel subscription with Authorize.');
}
示例6: processAPIContribution
static function processAPIContribution($params)
{
if (empty($params) || array_key_exists('error', $params)) {
return false;
}
// add contact using dedupe rule
require_once 'CRM/Dedupe/Finder.php';
$dedupeParams = CRM_Dedupe_Finder::formatParams($params, 'Individual');
$dupeIds = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
// if we find more than one contact, use the first one
if (CRM_Utils_Array::value(0, $dupeIds)) {
$params['contact_id'] = $dupeIds[0];
}
require_once 'CRM/Contact/BAO/Contact.php';
$contact = CRM_Contact_BAO_Contact::create($params);
if (!$contact->id) {
return false;
}
// only pass transaction params to contribution::create, if available
if (array_key_exists('transaction', $params)) {
$params = $params['transaction'];
$params['contact_id'] = $contact->id;
}
// handle contribution custom data
$customFields = CRM_Core_BAO_CustomField::getFields('Contribution', false, false, CRM_Utils_Array::value('contribution_type_id', $params));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, CRM_Utils_Array::value('id', $params, null), 'Contribution');
// create contribution
// if this is a recurring contribution then process it first
if ($params['trxn_type'] == 'subscrpayment') {
require_once 'CRM/Contribute/BAO/ContributionRecur.php';
$recurring =& CRM_Contribute_BAO_ContributionRecur::add($params, CRM_Core_DAO::$_nullArray);
if (is_a($recurring, 'CRM_Core_Error')) {
return false;
} else {
$params['contribution_recur_id'] = $recurring->id;
}
}
require_once 'CRM/Contribute/BAO/Contribution.php';
$contribution =& CRM_Contribute_BAO_Contribution::create($params, CRM_Core_DAO::$_nullArray);
if (!$contribution->id) {
return false;
}
return true;
}
示例7: createSimpleContribution
public function createSimpleContribution($contactID, $params, $isTest, $creditInfo)
{
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
$bltID = array_search('Billing', $locationTypes);
$settings = civicrm_api3('Setting', 'get', array('domain_id' => $domainID, 'return' => "simple_donation_page"));
$donatePageID = $settings['values'][$domainID]['simple_donation_page'];
$donateConfig = $donatePage = civicrm_api3('ContributionPage', 'getsingle', array('id' => $donatePageID));
$contributionparams = array();
$isrecur = $params['recur'];
$contributionparams = array("billing_first_name" => $params['first_name'], "first_name" => $params['first_name'], "billing_middle_name" => $params['middle_name'], "middle_name" => $params['middle_name'], "billing_last_name" => $params['last_name'], "last_name" => $params['last_name'], "billing_street_address-{$bltID}" => $params['address'], "street_address" => $params['address'], "billing_city-{$bltID}" => $params['city'], "city" => $params['city'], "billing_country_id-{$bltID}" => $params['country'], "country_id" => $params['country'], "billing_state_province_id-{$bltID}" => $params['state'], "state_province_id" => $params['state'], "state_province" => CRM_Core_PseudoConstant::stateProvince($params['state']), "billing_postal_code-{$bltID}" => $params['zip'], "postal_code" => $params['zip'], "year" => "20" . substr($params['cardExpiry'], 2, 3), "month" => substr($params['cardExpiry'], 0, 2), "email" => $params['email'], "contribution_page_id" => $donatePageID, "payment_processor_id" => CRM_Utils_Array::value('payment_processor', $params), "is_test" => $isTest, "is_pay_later" => $params['is_pay_later'], "total_amount" => $params['amount'], "financial_type_id" => $donateConfig['financial_type_id'], "currencyID" => $donateConfig['currency'], "currency" => $donateConfig['currency'], "skipLineItem" => 0, "skipRecentView" => 1, 'is_email_receipt' => 1, "contact_id" => $contactID, "source" => "Online Contribution: {$donateConfig['title']}");
if ($params['is_pay_later']) {
$contributionparams["contribution_status_id"] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$contributionparams["payment_processor_id"] = 1;
}
if (!empty($params['creditType'])) {
$contributionparams['credit_card_number'] = $creditInfo['credit_card_number'];
$contributionparams['cvv2'] = $creditInfo['cvv2'];
$contributionparams['credit_card_type'] = $creditInfo['credit_card_type'];
}
if (!empty($params['debitType'])) {
$contributionparams['bank_identification_number'] = $creditInfo['bank_identification_number'];
$contributionparams['bank_name'] = $creditInfo['bank_name'];
$contributionparams['bank_account_number'] = $creditInfo['bank_account_number'];
$contributionparams['payment_type'] = $creditInfo['payment_type'];
$contributionparams['account_holder'] = $creditInfo['account_holder'];
}
//unset the billing parameters if it is pay later mode
//to avoid creation of billing location
if ($params['is_pay_later']) {
$billingFields = array('billing_first_name', 'billing_middle_name', 'billing_last_name', "billing_street_address-{$bltID}", "billing_city-{$bltID}", "billing_state_province-{$bltID}", "billing_state_province_id-{$bltID}", "billing_postal_code-{$bltID}", "billing_country-{$bltID}", "billing_country_id-{$bltID}");
foreach ($billingFields as $value) {
unset($contributionparams[$value]);
}
}
//check for recurring contribution
if ($isrecur) {
$recurParams = array('contact_id' => $contactID);
$recurParams['amount'] = $params['amount'];
$recurParams['auto_renew'] = 1;
$recurParams['frequency_unit'] = 'month';
$recurParams['frequency_interval'] = 1;
$recurParams['financial_type_id'] = $donateConfig['financial_type_id'];
$recurParams['is_test'] = $isTest;
$recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
$recurParams['invoice_id'] = $recurParams['trxn_id'] = md5(uniqid(rand(), TRUE));
$recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$recurParams['payment_processor_id'] = CRM_Utils_Array::value('payment_processor_id', $contributionparams);
$recurParams['is_email_receipt'] = 1;
//create recurring contribution record
$recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
$recurContriID = $recurring->id;
$contributionparams['contributionRecurID'] = $recurContriID;
//$contribution->id;
$contributionparams['contribution_recur_id'] = $recurContriID;
//$contribution->id;
}
//call transact api
try {
$result = civicrm_api3('Contribution', 'transact', $contributionparams);
} catch (CiviCRM_API3_Exception $e) {
$error = $e->getMessage();
$errorList['error'] = $error;
return $errorList;
}
if ($result['error']) {
//make sure to cleanup db for recurring case.
if ($recurContriID) {
CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($recurContriID);
}
return $result['error'];
} else {
if ($result) {
$contributionID = $result['id'];
// Send receipt
// send recurring Notification email for user
if ($recurContriID) {
CRM_Contribute_BAO_ContributionPage::recurringNotify(CRM_Core_Payment::RECURRING_PAYMENT_START, $contactID, $donatePageID, $recurring);
}
civicrm_api3('contribution', 'sendconfirmation', array('id' => $contributionID) + $donateConfig);
return $result;
}
}
}
示例8: processRecurringContribution
/**
* Create the recurring contribution record
*
*/
function processRecurringContribution(&$form, &$params, $contactID, $online = true)
{
// return if this page is not set for recurring
// or the user has not chosen the recurring option
//this is online case validation.
if (!CRM_Utils_Array::value('is_recur', $form->_values) && $online || !CRM_Utils_Array::value('is_recur', $params)) {
return null;
}
$recurParams = array();
$config = CRM_Core_Config::singleton();
$recurParams['contact_id'] = $contactID;
$recurParams['amount'] = $params['amount'];
$recurParams['frequency_unit'] = $params['frequency_unit'];
$recurParams['frequency_interval'] = $params['frequency_interval'];
$recurParams['installments'] = $params['installments'];
$recurParams['is_test'] = 0;
if ($form->_action & CRM_Core_Action::PREVIEW || isset($form->_mode) && $form->_mode == 'test') {
$recurParams['is_test'] = 1;
}
$now = date('YmdHis');
$recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = $now;
$recurParams['invoice_id'] = $params['invoiceID'];
$recurParams['contribution_status_id'] = 2;
$recurParams['payment_processor_id'] = $params['payment_processor_id'];
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
$ids = array();
require_once 'CRM/Contribute/BAO/ContributionRecur.php';
$recurring =& CRM_Contribute_BAO_ContributionRecur::add($recurParams, $ids);
if (is_a($recurring, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($result);
$urlString = 'civicrm/contribute/transact';
$urlParams = '_qf_Main_display=true';
if ($className == 'CRM_Contributet_Form_Contribution') {
$urlString = 'civicrm/contact/view/contribution';
$urlParams = "action=add&cid={$form->_contactID}";
if ($form->_mode) {
$urlParams .= "&mode={$form->_mode}";
}
}
CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
}
return $recurring->id;
}