/**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL)
 {
     $balance = uc_payment_balance($uc_order);
     $form['balance'] = array('#prefix' => '<strong>' . $this->t('Order balance:') . '</strong> ', '#markup' => uc_currency_format($balance));
     $form['order_id'] = array('#type' => 'hidden', '#value' => $uc_order->id());
     $form['amount'] = array('#type' => 'uc_price', '#title' => $this->t('Check amount'), '#default_value' => $balance);
     $form['comment'] = array('#type' => 'textfield', '#title' => $this->t('Comment'), '#description' => $this->t('Any notes about the check, like type or check number.'), '#size' => 64, '#maxlength' => 256);
     $form['clear_date'] = array('#type' => 'datetime', '#title' => $this->t('Expected clear date'), '#date_date_element' => 'date', '#date_time_element' => 'none', '#default_value' => DrupalDateTime::createFromTimestamp(REQUEST_TIME));
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Receive check'));
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL)
 {
     $balance = uc_payment_balance($uc_order);
     $form['balance'] = array('#prefix' => '<strong>' . $this->t('Order balance:') . '</strong> ', '#markup' => uc_currency_format($balance));
     $form['order_id'] = array('#type' => 'hidden', '#value' => $uc_order->id());
     $form['amount'] = array('#type' => 'uc_price', '#title' => $this->t('Amount'), '#default_value' => $balance);
     $form['comment'] = array('#type' => 'textfield', '#title' => $this->t('Comment'), '#description' => $this->t('Any notes about the check, like type or check number.'), '#size' => 64, '#maxlength' => 256);
     $form['clear'] = array('#type' => 'fieldset', '#title' => $this->t('Expected clear date'), '#attributes' => array('class' => array('uc-inline-form', 'clearfix')));
     $form['clear']['clear_month'] = uc_select_month(NULL, \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'n'));
     $form['clear']['clear_day'] = uc_select_day(NULL, \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'j'));
     $form['clear']['clear_year'] = uc_select_year(NULL, \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'Y'), \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'Y'), \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'Y') + 1);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Receive check'));
     return $form;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function view(OrderInterface $order, $view_mode)
 {
     if ($view_mode != 'customer') {
         $build['balance'] = array('#markup' => $this->t('Balance: @balance', ['@balance' => uc_currency_format(uc_payment_balance($order))]));
         $account = \Drupal::currentUser();
         if ($account->hasPermission('view payments')) {
             $build['view_payments'] = array('#type' => 'link', '#prefix' => ' (', '#title' => $this->t('View'), '#url' => Url::fromRoute('uc_payments.order_payments', ['uc_order' => $order->id()]), '#suffix' => ')');
         }
         $method = \Drupal::service('plugin.manager.uc_payment.method')->createFromOrder($order);
         $build['method'] = array('#markup' => $this->t('Method: @payment_method', ['@payment_method' => $method->cartReviewTitle()]), '#prefix' => '<br />');
         $method_output = $method->orderView($order);
         if (!empty($method_output)) {
             $build['output'] = $method_output + array('#prefix' => '<br />');
         }
     } else {
         $method = \Drupal::service('plugin.manager.uc_payment.method')->createFromOrder($order);
         $build['method'] = array('#markup' => $this->t('Method: @payment_method', ['@payment_method' => $method->cartReviewTitle()]));
         $method_output = $method->customerView($order);
         if (!empty($method_output)) {
             $build['output'] = $method_output + array('#prefix' => '<br />');
         }
     }
     return $build;
 }
 /**
  * {@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;
 }