コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $credit_config = $this->config('uc_credit.settings');
     $account = $this->currentUser();
     if (!$account->hasPermission('administer credit cards')) {
         $form['notice'] = array('#markup' => '<div>' . $this->t('You must have access to <b>administer credit cards</b> to adjust these settings.') . '</div>');
         return $form;
     }
     $gateways = _uc_payment_gateway_list('credit');
     if (!count($gateways)) {
         $form['notice'] = array('#markup' => '<div>' . $this->t('Please enable a credit card gateway module for your chosen payment provider.') . '</div>');
         // @todo - This is commented out to test this form without a gateway
         //      return $form;
     }
     $form['uc_credit'] = array('#type' => 'vertical_tabs', '#attached' => array('library' => array('uc_credit/uc_credit.scripts')));
     $form['cc_basic'] = array('#type' => 'details', '#title' => $this->t('Basic settings'), '#group' => 'uc_credit');
     $options = array();
     foreach ($gateways as $id => $gateway) {
         $options[$id] = $gateway['title'];
     }
     $form['cc_basic']['uc_payment_credit_gateway'] = array('#type' => 'radios', '#title' => $this->t('Default gateway'), '#options' => $options, '#default_value' => uc_credit_default_gateway());
     $form['cc_basic']['uc_credit_validate_numbers'] = array('#type' => 'checkbox', '#title' => $this->t('Validate credit card numbers at checkout.'), '#description' => $this->t('Invalid card numbers will show an error message to the user so they can correct it.'), '#default_value' => $credit_config->get('validate_numbers'));
     // Form elements that deal specifically with card number security.
     $form['cc_security'] = array('#type' => 'details', '#title' => $this->t('Security settings'), '#description' => $this->t('You are responsible for the security of your website, including the protection of credit card numbers.  Please be aware that choosing some settings in this section may decrease the security of credit card data on your website and increase your liability for damages in the case of fraud.'), '#group' => 'uc_credit');
     $form['cc_security']['uc_credit_encryption_path'] = array('#type' => 'textfield', '#title' => $this->t('Encryption key directory'), '#description' => $this->t('The card type, expiration date and last four digits of the card number are encrypted and stored temporarily while the customer is in the process of checking out.<br /><b>You must enable encryption</b> by following the <a href=":url">encryption instructions</a> in order to accept credit card payments.<br />In short, you must enter the path of a directory outside of your document root where the encryption key may be stored.<br />Relative paths will be resolved relative to the Drupal installation directory.<br />Once this directory is set, you should not change it.', [':url' => 'http://drupal.org/node/1309226']), '#default_value' => uc_credit_encryption_key() ? $credit_config->get('encryption_path') : $this->t('Not configured.'));
     // Form elements that deal with the type of data requested at checkout.
     $form['cc_fields'] = array('#type' => 'details', '#title' => $this->t('Credit card fields'), '#description' => $this->t('Specify what information to collect from customers in addition to the card number.'), '#group' => 'uc_credit', '#weight' => 10);
     $form['cc_fields']['uc_credit_cvv_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable CVV text field on checkout form.'), '#description' => $this->t('The CVV is an added security measure on credit cards. On Visa, Mastercard, and Discover cards it is a three digit number, and on AmEx cards it is a four digit number. If your credit card processor or payment gateway requires this information, you should enable this feature here.'), '#default_value' => $credit_config->get('cvv_enabled'));
     $form['cc_fields']['uc_credit_owner_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable card owner text field on checkout form.'), '#default_value' => $credit_config->get('owner_enabled'));
     $form['cc_fields']['uc_credit_start_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable card start date on checkout form.'), '#default_value' => $credit_config->get('start_enabled'));
     $form['cc_fields']['uc_credit_issue_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable card issue number text field on checkout form.'), '#default_value' => $credit_config->get('issue_enabled'));
     $form['cc_fields']['uc_credit_bank_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable issuing bank text field on checkout form.'), '#default_value' => $credit_config->get('bank_enabled'));
     $form['cc_fields']['uc_credit_type_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable card type selection on checkout form.'), '#description' => $this->t('If enabled, specify in the textarea below which card options to populate the select box with.'), '#default_value' => $credit_config->get('type_enabled'));
     $form['cc_fields']['uc_credit_accepted_types'] = array('#type' => 'textarea', '#title' => $this->t('Card type select box options'), '#description' => $this->t('Enter one card type per line. These fields will populate the card type select box if it is enabled.'), '#default_value' => implode("\r\n", $credit_config->get('accepted_types')));
     // Form elements that deal with card types accepted.
     $form['cc_fields']['cc_types'] = array('#type' => 'details', '#title' => $this->t('Card types'), '#description' => $this->t('Use the checkboxes to specify which card types you accept for payment. Selected card types will show their icons in the payment method selection list and be used for card number validation.'));
     $form['cc_fields']['cc_types']['uc_credit_visa'] = array('#type' => 'checkbox', '#title' => $this->t('Visa'), '#default_value' => $credit_config->get('visa'));
     $form['cc_fields']['cc_types']['uc_credit_mastercard'] = array('#type' => 'checkbox', '#title' => $this->t('Mastercard'), '#default_value' => $credit_config->get('mastercard'));
     $form['cc_fields']['cc_types']['uc_credit_discover'] = array('#type' => 'checkbox', '#title' => $this->t('Discover'), '#default_value' => $credit_config->get('discover'));
     $form['cc_fields']['cc_types']['uc_credit_amex'] = array('#type' => 'checkbox', '#title' => $this->t('American Express'), '#default_value' => $credit_config->get('amex'));
     // Form elements that deal with credit card messages to customers.
     $form['cc_messages'] = array('#type' => 'details', '#title' => $this->t('Customer messages'), '#description' => $this->t('Here you can alter messages displayed to customers using credit cards.'), '#group' => 'uc_credit', '#weight' => 10);
     $form['cc_messages']['uc_credit_policy'] = array('#type' => 'textarea', '#title' => $this->t('Credit card payment policy'), '#description' => $this->t('Instructions for customers on the checkout page above the credit card fields.'), '#default_value' => $credit_config->get('policy'), '#rows' => 3);
     $form['cc_messages']['uc_credit_fail_message'] = array('#type' => 'textarea', '#title' => $this->t('Card processing failure message'), '#description' => $this->t('Error message displayed to customers when an attempted payment fails at checkout.'), '#default_value' => $credit_config->get('fail_message'));
     $txn_types = array(UC_CREDIT_AUTH_ONLY => $this->t('Authorization only'), UC_CREDIT_AUTH_CAPTURE => $this->t('Authorize and capture immediately'), UC_CREDIT_REFERENCE_SET => $this->t('Set a reference only'));
     foreach ($gateways as $id => $gateway) {
         $form['gateways'][$id] = array('#type' => 'details', '#title' => SafeMarkup::checkPlain($gateway['title']), '#group' => 'uc_credit', '#weight' => 5);
         $form['gateways'][$id]['uc_pg_' . $id . '_enabled'] = array('#type' => 'checkbox', '#title' => $this->t('Enable this payment gateway for use.'), '#default_value' => $credit_config->get('uc_pg_' . $id . '_enabled'), '#weight' => -10);
         // Get the transaction types associated with this gateway.
         $gateway_types = uc_credit_gateway_txn_types($id);
         $options = array();
         foreach ($txn_types as $type => $title) {
             if (in_array($type, $gateway_types)) {
                 $options[$type] = $title;
             }
         }
         $form['gateways'][$id]['uc_pg_' . $id . '_cc_txn_type'] = array('#type' => 'radios', '#title' => $this->t('Default credit transaction type'), '#description' => $this->t('Only available transaction types are listed. The default will be used unless an administrator chooses otherwise through the terminal.'), '#options' => $options, '#default_value' => $credit_config->get('uc_pg_' . $id . '_cc_txn_type'), '#weight' => -5);
         if (isset($gateway['settings']) && function_exists($gateway['settings'])) {
             $gateway_settings = $gateway['settings'](array(), $form_state);
             if (is_array($gateway_settings)) {
                 $form['gateways'][$id] += $gateway_settings;
             }
         }
     }
     if (empty($_POST) && !uc_credit_encryption_key()) {
         drupal_set_message($this->t('Credit card security settings must be configured in the security settings tab.'), 'warning');
     }
     return $form;
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL)
 {
     $this->order = $uc_order;
     // Get the transaction types available to our default gateway.
     $types = uc_credit_gateway_txn_types(uc_credit_default_gateway());
     $balance = uc_payment_balance($this->order);
     $form['order_total'] = array('#markup' => '<div><strong>' . $this->t('Order total: @total', array('@total' => uc_currency_format($this->order->getTotal()))) . '</strong></div>');
     $form['balance'] = array('#markup' => '<div><strong>' . $this->t('Balance: @balance', array('@balance' => uc_currency_format($balance))) . '</strong></div>');
     // Let the administrator set the amount to charge.
     $form['amount'] = array('#type' => 'uc_price', '#title' => $this->t('Charge Amount'), '#default_value' => $balance > 0 ? uc_currency_format($balance, FALSE, FALSE, '.') : 0);
     // Build a credit card form.
     $form['specify_card'] = array('#type' => 'fieldset', '#title' => $this->t('Credit card details'), '#description' => $this->t('Use the available buttons in this fieldset to process with the specified card details.'));
     $form['specify_card']['cc_data'] = array('#tree' => TRUE, '#prefix' => '<div class="payment-details-credit clearfix">', '#suffix' => '</div>');
     $form['specify_card']['cc_data'] += uc_payment_method_credit_form(array(), $form_state, $this->order);
     unset($form['specify_card']['cc_data']['cc_policy']);
     $form['specify_card']['actions'] = array('#type' => 'actions');
     // If available, let the card be charged now.
     if (in_array(UC_CREDIT_AUTH_CAPTURE, $types)) {
         $form['specify_card']['actions']['charge_card'] = array('#type' => 'submit', '#value' => $this->t('Charge amount'));
     }
     // If available, let the amount be authorized.
     if (in_array(UC_CREDIT_AUTH_ONLY, $types)) {
         $form['specify_card']['actions']['authorize_card'] = array('#type' => 'submit', '#value' => $this->t('Authorize amount only'));
     }
     // If available, create a reference at the gateway.
     if (in_array(UC_CREDIT_REFERENCE_SET, $types)) {
         $form['specify_card']['actions']['reference_set'] = array('#type' => 'submit', '#value' => $this->t('Set a reference only'));
     }
     // If available, create a reference at the gateway.
     if (in_array(UC_CREDIT_CREDIT, $types)) {
         $form['specify_card']['actions']['credit_card'] = array('#type' => 'submit', '#value' => $this->t('Credit amount to this card'));
     }
     // Find any uncaptured authorizations.
     $options = array();
     if (isset($this->order->data->cc_txns['authorizations'])) {
         foreach ($this->order->data->cc_txns['authorizations'] as $auth_id => $data) {
             if (empty($data['captured'])) {
                 $options[$auth_id] = $this->t('@auth_id - @date - @amount authorized', array('@auth_id' => strtoupper($auth_id), '@date' => \Drupal::service('date.formatter')->format($data['authorized'], 'short'), '@amount' => uc_currency_format($data['amount'])));
             }
         }
     }
     // If any authorizations existed...
     if (!empty($options)) {
         // Display a fieldset with the authorizations and available action buttons.
         $form['authorizations'] = array('#type' => 'fieldset', '#title' => $this->t('Prior authorizations'), '#description' => $this->t('Use the available buttons in this fieldset to select and act on a prior authorization. The charge amount specified above will be captured against the authorization listed below.  Only one capture is possible per authorization, and a capture for more than the amount of the authorization may result in additional fees to you.'));
         $form['authorizations']['select_auth'] = array('#type' => 'radios', '#title' => $this->t('Select authorization'), '#options' => $options);
         $form['authorizations']['actions'] = array('#type' => 'actions');
         // If available, capture a prior authorization.
         if (in_array(UC_CREDIT_PRIOR_AUTH_CAPTURE, $types)) {
             $form['authorizations']['actions']['auth_capture'] = array('#type' => 'submit', '#value' => $this->t('Capture amount to this authorization'));
         }
         // If available, void a prior authorization.
         if (in_array(UC_CREDIT_VOID, $types)) {
             $form['authorizations']['actions']['auth_void'] = array('#type' => 'submit', '#value' => $this->t('Void authorization'));
         }
         // Collapse this fieldset if no actions are available.
         if (!isset($form['authorizations']['actions']['auth_capture']) && !isset($form['authorizations']['actions']['auth_void'])) {
             $form['authorizations']['#type'] = 'details';
         }
     }
     // Find any uncaptured authorizations.
     $options = array();
     // Log a reference to the order for testing.
     // $this->order->data = uc_credit_log_reference($this->order->id(), substr(md5(REQUEST_TIME), 0, 16), '4111111111111111');
     if (isset($this->order->data->cc_txns['references'])) {
         foreach ($this->order->data->cc_txns['references'] as $ref_id => $data) {
             $options[$ref_id] = $this->t('@ref_id - @date - (Last 4) @card', array('@ref_id' => strtoupper($ref_id), '@date' => \Drupal::service('date.formatter')->format($data['created'], 'short'), '@card' => $data['card']));
         }
     }
     // If any references existed...
     if (!empty($options)) {
         // Display a fieldset with the authorizations and available action buttons.
         $form['references'] = array('#type' => 'fieldset', '#title' => $this->t('Customer references'), '#description' => $this->t('Use the available buttons in this fieldset to select and act on a customer reference.'));
         $form['references']['select_ref'] = array('#type' => 'radios', '#title' => $this->t('Select references'), '#options' => $options);
         $form['references']['actions'] = array('#type' => 'actions');
         // If available, capture a prior references.
         if (in_array(UC_CREDIT_REFERENCE_TXN, $types)) {
             $form['references']['actions']['ref_capture'] = array('#type' => 'submit', '#value' => $this->t('Charge amount to this reference'));
         }
         // If available, remove a previously stored reference.
         if (in_array(UC_CREDIT_REFERENCE_REMOVE, $types)) {
             $form['references']['actions']['ref_remove'] = array('#type' => 'submit', '#value' => $this->t('Remove reference'));
         }
         // If available, remove a previously stored reference.
         if (in_array(UC_CREDIT_REFERENCE_CREDIT, $types)) {
             $form['references']['actions']['ref_credit'] = array('#type' => 'submit', '#value' => $this->t('Credit amount to this reference'));
         }
         // Collapse this fieldset if no actions are available.
         if (!isset($form['references']['actions']['ref_capture']) && !isset($form['references']['actions']['ref_remove']) && !isset($form['references']['actions']['ref_credit'])) {
             $form['references']['#type'] = 'details';
         }
     }
     $form['#attached']['library'][] = 'uc_payment/uc_payment.styles';
     return $form;
 }