function __construct($options)
 {
     $this->type = isset($options['type']) ? $options['type'] : 'process';
     $method = $options['method'];
     $iats_domain = $options['iats_domain'];
     switch ($this->type) {
         case 'report':
             $this->_wsdl_url = 'https://' . $iats_domain . self::iATS_URL_REPORTLINK;
             break;
         case 'customer':
             $this->_wsdl_url = 'https://' . $iats_domain . self::iATS_URL_CUSTOMERLINK;
             break;
         case 'process':
         default:
             $this->_wsdl_url = 'https://' . $iats_domain . self::iATS_URL_PROCESSLINK;
             if ($method == 'cc') {
                 /* as suggested by iATS, though not necessary I believe */
                 $this->_tag_order = array('agentCode', 'password', 'customerIPAddress', 'invoiceNum', 'creditCardNum', 'ccNum', 'creditCardExpiry', 'ccExp', 'firstName', 'lastName', 'address', 'city', 'state', 'zipCode', 'cvv2', 'total', 'comment');
             }
             break;
     }
     // TODO: check that the method is allowed!
     $this->method = $this->methodInfo($this->type, $method);
     // initialize the request array
     $this->request = array();
     // name space url
     $this->_wsdl_url_ns = 'https://www.iatspayments.com/NetGate/';
     $this->options = $options;
     $this->options['log'] = _iats_civicrm_domain_info('userFrameworkLogging') && function_exists('watchdog');
     $this->options['debug'] = _iats_civicrm_domain_info('debug');
     // check for valid currencies with domain/method combinations
     if (isset($options['currencyID'])) {
         $valid = FALSE;
         switch ($iats_domain) {
             case 'www.iatspayments.com':
                 if (in_array($options['currencyID'], array('USD', 'CAD'))) {
                     $valid = TRUE;
                 }
                 break;
             case 'www.uk.iatspayments.com':
                 if ('cc' == substr($method, 0, 2)) {
                     if (in_array($options['currencyID'], array('AUD', 'USD', 'EUR', 'GBP', 'IEE', 'CHF', 'HKD', 'JPY', 'SGD', 'MXN'))) {
                         $valid = TRUE;
                     }
                 } elseif ('direct_debit' == substr($method, 0, 12)) {
                     if (in_array($options['currencyID'], array('GBP'))) {
                         $valid = TRUE;
                     }
                 }
                 break;
         }
         if (!$valid) {
             // TODO how about a nicer error here!
             die('Invalid currency selection: ' . $options['currencyID'] . ' for domain ' . $iats_domain);
         }
     }
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
function iats_ukdd_form_customize($form)
{
    /* uk direct debits have to start 16 days after the initial request is made */
    if (!$form->elementExists('is_recur')) {
        // todo generate an error on the page
        return;
    }
    define('IATS_UKDD_START_DELAY', 16 * 24 * 60 * 60);
    /* for batch efficiencies, restrict to a specific set of days of the month, less than 28 */
    $start_days = array('1', '15');
    // you can change these if you're sensible and careful
    $start_dates = array();
    // actual date options
    $start_date = time() + IATS_UKDD_START_DELAY;
    for ($j = 0; $j < count($start_days); $j++) {
        $i = 0;
        // so I don't get into an infinite loop somehow ..
        while ($i++ < 60 && !in_array($dp['mday'], $start_days)) {
            $start_date += 24 * 60 * 60;
            $dp = getdate($start_date);
        }
        $start_dates[date('Y-m-d', $start_date)] = strftime('%B %e, %Y', $start_date);
        $start_date += 24 * 60 * 60;
        $dp = getdate($start_date);
    }
    $service_user_number = $form->_paymentProcessor['signature'];
    $payee = _iats_civicrm_domain_info('name');
    $phone = _iats_civicrm_domain_info('domain_phone');
    $email = _iats_civicrm_domain_info('domain_email');
    $form->addRule('is_recur', ts('You can only use this form to make recurring contributions.'), 'required');
    /* declaration checkbox at the top */
    $form->addElement('checkbox', 'payer_validate_declaration', ts('I wish to start a Direct Debit'));
    $form->addElement('static', 'payer_validate_contact', ts(''), ts('Organization: %1, Phone: %2, Email: %3', array('%1' => $payee, '%2' => $phone['phone'], '%3' => $email)));
    $form->addElement('select', 'payer_validate_start_date', ts('Date of first collection'), $start_dates);
    $form->addRule('payer_validate_declaration', ts('%1 is a required field.', array(1 => ts('The Declaration'))), 'required');
    $form->addRule('installments', ts('%1 is a required field.', array(1 => ts('Number of installments'))), 'required');
    /* customization of existing elements */
    $element = $form->getElement('account_holder');
    $element->setLabel(ts('Account Holder Name'));
    $form->addRule('account_holder', ts('%1 is a required field.', array(1 => ts('Name of Account Holder'))), 'required');
    $element = $form->getElement('bank_account_number');
    $element->setLabel(ts('Account Number'));
    $form->addRule('bank_account_number', ts('%1 is a required field.', array(1 => ts('Account Number'))), 'required');
    $element = $form->getElement('bank_identification_number');
    $element->setLabel(ts('Sort Code'));
    $form->addRule('bank_identification_number', ts('%1 is a required field.', array(1 => ts('Sort Code'))), 'required');
    /* new payer validation elements */
    $form->addElement('textarea', 'payer_validate_address', ts('Name and full postal address of your Bank or Building Society'), array('rows' => '6', 'columns' => '30'));
    $form->addElement('text', 'payer_validate_service_user_number', ts('Service User Number'));
    $form->addElement('text', 'payer_validate_reference', ts('Reference'), array());
    $form->addElement('text', 'payer_validate_date', ts('Today\'s Date'), array());
    // date on which the validation happens, reference
    $form->addElement('static', 'payer_validate_instruction', ts('Instruction to your Bank or Building Society'), ts('Please pay %1 Direct Debits from the account detailed in this instruction subject to the safeguards assured by the Direct Debit Guarantee. I understand that this instruction may remain with TestingTest and, if so, details will be passed electronically to my Bank / Building Society.', array('%1' => "<strong>{$payee}</strong>")));
    // $form->addRule('bank_name', ts('%1 is a required field.', array(1 => ts('Bank Name'))), 'required');
    //$form->addRule('bank_account_type', ts('%1 is a required field.', array(1 => ts('Account type'))), 'required');
    /* only allow recurring contributions, set date */
    $form->setDefaults(array('is_recur' => 1, 'payer_validate_date' => date('F j, Y'), 'payer_validate_start_date' => current(array_keys($start_dates)), 'payer_validate_service_user_number' => $service_user_number));
    // make recurring contrib default to true
    CRM_Core_Region::instance('billing-block')->add(array('template' => 'CRM/iATS/BillingBlockDirectDebitExtra_GBP.tpl'));
}