/**
  * takes an associative array and creates a contribution page object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Contribute_DAO_ContributionPage object
  * @access public
  * @static
  */
 public static function &create(&$params)
 {
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->copyValues($params);
     $dao->save();
     return $dao;
 }
 /**
  * Helper function to delete a Contribution Page.
  *
  * @param int $contributionPageId
  *   Id of the Contribution Page.
  *   to be deleted
  * @return bool
  *   true if Contribution Page deleted, false otherwise
  */
 public static function delete($contributionPageId)
 {
     require_once "CRM/Contribute/DAO/ContributionPage.php";
     $cp = new CRM_Contribute_DAO_ContributionPage();
     $cp->id = $contributionPageId;
     if ($cp->find(TRUE)) {
         $result = $cp->delete();
     }
     return $result;
 }
 /**
  * takes an associative array and creates a contribution page object
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  *
  * @return object CRM_Contribute_DAO_ContributionPage object
  * @access public
  * @static
  */
 public static function &create(&$params)
 {
     $financialTypeId = NULL;
     if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
         $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->copyValues($params);
     $dao->save();
     if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
         CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
     }
     return $dao;
 }
 /**
  * Takes an associative array and creates a contribution page object.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Contribute_DAO_ContributionPage
  */
 public static function &create(&$params)
 {
     $financialTypeId = NULL;
     if (!empty($params['id']) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
         $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'ContributionPage', CRM_Utils_Array::value('id', $params), $params);
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->copyValues($params);
     $dao->save();
     if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
         CRM_Price_BAO_PriceFieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']);
     }
     CRM_Utils_Hook::post($hook, 'ContributionPage', $dao->id, $dao);
     return $dao;
 }
Esempio n. 5
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     // first delete the join entries associated with this contribution page
     require_once 'CRM/Core/DAO/UFJoin.php';
     $dao = new CRM_Core_DAO_UFJoin();
     $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     $dao->copyValues($params);
     $dao->delete();
     require_once 'CRM/Core/OptionGroup.php';
     $groupName = "civicrm_contribution_page.amount.{$this->_id}";
     CRM_Core_OptionGroup::deleteAssoc($groupName);
     //next delete the membership block fields
     require_once 'CRM/Member/DAO/MembershipBlock.php';
     $dao = new CRM_Member_DAO_MembershipBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     //next delete the pcp block fields
     require_once 'CRM/Contribute/DAO/PCPBlock.php';
     $dao = new CRM_Contribute_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     // need to delete premiums. CRM-4586
     require_once 'CRM/Contribute/BAO/Premium.php';
     CRM_Contribute_BAO_Premium::deletePremium($this->_id);
     // price set cleanup, CRM-5527
     require_once 'CRM/Price/BAO/Set.php';
     CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $this->_id);
     // finally delete the contribution page
     require_once 'CRM/Contribute/DAO/ContributionPage.php';
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->id = $this->_id;
     $dao->delete();
     $transaction->commit();
     CRM_Core_Session::setStatus(ts('The contribution page \'%1\' has been deleted.', array(1 => $this->_title)));
 }
Esempio n. 6
0
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 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['contribution_page'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
Esempio n. 7
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $transaction = new CRM_Core_Transaction();
     // first delete the join entries associated with this contribution page
     $dao = new CRM_Core_DAO_UFJoin();
     $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
     $dao->copyValues($params);
     $dao->delete();
     //next delete the membership block fields
     $dao = new CRM_Member_DAO_MembershipBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     //next delete the pcp block fields
     $dao = new CRM_PCP_DAO_PCPBlock();
     $dao->entity_table = 'civicrm_contribution_page';
     $dao->entity_id = $this->_id;
     $dao->delete();
     // need to delete premiums. CRM-4586
     CRM_Contribute_BAO_Premium::deletePremium($this->_id);
     // price set cleanup, CRM-5527
     CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
     // finally delete the contribution page
     $dao = new CRM_Contribute_DAO_ContributionPage();
     $dao->id = $this->_id;
     $dao->delete();
     $transaction->commit();
     CRM_Core_Session::setStatus(ts("The contribution page '%1' has been deleted.", array(1 => $this->_title)), ts('Deleted'), 'success');
 }
 function _process_csv($csv_array, $csv_name, $mail_date)
 {
     $this->_addToSummary("Processing {$csv_name}");
     foreach ($csv_array as $row) {
         $this->_addToSummary(null);
         // insert blank line.
         // check if this is a blank line
         if (count($row) <= 1) {
             continue;
         }
         $subscriptionId = $row[0];
         $subscriptionStatus = $row[1];
         $paymentNum = $row[2];
         $totalRecurrences = $row[3];
         $transactionId = $row[4];
         $amount = $row[5];
         $currency = $row[6];
         $custFirstName = $row[8];
         $custLastName = $row[9];
         $contributionStatus = $row[10];
         $recur = new CRM_Contribute_DAO_ContributionRecur();
         $first_contribution = new CRM_Contribute_DAO_Contribution();
         // If this is the first payment, load recurring contribution and update
         if ($paymentNum == 1) {
             // Load contribution using SubscriptionID as trxn_id
             $first_contribution->trxn_id = $subscriptionId;
             if (!$first_contribution->find(true)) {
                 $this->_addToSummary("THE RECURRING TRANSACTION FOR SUBSCRIPTION {$subscriptionId} COULD NOT BE FOUND. A TRANSACTION HAS OCCURED THAT WAS NOT EXPECTED.  PLEASE REVIEW {$csv_name}.");
                 continue;
             }
             // Load recurring contribution from contribution
             $recur->id = $first_contribution->contribution_recur_id;
             if (!$recur->find(true)) {
                 $this->_addToSummary("INITIAL RECURRING CONTRIBUTION NOT FOUND FOR {$subscriptionId}. PLEASE REVIEW {$csv_name}");
                 continue;
             }
             $recur->start_date = $mail_date;
             $recur->processor_id = $subscriptionId;
             $recur->trxn_id = $subscriptionId;
             $recur->contribution_status_id = _CRM_PROCESS_AUTHORIZE_REPORT_STATUS_CURRENT;
             // update transaction id for contribution
             $first_contribution->trxn_id = $transactionId;
             $first_contribution->receive_date = $mail_date;
             $first_contribution->contribution_status_id = $this->_get_contribution_status($contributionStatus);
             // load contribution page
             $contribution_page = new CRM_Contribute_DAO_ContributionPage();
             $contribution_page->id = $first_contribution->contribution_page_id;
             if (!$contribution_page->find(true)) {
                 $this->_addToSummary("COULD NOT FIND CONTRIBUTION PAGE FOR {$subscriptionId}. PLEASE REVIEW {$csv_name}");
                 continue;
             }
             // is there an email receipt
             if ($contribution_page->is_email_receipt) {
                 $first_contribution->receipt_date = date('YmdHis');
             }
         } else {
             $recur->processor_id = $subscriptionId;
             if (!$recur->find(true)) {
                 $this->_addToSummary("THE RECURRING TRANSACTION FOR SUBSCRIPTION {$subscriptionId} COULD NOT BE FOUND. A TRANSACTION HAS OCCURED THAT WAS NOT EXPECTED.  PLEASE REVIEW {$csv_name}.");
                 continue;
             }
             $recur->modified_date = $mail_date;
             // load first contribution
             $first_contribution->contribution_recur_id = $recur->id;
             $first_contribution->orderBy('receive_date');
             $first_contribution->limit(1);
             if (!$first_contribution->find(true)) {
                 $this->_addToSummary("CONTRIBUTION RECORD FOR SUBSCRIPTION {$subscriptonId} COULD NOT BE FOUND.  PLEASE REVIEW {$csv_name}");
                 continue;
             }
             // load contribution page
             $contribution_page = new CRM_Contribute_DAO_ContributionPage();
             $contribution_page->id = $first_contribution->contribution_page_id;
             if (!$contribution_page->find(true)) {
                 $this->_addToSummary("COULD NOT FIND CONTRIBUTION PAGE FOR {$subscriptionId}. PLEASE REVIEW {$csv_name}");
                 continue;
             }
         }
         // is this valid for failed transactions also?
         if ($amount != $recur->amount) {
             $this->_addToSummary("AN UNEXPECTED AMOUNT WAS RECEIVED FOR SUBSCRIPTION {$subscriptionId}. SKIPPING THIS TRANSACTION. PLEASE REVIEW {$csv_name}");
             continue;
         }
         // Verify contact exists
         if (!$recur->contact_id) {
             // assuming if contact_id is set, contact exists
             $this->_addToSummary("NO USER IS ASSOCIATED WITH THE CONTRIBUTION FOR SUBSCRIPTION {$subscrptionId}, EXPECTED '{$custFirstName} {$custLastName}'. PLEASE REVIEW {$csv_name}");
             continue;
         }
         // Verify number of recurrences
         if ($recur->installments != $totalRecurrences) {
             $this->_addToSummary("SUBSCRIPTION {$subscriptionId} EXPECTS {$recur->installments}, OFFERED {$totalRecurrences}. PLEASE REVIEW {$csv_name}");
             continue;
         }
         // Check if this contribution is complete
         if (!empty($recur->end_date) && $recur->end_date != '0000-00-00 00:00:00') {
             $this->_addToSummary("SUBSCRIPTION {$subscriptionId} IS MARKED AS COMPLETE. PLEASE REVIEW {$csv_name}");
             continue;
         }
         if (!empty($recur->cancel_date) && $recur->cancel_date != '0000-00-00 00:00:00') {
             $this->_addToSummary("SUBSCRIPTION {$subscriptionId} IS MARKED AS CANCELLED. PLEASE REVIEW {$csv_name}");
             continue;
         }
         if ($paymentNum == $totalRecurrences) {
             $recur->end_date = $mail_date;
             $recur->contribution_status_id = _CRM_PROCESS_AUTHORIZE_REPORT_STATUS_COMPLETE;
         }
         if ($contributionStatus != CRM_Core_Payment_AuthorizeNet::AUTH_APPROVED) {
             $recur->failure_count++;
         }
         CRM_Core_DAO::transaction('BEGIN');
         if (!$recur->save()) {
             $this->_addToSummary("THE RECURRING CONTRIBUTION COULD NOT BE UPDATED. PLEASE REVIEW {$csv_name} FOR subscription_id={$subscription_id}");
             CRM_Core_DAO::transaction('ROLLBACK');
             continue;
         }
         $this->_addToSummary("The recurring transaction has been updated.");
         if ($paymentNum == 1) {
             // update first contribution
             if (!$first_contribution->save()) {
                 $this->_addToSummary("THE CONTRIBUTION COULD NOT BE UPDATED. PLEASE REVIEW {$csv_name} FOR subscription_id={$subscription_id}");
                 CRM_Core_DAO::transaction('ROLLBACK');
                 continue;
             }
             // copy $first_contribution to $contribution for use later
             $contribution = $first_contribution;
         } else {
             // create a contribution and then get it processed
             $contribution = new CRM_Contribute_DAO_Contribution();
             // make sure that the transaction doesn't already exist
             $contribution->trxn_id = $transactionId;
             if ($contribution->find()) {
                 $this->_addToSummary("THE TRANSACTION {$transaction_id} ALREADY EXISTS IN CIVICRM. PLEASE REVIEW {$csv_name} FOR subscription_id={$subscription_id}");
                 CRM_Core_DAO::transaction('ROLLBACK');
                 continue;
             }
             $contribution->contribution_recur_id = $recur->id;
             $contribution->receive_date = $mail_date;
             $contribution->total_amount = $amount;
             $contribution->net_amount = $amount;
             $contribution->trxn_id = $transactionId;
             $contribution->currency = $currency;
             $contribution->contribution_status_id = $this->_get_contribution_status($contributionStatus);
             $contribution->contact_id = $first_contribution->contact_id;
             $contribution->contribution_type_id = $first_contribution->contribution_type_id;
             $contribution->contribution_page_id = $first_contribution->contribution_page_id;
             $contribution->payment_instrument_id = $first_contribution->payment_instrument_id;
             $contribution->is_test = $first_contribution->is_test;
             $contribution->invoice_id = md5(uniqid(rand(), true));
             if ($contribution_page->is_email_receipt) {
                 $contribution->receipt_date = date('YmdHis');
             }
             if (!$contribution->save()) {
                 $this->_addToSummary("THE CONTRIBUTION COULD NOT BE SAVED. PLEASE REVIEW {$csv_name} FOR subscription_id={$subscription_id}");
                 CRM_Core_DAO::transaction('ROLLBACK');
                 continue;
             }
         }
         $this->_addToSummary('Contribution saved');
         // create the transaction record
         $trxnParams = array('entity_table' => 'civicrm_contribution', 'entity_id' => $contribution->id, 'trxn_date' => $mail_date, 'trxn_type' => 'Debit', 'total_amount' => $amount, 'fee_amount' => $contribution->fee_amount, 'net_amount' => $contribution->net_amount, 'currency' => $contribution->currency, 'payment_processor' => 'AuthNet_AIM', 'trxn_id' => $contribution->trxn_id);
         require_once 'CRM/Contribute/BAO/FinancialTrxn.php';
         $trxn =& CRM_Contribute_BAO_FinancialTrxn::create($trxnParams);
         if (is_a($trxn, 'CRM_Core_Error')) {
             $this->_addToSummary("A TRANSACTION RECORD COULD NOT BE CREATED. PLEASE REVIEW {$csv_name} FOR subscription_id={$subscription_id}");
             CRM_Core_DAO::transaction('ROLLBACK');
             continue;
         } else {
             $this->_addToSummary("Transaction record created.");
         }
         // get the title of the contribution page
         $title = $contribution_page->title;
         // format the money
         require_once 'CRM/Utils/Money.php';
         $formattedAmount = CRM_Utils_Money::format($amount, $contribution->currency);
         CRM_Core_DAO::transaction('COMMIT');
         // get the contribution type
         require_once 'CRM/Contribute/BAO/ContributionType.php';
         $contribution_type_name = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $contribution->contribution_type_id, 'name');
         // create an activity history record
         $ahParams = array('entity_table' => 'civicrm_contact', 'entity_id' => $recur->contact_id, 'activity_type' => $contribution_type_name, 'module' => 'CiviContribute', 'callback' => 'CRM_Contribute_Page_Contribution::details', 'activity_id' => $contribution->id, 'activity_summary' => "{$formattedAmount} - {$title} (online)", 'activity_date' => $mail_date);
         require_once 'api/History.php';
         if (is_a(crm_create_activity_history($ahParams), 'CRM_Core_Error')) {
             $this->_addToSummary("AN ACTIVITY HISTORY RECORD COULD NOT BE CREATED.");
         } else {
             $this->_addToSummary("Activity History record created.");
         }
         $this->_addToSummary("Transaction {$transactionId} has been processed.");
         $first_contribution->free();
         $contribution_page->free();
         $contribution->free();
         $recur->free();
         $trxn->free();
     }
     $this->_addToSummary("Done processing {$csv_name}");
     $this->_addToSummary('');
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  */
 function &export($prefix = false)
 {
     if (!$GLOBALS['_CRM_CONTRIBUTE_DAO_CONTRIBUTIONPAGE']['_export']) {
         $GLOBALS['_CRM_CONTRIBUTE_DAO_CONTRIBUTIONPAGE']['_export'] = array();
         $fields =& CRM_Contribute_DAO_ContributionPage::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     $GLOBALS['_CRM_CONTRIBUTE_DAO_CONTRIBUTIONPAGE']['_export']['contribution_page'] =& $fields[$name];
                 } else {
                     $GLOBALS['_CRM_CONTRIBUTE_DAO_CONTRIBUTIONPAGE']['_export'][$name] =& $fields[$name];
                 }
             }
         }
     }
     return $GLOBALS['_CRM_CONTRIBUTE_DAO_CONTRIBUTIONPAGE']['_export'];
 }