function getSmartDebitPayments($referenceNumber)
 {
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     $paymentProcessorTypeId = CRM_Utils_Array::key('Smart Debit', $paymentProcessorType);
     $domainID = CRM_Core_Config::domainID();
     $sql = " SELECT user_name ";
     $sql .= " ,      password ";
     $sql .= " ,      signature ";
     $sql .= " FROM civicrm_payment_processor ";
     $sql .= " WHERE payment_processor_type_id = %1";
     $sql .= " AND is_test= %2 AND domain_id = %3";
     $params = array(1 => array($paymentProcessorTypeId, 'Integer'), 2 => array('0', 'Int'), 3 => array($domainID, 'Int'));
     $dao = CRM_Core_DAO::executeQuery($sql, $params);
     if ($dao->fetch()) {
         $username = $dao->user_name;
         $password = $dao->password;
         $pslid = $dao->signature;
     }
     // Send payment POST to the target URL
     $url = "https://secure.ddprocessing.co.uk/api/data/dump?query[service_user][pslid]={$pslid}&query[report_format]=XML";
     // Restrict to a single payer if we have a reference
     if ($referenceNumber) {
         $url .= "&query[reference_number]={$referenceNumber}";
     }
     $response = self::requestPost($url, $username, $password);
     // Take action based upon the response status
     switch (strtoupper($response["Status"])) {
         case 'OK':
             $smartDebitArray = array();
             // Cater for a single response
             if (isset($response['Data']['PayerDetails']['@attributes'])) {
                 $smartDebitArray[] = $response['Data']['PayerDetails']['@attributes'];
             } else {
                 foreach ($response['Data']['PayerDetails'] as $key => $value) {
                     $smartDebitArray[] = $value['@attributes'];
                 }
             }
             return $smartDebitArray;
         default:
             return false;
     }
 }
示例#2
0
 /**
  * This function checks to see if we have the right config values.
  *
  * @return string
  *   the error message if any
  */
 public function checkConfig()
 {
     $error = array();
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');
     if ($this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType) || $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('PayPal', $paymentProcessorType)) {
         if (empty($this->_paymentProcessor['user_name'])) {
             $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
         }
     }
     if ($this->_paymentProcessor['payment_processor_type_id'] != CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType)) {
         if (empty($this->_paymentProcessor['signature'])) {
             $error[] = ts('Signature is not set in the Administer » System Settings » Payment Processors.');
         }
         if (empty($this->_paymentProcessor['password'])) {
             $error[] = ts('Password is not set in the Administer » System Settings » Payment Processors.');
         }
     }
     if (!empty($error)) {
         return implode('<p>', $error);
     } else {
         return NULL;
     }
 }
示例#3
0
 /**
  * Function to build payment processor details
  *
  * @param object $dao   payment processor object
  * @param  string $mode payment mode ie test or live
  *
  * @return array  associated array with payment processor related fields
  * @static
  * @access public
  */
 static function buildPayment($dao, $mode)
 {
     $fields = array('id', 'name', 'payment_processor_type_id', 'user_name', 'password', 'signature', 'url_site', 'url_api', 'url_recur', 'url_button', 'subject', 'class_name', 'is_recur', 'billing_mode', 'payment_type', 'is_default');
     $result = array();
     foreach ($fields as $name) {
         $result[$name] = $dao->{$name};
     }
     $result['payment_processor_type'] = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $dao->payment_processor_type_id, 'name');
     $result['instance'] =& CRM_Core_Payment::singleton($mode, $result);
     return $result;
 }
示例#4
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $params = $this->_params;
     // make sure we have values for it
     if (!empty($this->_values['honoree_profile_id']) && !empty($params['soft_credit_type_id'])) {
         $honorName = NULL;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($this->_values['honoree_profile_id']);
         $this->buildCustom($this->_values['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if ($invoicing) {
         $getTaxDetails = FALSE;
         $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
         foreach ($this->_lineItem as $key => $value) {
             foreach ($value as $v) {
                 if (isset($v['tax_rate'])) {
                     if ($v['tax_rate'] != '') {
                         $getTaxDetails = TRUE;
                     }
                 }
             }
         }
         $this->assign('getTaxDetails', $getTaxDetails);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('totalTaxAmount', $params['tax_amount']);
     }
     if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviMember', $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             $this->buildMembershipBlock($this->_membershipContactID, FALSE, $params['selectMembership'], FALSE);
             if (!empty($params['auto_renew'])) {
                 $this->assign('auto_renew', TRUE);
             }
         } else {
             $this->assign('membershipBlock', FALSE);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($this->_values['onbehalf_profile_id']) && !empty($params['onbehalf'])) {
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($this->_values['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');
     if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'crm-form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('Go Back'))));
     } else {
         // The concept of contributeMode is deprecated.
         // the is_monetary concept probably should be too as it can be calculated from
         // the existence of 'amount' & seems fragile.
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue');
             $this->assign('button', ts('Continue'));
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', ts('Make Contribution'));
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array_fill_keys(array_keys($this->_fields), 1);
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         // Recursively set defaults for nested fields
         if (isset($contact[$name]) && is_array($contact[$name]) && ($name == 'onbehalf' || $name == 'honor')) {
             foreach ($contact[$name] as $fieldName => $fieldValue) {
                 if (is_array($fieldValue) && !in_array($this->_fields[$name][$fieldName]['html_type'], array('Multi-Select', 'AdvMulti-Select'))) {
                     foreach ($fieldValue as $key => $value) {
                         $defaults["{$name}[{$fieldName}][{$key}]"] = $value;
                     }
                 } else {
                     $defaults["{$name}[{$fieldName}]"] = $fieldValue;
                 }
             }
         } elseif (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
                 if (isset($contact["{$name}_id"])) {
                     $defaults["{$name}_id"] = $contact["{$name}_id"];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->assign('useForMember', $this->get('useForMember'));
     $this->setDefaults($defaults);
     $this->freeze();
 }
示例#5
0
 /**
  * Build the form object.
  *
  * @param bool $check
  *
  * @return void
  */
 public function buildQuickForm($check = FALSE)
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessor');
     $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
     $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Financial_DAO_PaymentProcessor', $this->_id));
     $this->add('text', 'description', ts('Description'), $attributes['description']);
     $types = CRM_Core_PseudoConstant::paymentProcessorType();
     $this->add('select', 'payment_processor_type_id', ts('Payment Processor Type'), $types, TRUE, array('onchange' => "reload(true)"));
     // Financial Account of account type asset CRM-11515
     $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
     $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
     if ($fcount = count($financialAccount)) {
         $this->assign('financialAccount', $fcount);
     }
     $this->add('select', 'financial_account_id', ts('Financial Account'), array('' => ts('- select -')) + $financialAccount, TRUE);
     // is this processor active ?
     $this->add('checkbox', 'is_active', ts('Is this Payment Processor active?'));
     $this->add('checkbox', 'is_default', ts('Is this Payment Processor the default?'));
     foreach ($this->_fields as $field) {
         if (empty($field['label'])) {
             continue;
         }
         $this->add('text', $field['name'], $field['label'], $attributes[$field['name']]);
         $this->add('text', "test_{$field['name']}", $field['label'], $attributes[$field['name']]);
         if (!empty($field['rule'])) {
             $this->addRule($field['name'], $field['msg'], $field['rule']);
             $this->addRule("test_{$field['name']}", $field['msg'], $field['rule']);
         }
     }
     $this->addFormRule(array('CRM_Admin_Form_PaymentProcessor', 'formRule'));
 }
示例#6
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->assignToTemplate();
     $params = $this->_params;
     $honor_block_is_active = $this->get('honor_block_is_active');
     // make sure we have values for it
     if ($honor_block_is_active && !empty($params['soft_credit_type_id'])) {
         $honorName = null;
         $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
         $this->assign('honor_block_is_active', $honor_block_is_active);
         $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]);
         CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']);
         $fieldTypes = array('Contact');
         $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']);
         $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes);
     }
     $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
     $amount_block_is_active = $this->get('amount_block_is_active');
     $this->assign('amount_block_is_active', $amount_block_is_active);
     if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') {
         $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
         $productID = $params['selectProduct'];
         CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option);
         $this->set('productID', $productID);
         $this->set('option', $option);
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviMember', $config->enableComponents)) {
         if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') {
             CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, FALSE, $params['selectMembership'], FALSE);
         } else {
             $this->assign('membershipBlock', FALSE);
         }
     }
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
     if (!empty($params['hidden_onbehalf_profile'])) {
         $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
         $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
         $profileId = $OnBehalfProfile[0];
         $fieldTypes = array('Contact', 'Organization');
         $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
         $fieldTypes = array_merge($fieldTypes, $contactSubType);
         if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
             $fieldTypes = array_merge($fieldTypes, array('Membership'));
         } else {
             $fieldTypes = array_merge($fieldTypes, array('Contribution'));
         }
         $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes);
     }
     $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
     $this->assign('is_separate_payment', $this->_separateMembershipPayment);
     if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
         $this->assign('lineItem', $this->_lineItem);
     } else {
         $this->assign('is_quick_config', 1);
         $this->_params['is_quick_config'] = 1;
     }
     $this->assign('priceSetID', $this->_priceSetId);
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) {
         $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
         $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit'));
         $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back'))));
     } else {
         if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) {
             $contribButton = ts('Continue >>');
             $this->assign('button', ts('Continue'));
         } else {
             $contribButton = ts('Make Contribution');
             $this->assign('button', ts('Make Contribution'));
         }
         $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back'))));
     }
     $defaults = array();
     $fields = array();
     foreach ($this->_fields as $name => $dontCare) {
         if ($name != 'onbehalf' || $name != 'honor') {
             $fields[$name] = 1;
         }
     }
     $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
     $contact = $this->_params;
     foreach ($fields as $name => $dontCare) {
         if (isset($contact[$name])) {
             $defaults[$name] = $contact[$name];
             if (substr($name, 0, 7) == 'custom_') {
                 $timeField = "{$name}_time";
                 if (isset($contact[$timeField])) {
                     $defaults[$timeField] = $contact[$timeField];
                 }
                 if (isset($contact["{$name}_id"])) {
                     $defaults["{$name}_id"] = $contact["{$name}_id"];
                 }
             } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) {
                 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
             }
         }
     }
     $this->assign('useForMember', $this->get('useForMember'));
     // now fix all state country selectors
     CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
     $this->setDefaults($defaults);
     $this->freeze();
 }
示例#7
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param $self
  *
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     //as for separate membership payment we has to have
     //contribution amount section enabled, hence to disable it need to
     //check if separate membership payment enabled,
     //if so disable first separate membership payment option
     //then disable contribution amount section. CRM-3801,
     $membershipBlock = new CRM_Member_DAO_MembershipBlock();
     $membershipBlock->entity_table = 'civicrm_contribution_page';
     $membershipBlock->entity_id = $self->_id;
     $membershipBlock->is_active = 1;
     $hasMembershipBlk = FALSE;
     if ($membershipBlock->find(TRUE)) {
         if (!empty($fields['amount_block_is_active']) && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $self->_id, NULL, 1))) {
             $extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
             if ($extends && $extends == CRM_Core_Component::getComponentID('CiviMember')) {
                 $errors['amount_block_is_active'] = ts('You cannot use a Membership Price Set when the Contribution Amounts section is enabled. Click the Memberships tab above, and select your Membership Price Set on that form. Membership Price Sets may include additional fields for non-membership options that require an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
                 return $errors;
             }
         }
         $hasMembershipBlk = TRUE;
         if ($membershipBlock->is_separate_payment && empty($fields['amount_block_is_active'])) {
             $errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.');
         }
         //CRM-16165, Don't allow reccuring contribution if membership block contain any renewable membership option
         $membershipTypes = unserialize($membershipBlock->membership_types);
         if (!empty($fields['is_recur']) && !empty($membershipTypes)) {
             if (!$membershipBlock->is_separate_payment) {
                 $errors['is_recur'] = ts('You need to enable Separate Membership Payment when online contribution page is configured for both Membership and Recurring Contribution.');
             } elseif (count(array_filter($membershipTypes)) != 0) {
                 $errors['is_recur'] = ts('You cannot enable both Recurring Contributions and Auto-renew memberships on the same online contribution page.');
             }
         }
     }
     //check for the amount label (mandatory)
     if (!empty($fields['amount_block_is_active']) && empty($fields['amount_label'])) {
         $errors['amount_label'] = ts('Please enter the contribution amount label.');
     }
     $minAmount = CRM_Utils_Array::value('min_amount', $fields);
     $maxAmount = CRM_Utils_Array::value('max_amount', $fields);
     if (!empty($minAmount) && !empty($maxAmount)) {
         $minAmount = CRM_Utils_Rule::cleanMoney($minAmount);
         $maxAmount = CRM_Utils_Rule::cleanMoney($maxAmount);
         if ((double) $minAmount > (double) $maxAmount) {
             $errors['min_amount'] = ts('Minimum Amount should be less than Maximum Amount');
         }
     }
     if (isset($fields['is_pay_later'])) {
         if (empty($fields['pay_later_text'])) {
             $errors['pay_later_text'] = ts('Please enter the text for the \'pay later\' checkbox displayed on the contribution form.');
         }
         if (empty($fields['pay_later_receipt'])) {
             $errors['pay_later_receipt'] = ts('Please enter the instructions to be sent to the contributor when they choose to \'pay later\'.');
         }
     }
     // don't allow price set w/ membership signup, CRM-5095
     if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
         // don't allow price set w/ membership.
         if ($hasMembershipBlk) {
             $errors['price_set_id'] = ts('You cannot enable both a Contribution Price Set and Membership Signup on the same online contribution page.');
         }
     } else {
         if (isset($fields['is_recur'])) {
             if (empty($fields['recur_frequency_unit'])) {
                 $errors['recur_frequency_unit'] = ts('At least one recurring frequency option needs to be checked.');
             }
         }
         // validation for pledge fields.
         if (!empty($fields['is_pledge_active'])) {
             if (empty($fields['pledge_frequency_unit'])) {
                 $errors['pledge_frequency_unit'] = ts('At least one pledge frequency option needs to be checked.');
             }
             if (!empty($fields['is_recur'])) {
                 $errors['is_recur'] = ts('You cannot enable both Recurring Contributions AND Pledges on the same online contribution page.');
             }
         }
         // If Contribution amount section is enabled, then
         // Allow other amounts must be enabled OR the Fixed Contribution
         // Contribution options must contain at least one set of values.
         if (!empty($fields['amount_block_is_active'])) {
             if (empty($fields['is_allow_other_amount']) && !$priceSetId) {
                 //get the values of amount block
                 $values = CRM_Utils_Array::value('value', $fields);
                 $isSetRow = FALSE;
                 for ($i = 1; $i < self::NUM_OPTION; $i++) {
                     if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
                         $isSetRow = TRUE;
                     }
                 }
                 if (!$isSetRow) {
                     $errors['amount_block_is_active'] = ts('If you want to enable the \'Contribution Amounts section\', you need to either \'Allow Other Amounts\' and/or enter at least one row in the \'Fixed Contribution Amounts\' table.');
                 }
             }
         }
     }
     if (!empty($fields['payment_processor']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($self->_defaultValues['financial_type_id']))) {
         $errors['payment_processor'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
     if (!empty($fields['is_recur_interval'])) {
         foreach (array_keys($fields['payment_processor']) as $paymentProcessorID) {
             $paymentProcessorTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $paymentProcessorID, 'payment_processor_type_id');
             $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $paymentProcessorTypeId, 'name');
         }
     }
     return $errors;
 }
示例#8
0
 /**
  * Get active payment processor types
  */
 private function payProcStats()
 {
     $dao = new CRM_Financial_DAO_PaymentProcessor();
     $dao->is_active = 1;
     $dao->find();
     $ppTypes = array();
     // Get title and id for all processor types
     $ppTypeNames = CRM_Core_PseudoConstant::paymentProcessorType();
     while ($dao->fetch()) {
         $ppTypes[] = $ppTypeNames[$dao->payment_processor_type_id];
     }
     // add the .-separated list of the processor types
     $this->stats['PPTypes'] = implode(',', array_unique($ppTypes));
 }
 /**
  * Get the payment processor details.
  *
  * This returns an array whereas Civi\Payment\System::singleton->getByID() returns an object.
  * The object is a key in the array.
  *
  * @param int $paymentProcessorID
  *   Payment processor id.
  * @param string $mode
  *   Payment mode ie test or live.
  *
  * @return array
  *   associated array with payment processor related fields
  */
 public static function getPayment($paymentProcessorID, $mode = 'based_on_id')
 {
     $capabilities = $mode == 'test' ? array('TestMode') : array();
     $processors = self::getPaymentProcessors($capabilities, array($paymentProcessorID));
     $processor = $processors[$paymentProcessorID];
     $fields = array('id', 'name', 'payment_processor_type_id', 'user_name', 'password', 'signature', 'url_site', 'url_api', 'url_recur', 'url_button', 'subject', 'class_name', 'is_recur', 'billing_mode', 'is_test', 'payment_type', 'is_default');
     // Just to prevent e-Notices elsewhere we set all fields.
     foreach ($fields as $name) {
         if (!isset($processor)) {
             $processor[$name] = NULL;
         }
     }
     $processor['payment_processor_type'] = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, $processor['payment_processor_type_id'], 'name');
     return $processors[$paymentProcessorID];
 }
 function doTransferCheckout(&$params, $component)
 {
     $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
     $paymentProcessorTypeId = CRM_Utils_Array::key('Gocardless', $paymentProcessorType);
     $domainID = CRM_Core_Config::domainID();
     $sql = " SELECT user_name ";
     $sql .= " ,      password ";
     $sql .= " ,      signature ";
     $sql .= " ,      subject ";
     $sql .= " FROM civicrm_payment_processor ";
     $sql .= " WHERE payment_processor_type_id = %1 ";
     $sql .= " AND is_test= %2 ";
     $sql .= " AND domain_id = %3 ";
     $isTest = 0;
     if ($this->_mode == 'test') {
         $isTest = 1;
     }
     $sql_params = array(1 => array($paymentProcessorTypeId, 'Integer'), 2 => array($isTest, 'Int'), 3 => array($domainID, 'Int'));
     $dao = CRM_Core_DAO::executeQuery($sql, $sql_params);
     if ($dao->fetch()) {
         $app_id = $dao->user_name;
         $app_secret = $dao->password;
         $merchant_id = $dao->signature;
         $access_token = $dao->subject;
     }
     $account_details = array('app_id' => $app_id, 'app_secret' => $app_secret, 'merchant_id' => $merchant_id, 'access_token' => $access_token);
     // Fail nicely if no account details set
     if (!$account_details['app_id'] && !$account_details['app_secret']) {
         echo '<p>First sign up to <a href="http://gocardless.com">GoCardless</a> and
     copy your sandbox API credentials from the \'Developer\' tab into the top of
     this script.</p>';
         exit;
     }
     // Set $environment to 'production' if live. Default is 'sandbox'
     if ($this->_mode == 'live') {
         GoCardless::$environment = 'production';
     }
     // Initialize GoCardless
     GoCardless::set_account_details($account_details);
     $goCardLessParams = array();
     $goCardLessParams['amount'] = $params['amount'];
     $goCardLessParams['interval_length'] = $params['frequency_interval'];
     $goCardLessParams['interval_unit'] = $params['frequency_unit'];
     if (!empty($params['preferred_collection_day'])) {
         $preferredCollectionDay = $params['preferred_collection_day'];
         $collectionDate = UK_Direct_Debit_Form_Main::firstCollectionDate($preferredCollectionDay, null);
         // ISO8601 format.
         $goCardLessParams['start_at'] = $collectionDate->format('c');
     }
     $url = $component == 'event' ? 'civicrm/event/register' : 'civicrm/contribute/transact';
     $cancel = $component == 'event' ? '_qf_Register_display' : '_qf_Main_display';
     $returnURL = CRM_Utils_System::url($url, "_qf_ThankYou_display=1&qfKey={$params['qfKey']}" . "&cid={$params['contactID']}", true, null, false);
     $goCardLessParams['redirect_uri'] = $returnURL;
     $goCardLessParams['user'] = array('email' => isset($params['email-5']) ? $params['email-5'] : NULL, 'first_name' => isset($params['first_name']) ? $params['first_name'] : NULL, 'last_name' => isset($params['last_name']) ? $params['last_name'] : NULL, 'billing_address1' => isset($params['street_address']) ? $params['street_address'] : NULL, 'billing_town' => isset($params['city']) ? $params['city'] : NULL, 'billing_postcode' => isset($params['postal_code']) ? $params['postal_code'] : NULL, 'country_code' => 'GB');
     // Allow further manipulation of the arguments via custom hooks ..
     CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $goCardLessParams);
     $subscription_url = GoCardless::new_subscription_url($goCardLessParams);
     CRM_Utils_System::redirect($subscription_url);
 }
示例#11
0
 /**
  * Function for validation
  *
  * @param array $params (ref.) an assoc array of name/value pairs
  *
  * @return mixed true or array of errors
  * @access public
  * @static
  */
 static function formRule($params, $files, $contributionPageId = NULL)
 {
     $errors = array();
     if (CRM_Utils_Array::value('member_price_set_id', $params)) {
         //check if this price set has membership type both auto-renew and non-auto-renew memberships.
         $bothTypes = CRM_Price_BAO_PriceSet::checkMembershipPriceSet($params['member_price_set_id']);
         //check for supporting payment processors
         //if both auto-renew and non-auto-renew memberships
         if ($bothTypes) {
             $paymentProcessorIds = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'payment_processor');
             $paymentProcessorId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $paymentProcessorIds);
             if (!empty($paymentProcessorId)) {
                 $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
                 foreach ($paymentProcessorId as $pid) {
                     if ($pid) {
                         $paymentProcessorTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $pid, 'payment_processor_type_id');
                     }
                     if (!($paymentProcessorTypeId == CRM_Utils_Array::key('PayPal', $paymentProcessorType) || $paymentProcessorTypeId == CRM_Utils_Array::key('AuthNet', $paymentProcessorType))) {
                         $errors['member_price_set_id'] = ts('The membership price set associated with this online contribution allows a user to select BOTH an auto-renew AND a non-auto-renew membership. This requires submitting multiple processor transactions, and is not supported for one or more of the payment processors enabled under the Fees tab.');
                     }
                 }
             }
         }
     }
     if (CRM_Utils_Array::value('member_is_active', $params)) {
         // don't allow price set w/ membership signup, CRM-5095
         if ($contributionPageId && ($setID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $contributionPageId, NULL, 1))) {
             $extends = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'extends');
             if ($extends != CRM_Core_Component::getComponentID('CiviMember')) {
                 $errors['member_is_active'] = ts('You cannot enable both Membership Signup and a Contribution Price Set on the same online contribution page.');
                 return $errors;
             }
         }
         if ($contributionPageId && CRM_Utils_Array::value('member_price_set_id', $params) && CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active')) {
             $errors['member_price_set_id'] = ts('You cannot use Membership Price Sets with the Contribution Amounts section. However, a membership price set may include additional fields for non-membership options that requires an additional fee (e.g. magazine subscription) or an additional voluntary contribution.');
         }
         if (CRM_Utils_Array::value('member_price_set_id', $params)) {
             return $errors;
         }
         if (!isset($params['membership_type']) || !is_array($params['membership_type'])) {
             $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
         } else {
             $membershipType = array_values($params['membership_type']);
             if (array_sum($membershipType) == 0) {
                 $errors['membership_type'] = ts('Please select at least one Membership Type to include in the Membership section of this page.');
             } elseif (array_sum($membershipType) > CRM_Price_Form_Field::NUM_OPTION) {
                 // for CRM-13079
                 $errors['membership_type'] = ts('You cannot select more than %1 choices. For more complex functionality, please use a Price Set.', array(1 => CRM_Price_Form_Field::NUM_OPTION));
             }
         }
         //for CRM-1302
         //if Membership status is not present, then display an error message
         $dao = new CRM_Member_BAO_MembershipStatus();
         if (!$dao->find()) {
             $errors['_qf_default'] = ts('Add status rules, before configuring membership');
         }
         //give error if default is selected for an unchecked membership type
         if (!empty($params['membership_type_default']) && !$params['membership_type'][$params['membership_type_default']]) {
             $errors['membership_type_default'] = ts('Can\'t set default option for an unchecked membership type.');
         }
         if ($contributionPageId) {
             $amountBlock = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageId, 'amount_block_is_active');
             if (!$amountBlock && CRM_Utils_Array::value('is_separate_payment', $params)) {
                 $errors['is_separate_payment'] = ts('Please enable the contribution amount section to use this option.');
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
function smartdebit_civicrm_pageRun(&$page)
{
    $pageName = $page->getVar('_name');
    // To avoid standalone new contribution fail
    if ($pageName == 'CRM_Contribute_Page_Tab' && $page->getVar('_contactId')) {
        $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
        if (!CRM_Utils_Array::key('Smart Debit', $paymentProcessorType)) {
            return;
        }
        $query = "\n      SELECT cr.id, cr.trxn_id FROM civicrm_contribution_recur cr\n      INNER JOIN civicrm_payment_processor cpp ON cpp.id = cr.payment_processor_id\n      INNER JOIN civicrm_payment_processor_type cppt ON cppt.id = cpp.payment_processor_type_id\n      LEFT JOIN civicrm_option_value opva ON (cr.payment_instrument_id = opva.value)\n      LEFT JOIN civicrm_option_group opgr ON (opgr.id = opva.option_group_id) \n      WHERE cppt.name = %1 AND cr.contact_id = %2 AND opgr.name = %3 AND opva.label = %4";
        $queryParams = array(1 => array('Smart Debit', 'String'), 2 => array($page->getVar('_contactId'), 'Int'), 3 => array('payment_instrument', 'String'), 4 => array('Direct Debit', 'String'));
        $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
        $contributionRecurDetails = array();
        while ($dao->fetch()) {
            $smartDebitResponse = CRM_SmartdebitReconciliation_Form_SmartdebitReconciliationList::getSmartDebitPayments($dao->trxn_id);
            foreach ($smartDebitResponse[0] as $key => $value) {
                $contributionRecurDetails[$dao->id][$key] = $value;
            }
        }
        $contributionRecurDetails = json_encode($contributionRecurDetails);
        $page->assign('contributionRecurDetails', $contributionRecurDetails);
        $page->assign('smartdebit', TRUE);
    }
}
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm($check = FALSE)
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_PaymentProcessor');
     $this->add('text', 'name', ts('Name'), $attributes['name'], TRUE);
     $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_PaymentProcessor', $this->_id));
     $this->add('text', 'description', ts('Description'), $attributes['description']);
     $types = CRM_Core_PseudoConstant::paymentProcessorType();
     $this->add('select', 'payment_processor_type', ts('Payment Processor Type'), $types, TRUE, array('onchange' => "reload(true)"));
     // is this processor active ?
     $this->add('checkbox', 'is_active', ts('Is this Payment Processor active?'));
     $this->add('checkbox', 'is_default', ts('Is this Payment Processor the default?'));
     foreach ($this->_fields as $field) {
         if (empty($field['label'])) {
             continue;
         }
         $this->add('text', $field['name'], $field['label'], $attributes[$field['name']]);
         $this->add('text', "test_{$field['name']}", $field['label'], $attributes[$field['name']]);
         if (CRM_Utils_Array::value('rule', $field)) {
             $this->addRule($field['name'], $field['msg'], $field['rule']);
             $this->addRule("test_{$field['name']}", $field['msg'], $field['rule']);
         }
     }
     $this->addFormRule(array('CRM_Admin_Form_PaymentProcessor', 'formRule'));
 }
function civicrm_api3_job_process_offline_recurring_payments($params)
{
    $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
    $paymentProcessorTypeId = CRM_Utils_Array::key('Manual', $paymentProcessorType);
    if (empty($paymentProcessorTypeId)) {
        return civicrm_api3_create_error(ts("There is no 'Manual' payment processor type"));
    }
    $config =& CRM_Core_Config::singleton();
    $debug = false;
    $dtCurrentDay = date("Ymd", mktime(0, 0, 0, date("m"), date("d"), date("Y")));
    $dtCurrentDayStart = $dtCurrentDay . "000000";
    $dtCurrentDayEnd = $dtCurrentDay . "235959";
    // Select the recurring payment, where current date is equal to next scheduled date
    $sql = "\n      SELECT ccr.* FROM civicrm_contribution_recur ccr\n      INNER JOIN civicrm_payment_processor cpp ON (cpp.id = ccr.payment_processor_id AND cpp.is_test = 0)\n      INNER JOIN civicrm_payment_processor_type cppt ON cppt.id = cpp.payment_processor_type_id\n      WHERE cppt.name = 'Manual'\n      AND (ccr.end_date IS NULL OR ccr.end_date > NOW())\n      AND ccr.next_sched_contribution_date <= %2\n  ";
    $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($dtCurrentDayStart, 'String'), 2 => array($dtCurrentDayEnd, 'String')));
    $counter = 0;
    $errors = 0;
    $output = array();
    while ($dao->fetch()) {
        $hash = md5(uniqid(rand(), true));
        require_once 'api/api.php';
        $result = civicrm_api('contribution', 'create', array('version' => 3, 'contact_id' => $dao->contact_id, 'receive_date' => date("YmdHis"), 'total_amount' => $dao->amount, 'payment_instrument_id' => $dao->payment_instrument_id, 'trxn_id' => $hash, 'invoice_id' => $hash, 'source' => "Offline Recurring Contribution", 'contribution_status_id' => 2, 'contribution_type_id' => 1, 'contribution_recur_id' => $dao->id));
        if ($result['is_error']) {
            $output[] = $result['error_message'];
            ++$errors;
            ++$counter;
            continue;
        } else {
            $contribution = reset($result['values']);
            $contribution_id = $contribution['id'];
            $output[] = ts('Created contribution record for contact id %1', array(1 => $dao->contact_id));
        }
        //$mem_end_date = $member_dao->end_date;
        $temp_date = strtotime($dao->next_sched_contribution_date);
        $next_collectionDate = strtotime("+{$dao->frequency_interval} {$dao->frequency_unit}", $temp_date);
        $next_collectionDate = date('YmdHis', $next_collectionDate);
        $sql = "\n        UPDATE civicrm_contribution_recur \n           SET next_sched_contribution_date = %1 \n         WHERE id = %2\n    ";
        CRM_Core_DAO::executeQuery($sql, array(1 => array($next_collectionDate, 'String'), 2 => array($dao->id, 'Integer')));
        $result = civicrm_api('activity', 'create', array('version' => 3, 'activity_type_id' => 6, 'source_record_id' => $contribution_id, 'source_contact_id' => $dao->contact_id, 'assignee_contact_id' => $dao->contact_id, 'subject' => "Offline Recurring Contribution - " . $dao->amount, 'status_id' => 2, 'activity_date_time' => date("YmdHis")));
        if ($result['is_error']) {
            $output[] = ts('An error occurred while creating activity record for contact id %1: %2', array(1 => $dao->contact_id, 2 => $result['error_message']));
            ++$errors;
        } else {
            $output[] = ts('Created activity record for contact id %1', array(1 => $dao->contact_id));
        }
        ++$counter;
    }
    // If errors ..
    if ($errors) {
        return civicrm_api3_create_error(ts("Completed, but with %1 errors. %2 records processed.", array(1 => $errors, 2 => $counter)) . "<br />" . implode("<br />", $output));
    }
    // If no errors and records processed ..
    if ($counter) {
        return civicrm_api3_create_success(ts('%1 contribution record(s) were processed.', array(1 => $counter)) . "<br />" . implode("<br />", $output));
    }
    // No records processed
    return civicrm_api3_create_success(ts('No contribution records were processed.'));
}