function __construct()
 {
     self::$nscd_fid = _iats_civicrm_nscd_fid();
     self::$version = _iats_civicrm_domain_info('version');
     self::$financial_types = self::$version[0] <= 4 && self::$version[1] <= 2 ? array() : CRM_Contribute_PseudoConstant::financialType();
     if (self::$version[0] <= 4 && self::$version[1] < 4) {
         self::$prefixes = CRM_Core_PseudoConstant::individualPrefix();
         self::$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     } else {
         self::$prefixes = CRM_Contact_BAO_Contact::buildOptions('individual_prefix_id');
         self::$contributionStatus = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
     }
     $params = array('version' => 3, 'sequential' => 1, 'is_test' => 0, 'return.name' => 1);
     $result = civicrm_api('PaymentProcessor', 'get', $params);
     foreach ($result['values'] as $pp) {
         self::$processors[$pp['id']] = $pp['name'];
     }
     $this->_columns = array('civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'order_bys' => array('sort_name' => array('title' => ts("Last name, First name"))), 'fields' => array('first_name' => array('title' => ts('First Name')), 'last_name' => array('title' => ts('Last Name')), 'prefix_id' => array('title' => ts('Prefix')), 'sort_name' => array('title' => ts('Contact Name'), 'no_repeat' => TRUE, 'default' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'order_bys' => array('email' => array('title' => ts('Email'))), 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_contribution' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'fields' => array('id' => array('title' => ts('Contribution ID(s)'), 'required' => TRUE, 'dbAlias' => "GROUP_CONCAT(contribution_civireport.id SEPARATOR ', ')"), 'total_amount' => array('title' => ts('Amount Contributed to date'), 'required' => TRUE, 'statistics' => array('sum' => ts("Total Amount contributed")))), 'filters' => array('total_amount' => array('title' => ts('Total Amount'), 'operatorType' => CRM_Report_Form::OP_FLOAT, 'type' => CRM_Utils_Type::T_FLOAT))), 'civicrm_iats_customer_codes' => array('dao' => 'CRM_Contribute_DAO_Contribution', 'order_bys' => array('expiry' => array('title' => ts("Expiry Date"))), 'fields' => array('customer_code' => array('title' => 'customer code', 'default' => TRUE), 'expiry' => array('title' => 'Expiry Date', 'default' => TRUE))), 'civicrm_contribution_recur' => array('dao' => 'CRM_Contribute_DAO_ContributionRecur', 'order_bys' => array('id' => array('title' => ts("Series ID")), 'amount' => array('title' => ts("Current Amount")), 'start_date' => array('title' => ts('Start Date')), 'modified_date' => array('title' => ts('Modified Date')), self::$nscd_fid => array('title' => ts('Next Scheduled Contribution Date')), 'cycle_day' => array('title' => ts('Cycle Day')), 'payment_processor_id' => array('title' => ts('Payment Processor'))), 'fields' => array('id' => array('required' => TRUE, 'title' => ts("Series ID")), 'recur_id' => array('name' => 'id', 'title' => ts('Series ID')), 'invoice_id' => array('title' => ts('Invoice ID'), 'default' => FALSE), 'currency' => array('title' => ts("Currency")), 'amount' => array('title' => ts('Amount'), 'default' => TRUE), 'contribution_status_id' => array('title' => ts('Donation Status')), 'frequency_interval' => array('title' => ts('Frequency interval'), 'default' => TRUE), 'frequency_unit' => array('title' => ts('Frequency unit'), 'default' => TRUE), 'installments' => array('title' => ts('Installments'), 'default' => TRUE), 'start_date' => array('title' => ts('Start Date'), 'default' => TRUE), 'create_date' => array('title' => ts('Create Date')), 'modified_date' => array('title' => ts('Modified Date')), 'cancel_date' => array('title' => ts('Cancel Date')), self::$nscd_fid => array('title' => ts('Next Scheduled Contribution Date'), 'default' => TRUE), 'next_scheduled_day' => array('name' => self::$nscd_fid, 'dbAlias' => 'DAYOFMONTH(contribution_recur_civireport.next_sched_contribution)', 'title' => ts('Next Scheduled Day of the Month')), 'cycle_day' => array('title' => ts('Cycle Day')), 'failure_count' => array('title' => ts('Failure Count')), 'failure_retry_date' => array('title' => ts('Failure Retry Date')), 'payment_processor_id' => array('title' => ts('Payment Processor'), 'default' => TRUE)), 'filters' => array('contribution_status_id' => array('title' => ts('Donation Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => self::$contributionStatus, 'default' => array(5), 'type' => CRM_Utils_Type::T_INT), 'payment_processor_id' => array('title' => ts('Payment Processor'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => self::$processors, 'type' => CRM_Utils_Type::T_INT), 'currency' => array('title' => 'Currency', 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('currencies_enabled'), 'default' => NULL, 'type' => CRM_Utils_Type::T_STRING), 'financial_type_id' => array('title' => ts('Financial Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => self::$financial_types, 'type' => CRM_Utils_Type::T_INT), 'frequency_unit' => array('title' => ts('Frequency Unit'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_OptionGroup::values('recur_frequency_units')), self::$nscd_fid => array('title' => ts('Next Scheduled Contribution Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'next_scheduled_day' => array('title' => ts('Next Scheduled Day'), 'operatorType' => CRM_Report_Form::OP_INT, 'type' => CRM_Utils_Type::T_INT), 'cycle_day' => array('title' => ts('Cycle Day'), 'operatorType' => CRM_Report_Form::OP_INT, 'type' => CRM_Utils_Type::T_INT), 'start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'modified_date' => array('title' => ts('Modified Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'cancel_date' => array('title' => ts('Cancel Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE))), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('street_address' => array('title' => ts('Address'), 'default' => FALSE), 'supplemental_address_1' => array('title' => ts('Supplementary Address Field 1'), 'default' => FALSE), 'supplemental_address_2' => array('title' => ts('Supplementary Address Field 2'), 'default' => FALSE), 'city' => array('title' => 'City', 'default' => FALSE), 'state_province_id' => array('title' => 'Province', 'default' => FALSE, 'alter_display' => 'alterStateProvinceID'), 'postal_code' => array('title' => 'Postal Code', 'default' => FALSE), 'country_id' => array('title' => 'Country', 'default' => FALSE, 'alter_display' => 'alterCountryID')), 'grouping' => 'contact-fields'));
     if (empty(self::$financial_types)) {
         unset($this->_columns['civicrm_contribution_recur']['filters']['financial_type_id']);
     }
     parent::__construct();
 }
Beispiel #2
0
 /**
  * Process credit card payment.
  *
  * @param array $submittedValues
  * @param array $lineItem
  *
  * @param int $contactID
  *   Contact ID
  *
  * @return bool|\CRM_Contribute_DAO_Contribution
  * @throws \CRM_Core_Exception
  * @throws \Civi\Payment\Exception\PaymentProcessorException
  */
 protected function processCreditCard($submittedValues, $lineItem, $contactID)
 {
     $isTest = $this->_mode == 'test' ? 1 : 0;
     // CRM-12680 set $_lineItem if its not set
     // @todo - I don't believe this would ever BE set. I can't find anywhere in the code.
     // It would be better to pass line item out to functions than $this->_lineItem as
     // we don't know what is being changed where.
     if (empty($this->_lineItem) && !empty($lineItem)) {
         $this->_lineItem = $lineItem;
     }
     $this->_paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']);
     $this->_paymentProcessor = $this->_paymentObject->getPaymentProcessor();
     // Set source if not set
     if (empty($submittedValues['source'])) {
         $userID = CRM_Core_Session::singleton()->get('userID');
         $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID, 'sort_name');
         $submittedValues['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
     }
     $params = $submittedValues;
     $this->_params = array_merge($this->_params, $submittedValues);
     // Mapping requiring documentation.
     $this->_params['payment_processor'] = $submittedValues['payment_processor_id'];
     $now = date('YmdHis');
     // we need to retrieve email address
     if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     $this->_contributorEmail = $this->userEmail;
     $this->_contributorContactID = $contactID;
     $this->processBillingAddress();
     if (!empty($params['source'])) {
         unset($params['source']);
     }
     $this->_params['amount'] = $this->_params['total_amount'];
     // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
     // function to get correct amount level consistently. Remove setting of the amount level in
     // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
     // to cover all variants.
     $this->_params['amount_level'] = 0;
     $this->_params['description'] = ts("Contribution submitted by a staff person using contributor's credit card");
     $this->_params['currencyID'] = CRM_Utils_Array::value('currency', $this->_params, CRM_Core_Config::singleton()->defaultCurrency);
     if (!empty($this->_params['receive_date'])) {
         $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
     }
     $this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
     $this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
     $this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
     //Add common data to formatted params
     CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
     if (empty($this->_params['invoice_id'])) {
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
     } else {
         $this->_params['invoiceID'] = $this->_params['invoice_id'];
     }
     // At this point we've created a contact and stored its address etc
     // all the payment processors expect the name and address to be in the
     // so we copy stuff over to first_name etc.
     $paymentParams = $this->_params;
     $paymentParams['contactID'] = $contactID;
     CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
     $financialType = new CRM_Financial_DAO_FinancialType();
     $financialType->id = $params['financial_type_id'];
     $financialType->find(TRUE);
     // Add some financial type details to the params list
     // if folks need to use it.
     $paymentParams['contributionType_name'] = $this->_params['contributionType_name'] = $financialType->name;
     $paymentParams['contributionPageID'] = NULL;
     if (!empty($this->_params['is_email_receipt'])) {
         $paymentParams['email'] = $this->userEmail;
         $paymentParams['is_email_receipt'] = 1;
     } else {
         $paymentParams['is_email_receipt'] = 0;
         $this->_params['is_email_receipt'] = 0;
     }
     if (!empty($this->_params['receive_date'])) {
         $paymentParams['receive_date'] = $this->_params['receive_date'];
     }
     $this->_params['receive_date'] = $now;
     if (!empty($this->_params['is_email_receipt'])) {
         $this->_params['receipt_date'] = $now;
     } else {
         $this->_params['receipt_date'] = CRM_Utils_Date::processDate($this->_params['receipt_date'], $params['receipt_date_time'], TRUE);
     }
     $this->set('params', $this->_params);
     $this->assign('receive_date', $this->_params['receive_date']);
     // Result has all the stuff we need
     // lets archive it to a financial transaction
     if ($financialType->is_deductible) {
         $this->assign('is_deductible', TRUE);
         $this->set('is_deductible', TRUE);
     }
     $contributionParams = array('contact_id' => $contactID, 'line_item' => $lineItem, 'is_test' => $isTest, 'campaign_id' => CRM_Utils_Array::value('campaign_id', $this->_params), 'contribution_page_id' => CRM_Utils_Array::value('contribution_page_id', $this->_params), 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)), 'thankyou_date' => CRM_Utils_Array::value('thankyou_date', $this->_params));
     if (empty($paymentParams['is_pay_later'])) {
         // @todo look up payment_instrument_id on payment processor table.
         $contributionParams['payment_instrument_id'] = 1;
     }
     $contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this, $this->_params, NULL, $contributionParams, $financialType, FALSE, $this->_bltID, CRM_Utils_Array::value('is_recur', $this->_params));
     $paymentParams['contributionID'] = $contribution->id;
     $paymentParams['contributionTypeID'] = $contribution->financial_type_id;
     $paymentParams['contributionPageID'] = $contribution->contribution_page_id;
     $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id;
     if ($paymentParams['amount'] > 0.0) {
         // force a re-get of the payment processor in case the form changed it, CRM-7179
         // NOTE - I expect this is obsolete.
         $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
         try {
             $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
             $result = $payment->doPayment($paymentParams, 'contribute');
             $this->assign('trxn_id', $result['trxn_id']);
             $contribution->trxn_id = $result['trxn_id'];
             /* Our scenarios here are
              *  1) the payment failed & an Exception should have been thrown
              *  2) the payment succeeded but the payment is not immediate (for example a recurring payment
              *     with a delayed start)
              *  3) the payment succeeded with an immediate payment.
              *
              * The doPayment function ensures that payment_status_id is always set
              * as historically we have had to guess from the context - ie doDirectPayment
              * = error or success, unless it is a recurring contribution in which case it is pending.
              */
             if ($result['payment_status_id'] == array_search('Completed', $statuses)) {
                 try {
                     civicrm_api3('contribution', 'completetransaction', array('id' => $contribution->id, 'trxn_id' => $result['trxn_id'], 'payment_processor_id' => $this->_paymentProcessor['id'], 'is_transactional' => FALSE, 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result)));
                     // This has now been set to 1 in the DB - declare it here also
                     $contribution->contribution_status_id = 1;
                 } catch (CiviCRM_API3_Exception $e) {
                     if ($e->getErrorCode() != 'contribution_completed') {
                         throw new CRM_Core_Exception('Failed to update contribution in database');
                     }
                 }
             } else {
                 // Save the trxn_id.
                 $contribution->save();
             }
         } catch (PaymentProcessorException $e) {
             CRM_Contribute_BAO_Contribution::failPayment($contribution->id, $paymentParams['contactID'], $e->getMessage());
             throw new PaymentProcessorException($e->getMessage());
         }
     }
     // Send receipt mail.
     array_unshift($this->statusMessage, ts('The contribution record has been saved.'));
     if ($contribution->id && !empty($this->_params['is_email_receipt'])) {
         $this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
         $this->_params['contact_id'] = $contactID;
         $this->_params['contribution_id'] = $contribution->id;
         if (CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE)) {
             $this->statusMessage[] = ts('A receipt has been emailed to the contributor.');
         }
     }
     return $contribution;
 }
Beispiel #3
0
 /**
  * Get a list of status options.
  *
  * @param string|int $value
  *   The list of status options may be contingent upon the selected filter value.
  *   This is the selected filter value.
  * @return array
  *   Array(string $value => string $label).
  *   Ex: Array(123 => 'Completed', 456 => 'Scheduled').
  * @throws CRM_Core_Exception
  */
 public function getStatusLabels($value)
 {
     return CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'get', array());
 }
Beispiel #4
0
 /**
  * Submit a manual payment.
  *
  * @param array $params
  *   Assoc array of input parameters for this transaction.
  *
  * @return array
  */
 public function doDirectPayment(&$params)
 {
     $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
     if ($params['is_pay_later']) {
         $result['payment_status_id'] = array_search('Pending', $statuses);
     } else {
         $result['payment_status_id'] = array_search('Completed', $statuses);
     }
     return $result;
 }
 /**
  * Process payment - this function wraps around both doTransferPayment and doDirectPayment.
  *
  * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms
  * more agnostic.
  *
  * Payment processors should set payment_status_id. This function adds some historical defaults ie. the
  * assumption that if a 'doDirectPayment' processors comes back it completed the transaction & in fact
  * doTransferCheckout would not traditionally come back.
  *
  * doDirectPayment does not do an immediate payment for Authorize.net or Paypal so the default is assumed
  * to be Pending.
  *
  * Once this function is fully rolled out then it will be preferred for processors to throw exceptions than to
  * return Error objects
  *
  * @param array $params
  *
  * @param string $component
  *
  * @return array
  *   Result array
  *
  * @throws \Civi\Payment\Exception\PaymentProcessorException
  */
 public function doPayment(&$params, $component = 'contribute')
 {
     $this->_component = $component;
     $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
     if ($this->_paymentProcessor['billing_mode'] == 4) {
         $result = $this->doTransferCheckout($params, $component);
         if (is_array($result) && !isset($result['payment_status_id'])) {
             $result['payment_status_id'] = array_search('Pending', $statuses);
         }
     } else {
         $result = $this->doDirectPayment($params, $component);
         if (is_array($result) && !isset($result['payment_status_id'])) {
             if (!empty($params['is_recur'])) {
                 // See comment block.
                 $result['payment_status_id'] = array_search('Pending', $statuses);
             } else {
                 $result['payment_status_id'] = array_search('Completed', $statuses);
             }
         }
     }
     if (is_a($result, 'CRM_Core_Error')) {
         throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
     }
     return $result;
 }
Beispiel #6
0
 /**
  * Do the express checkout at paypal.
  *
  * Check PayPal documentation for more information
  *
  * @param array $params
  *
  * @return array
  *   The result in an nice formatted array.
  *
  * @throws \Civi\Payment\Exception\PaymentProcessorException
  */
 public function doExpressCheckout(&$params)
 {
     $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
     if (!empty($params['is_recur'])) {
         return $this->createRecurringPayments($params);
     }
     $args = array();
     $this->initialize($args, 'DoExpressCheckoutPayment');
     $args['token'] = $params['token'];
     $args['paymentAction'] = 'Sale';
     $args['amt'] = $params['amount'];
     $args['currencyCode'] = $params['currencyID'];
     $args['payerID'] = $params['payer_id'];
     $args['invnum'] = $params['invoiceID'];
     $args['returnURL'] = $this->getReturnSuccessUrl($params['qfKey']);
     $args['cancelURL'] = $this->getCancelUrl($params['qfKey'], NULL);
     $args['desc'] = $params['description'];
     // add CiviCRM BN code
     $args['BUTTONSOURCE'] = 'CiviCRM_SP';
     $result = $this->invokeAPI($args);
     if (is_a($result, 'CRM_Core_Error')) {
         throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
     }
     /* Success */
     $params['trxn_id'] = $result['transactionid'];
     $params['gross_amount'] = $result['amt'];
     $params['fee_amount'] = $result['feeamt'];
     $params['net_amount'] = CRM_Utils_Array::value('settleamt', $result);
     if ($params['net_amount'] == 0 && $params['fee_amount'] != 0) {
         $params['net_amount'] = number_format($params['gross_amount'] - $params['fee_amount'], 2);
     }
     $params['payment_status'] = $result['paymentstatus'];
     $params['pending_reason'] = $result['pendingreason'];
     if (!empty($params['is_recur'])) {
         // See comment block.
         $params['payment_status_id'] = array_search('Pending', $statuses);
     } else {
         $params['payment_status_id'] = array_search('Completed', $statuses);
     }
     return $params;
 }
 /**
  * Process credit card payment.
  *
  * @param array $submittedValues
  * @param array $lineItem
  *
  * @param int $contactID
  *   Contact ID
  *
  * @return bool|\CRM_Contribute_DAO_Contribution
  * @throws \CiviCRM_API3_Exception
  * @throws \Civi\Payment\Exception\PaymentProcessorException
  */
 protected function processCreditCard($submittedValues, $lineItem, $contactID)
 {
     $contribution = FALSE;
     $isTest = $this->_mode == 'test' ? 1 : 0;
     // CRM-12680 set $_lineItem if its not set
     // @todo - I don't believe this would ever BE set. I can't find anywhere in the code.
     // It would be better to pass line item out to functions than $this->_lineItem as
     // we don't know what is being changed where.
     if (empty($this->_lineItem) && !empty($lineItem)) {
         $this->_lineItem = $lineItem;
     }
     $this->_paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']);
     $this->_paymentProcessor = $this->_paymentObject->getPaymentProcessor();
     // Set source if not set
     if (empty($submittedValues['source'])) {
         $userID = CRM_Core_Session::singleton()->get('userID');
         $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID, 'sort_name');
         $submittedValues['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
     }
     $params = $this->_params = $submittedValues;
     // Mapping requiring documentation.
     $this->_params['payment_processor'] = $submittedValues['payment_processor_id'];
     $now = date('YmdHis');
     $fields = array();
     // we need to retrieve email address
     if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     // Set email for primary location.
     $fields['email-Primary'] = 1;
     $params['email-Primary'] = $this->userEmail;
     // now set the values for the billing location.
     foreach (array_keys($this->_fields) as $name) {
         $fields[$name] = 1;
     }
     // also add location name to the array
     $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
     $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
     $fields["address_name-{$this->_bltID}"] = 1;
     $nameFields = array('first_name', 'middle_name', 'last_name');
     foreach ($nameFields as $name) {
         $fields[$name] = 1;
         if (array_key_exists("billing_{$name}", $params)) {
             $params[$name] = $params["billing_{$name}"];
             $params['preserveDBName'] = TRUE;
         }
     }
     if (!empty($params['source'])) {
         unset($params['source']);
     }
     CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, NULL, NULL, CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'));
     // add all the additional payment params we need
     if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
     }
     if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
     }
     if (in_array('credit_card_exp_date', array_keys($this->_paymentFields))) {
         $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
         $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
     }
     $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
     $this->_params['amount'] = $this->_params['total_amount'];
     $this->_params['amount_level'] = 0;
     $this->_params['description'] = ts('Office Credit Card contribution');
     $this->_params['currencyID'] = CRM_Utils_Array::value('currency', $this->_params, CRM_Core_Config::singleton()->defaultCurrency);
     if (!empty($this->_params['receive_date'])) {
         $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
     }
     if (!empty($params['soft_credit_to'])) {
         $this->_params['soft_credit_to'] = $params['soft_credit_to'];
         $this->_params['pcp_made_through_id'] = $params['pcp_made_through_id'];
     }
     $this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
     $this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
     $this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
     //Add common data to formatted params
     CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
     if (empty($this->_params['invoice_id'])) {
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
     } else {
         $this->_params['invoiceID'] = $this->_params['invoice_id'];
     }
     // At this point we've created a contact and stored its address etc
     // all the payment processors expect the name and address to be in the
     // so we copy stuff over to first_name etc.
     $paymentParams = $this->_params;
     $paymentParams['contactID'] = $contactID;
     CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
     $financialType = new CRM_Financial_DAO_FinancialType();
     $financialType->id = $params['financial_type_id'];
     // Add some financial type details to the params list
     // if folks need to use it.
     $paymentParams['contributionType_name'] = $this->_params['contributionType_name'] = $financialType->name;
     $paymentParams['contributionPageID'] = NULL;
     if (!empty($this->_params['is_email_receipt'])) {
         $paymentParams['email'] = $this->userEmail;
         $paymentParams['is_email_receipt'] = 1;
     } else {
         $paymentParams['is_email_receipt'] = 0;
         $this->_params['is_email_receipt'] = 0;
     }
     if (!empty($this->_params['receive_date'])) {
         $paymentParams['receive_date'] = $this->_params['receive_date'];
     }
     $this->_params['receive_date'] = $now;
     if (!empty($this->_params['is_email_receipt'])) {
         $this->_params['receipt_date'] = $now;
     } else {
         $this->_params['receipt_date'] = CRM_Utils_Date::processDate($this->_params['receipt_date'], $params['receipt_date_time'], TRUE);
     }
     $this->set('params', $this->_params);
     $this->assign('receive_date', $this->_params['receive_date']);
     // Result has all the stuff we need
     // lets archive it to a financial transaction
     if ($financialType->is_deductible) {
         $this->assign('is_deductible', TRUE);
         $this->set('is_deductible', TRUE);
     }
     $contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this, $this->_params, NULL, $contactID, $financialType, TRUE, FALSE, $isTest, $lineItem, $this->_bltID);
     $paymentParams['contributionID'] = $contribution->id;
     $paymentParams['contributionTypeID'] = $contribution->financial_type_id;
     $paymentParams['contributionPageID'] = $contribution->contribution_page_id;
     $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id;
     if ($paymentParams['amount'] > 0.0) {
         // force a re-get of the payment processor in case the form changed it, CRM-7179
         // NOTE - I expect this is not obsolete.
         $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this, TRUE);
         try {
             $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
             $result = $payment->doPayment($paymentParams, 'contribute');
             $this->assign('trxn_id', $result['trxn_id']);
             $contribution->trxn_id = $result['trxn_id'];
             /* Our scenarios here are
              *  1) the payment failed & an Exception should have been thrown
              *  2) the payment succeeded but the payment is not immediate (for example a recurring payment
              *     with a delayed start)
              *  3) the payment succeeded with an immediate payment.
              *
              * The doPayment function ensures that contribution_status_id is always set
              * as historically we have had to guess from the context - ie doDirectPayment
              * = error or success, unless it is a recurring contribution in which case it is pending.
              */
             if (!isset($result['contribution_status_id']) || $result['contribution_status_id'] == array_search('Completed', $statuses)) {
                 civicrm_api3('contribution', 'completetransaction', array('id' => $contribution->id, 'trxn_id' => $result['trxn_id']));
             } else {
                 // Save the trxn_id.
                 $contribution->save();
             }
         } catch (PaymentProcessorException $e) {
             CRM_Contribute_BAO_Contribution::failPayment($contribution->id, $paymentParams['contactID'], $e->getMessage());
             throw new PaymentProcessorException($e->getMessage());
         }
     }
     // Send receipt mail.
     if ($contribution->id && !empty($this->_params['is_email_receipt'])) {
         $this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
         $this->_params['contact_id'] = $contactID;
         $this->_params['contribution_id'] = $contribution->id;
         if (CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE)) {
             $this->statusMessage[] = ts('A receipt has been emailed to the contributor.');
         }
     }
     return $contribution;
 }
Beispiel #8
0
 /**
  * Process payment - this function wraps around both doTransferPayment and doDirectPayment.
  *
  * The function ensures an exception is thrown & moves some of this logic out of the form layer and makes the forms
  * more agnostic.
  *
  * Payment processors should set payment_status_id. This function adds some historical defaults ie. the
  * assumption that if a 'doDirectPayment' processors comes back it completed the transaction & in fact
  * doTransferCheckout would not traditionally come back.
  *
  * doDirectPayment does not do an immediate payment for Authorize.net or Paypal so the default is assumed
  * to be Pending.
  *
  * Once this function is fully rolled out then it will be preferred for processors to throw exceptions than to
  * return Error objects
  *
  * @param array $params
  *
  * @param string $component
  *
  * @return array
  *   Result array
  *
  * @throws \Civi\Payment\Exception\PaymentProcessorException
  */
 public function doPayment(&$params, $component = 'contribute')
 {
     $this->_component = $component;
     $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
     // If we have a $0 amount, skip call to processor and set payment_status to Completed.
     // Conceivably a processor might override this - perhaps for setting up a token - but we don't
     // have an example of that at the mome.
     if ($params['amount'] == 0) {
         $result['payment_status_id'] = array_search('Completed', $statuses);
         return $result;
     }
     if ($this->_paymentProcessor['billing_mode'] == 4) {
         $result = $this->doTransferCheckout($params, $component);
         if (is_array($result) && !isset($result['payment_status_id'])) {
             $result['payment_status_id'] = array_search('Pending', $statuses);
         }
     } else {
         $result = $this->doDirectPayment($params, $component);
         if (is_array($result) && !isset($result['payment_status_id'])) {
             if (!empty($params['is_recur'])) {
                 // See comment block.
                 $result['payment_status_id'] = array_search('Pending', $statuses);
             } else {
                 $result['payment_status_id'] = array_search('Completed', $statuses);
             }
         }
     }
     if (is_a($result, 'CRM_Core_Error')) {
         throw new PaymentProcessorException(CRM_Core_Error::getMessages($result));
     }
     return $result;
 }