/** * {@inheritdoc} */ public function review(OrderInterface $order) { $line_items = $order->getDisplayLineItems(); foreach ($line_items as $line_item) { $review[] = array('title' => $line_item['title'], 'data' => uc_currency_format($line_item['amount'])); } $method = $this->paymentMethodManager->createFromOrder($order); $review[] = array('border' => 'top', 'title' => $this->t('Paying by'), 'data' => $method->cartReviewTitle()); $result = $method->cartReview($order); if (is_array($result)) { $review = array_merge($review, $result); } return $review; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $options = array_map(function ($definition) { return $definition['name']; }, array_filter($this->paymentMethodManager->getDefinitions(), function ($definition) { return !$definition['no_ui']; })); if ($options) { uasort($options, 'strnatcasecmp'); $form['add'] = array('#type' => 'details', '#title' => $this->t('Add payment method'), '#open' => TRUE, '#attributes' => array('class' => array('container-inline'))); $form['add']['payment_method_type'] = array('#type' => 'select', '#title' => $this->t('Type'), '#empty_option' => $this->t('- Choose -'), '#options' => $options); $form['add']['submit'] = array('#type' => 'submit', '#value' => $this->t('Add payment method'), '#validate' => array('::validateAddPaymentMethod'), '#submit' => array('::submitAddPaymentMethod'), '#limit_validation_errors' => array(array('payment_method_type'))); } $form = parent::buildForm($form, $form_state); $form[$this->entitiesKey]['#empty'] = $this->t('No payment methods have been configured.'); $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save configuration'), '#button_type' => 'primary'); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, OrderInterface $uc_order = NULL) { $this->order = $uc_order; $form['#attached']['library'][] = 'uc_payment/uc_payment.styles'; $total = $this->order->getTotal(); $payments = uc_payment_load_payments($this->order->id()); $form['order_total'] = array('#type' => 'item', '#title' => $this->t('Order total'), '#theme' => 'uc_price', '#price' => $total); $form['payments'] = array('#type' => 'table', '#tree' => TRUE, '#header' => array($this->t('Received'), $this->t('User'), $this->t('Method'), $this->t('Amount'), $this->t('Balance'), $this->t('Comment'), $this->t('Action')), '#weight' => 10); $account = \Drupal::currentUser(); if ($payments !== FALSE) { foreach ($payments as $payment) { $form['payments'][$payment->receipt_id]['received'] = array('#markup' => \Drupal::service('date.formatter')->format($payment->received, 'short')); $markup = array('#theme' => 'uc_uid', '#uid' => $payment->uid); $form['payments'][$payment->receipt_id]['user'] = array('#markup' => drupal_render($markup)); $form['payments'][$payment->receipt_id]['method'] = array('#markup' => $payment->method == '' ? $this->t('Unknown') : $payment->method); $form['payments'][$payment->receipt_id]['amount'] = array('#theme' => 'uc_price', '#price' => $payment->amount); $total -= $payment->amount; $form['payments'][$payment->receipt_id]['balance'] = array('#theme' => 'uc_price', '#price' => $total); $form['payments'][$payment->receipt_id]['comment'] = array('#markup' => $payment->comment == '' ? '-' : Xss::filterAdmin($payment->comment)); if ($account->hasPermission('delete payments')) { $action_value = $this->l($this->t('Delete'), new Url('uc_payments.delete', ['uc_order' => $this->order->id(), 'payment' => $payment->receipt_id])); } else { $action_value = '-'; } $form['payments'][$payment->receipt_id]['action'] = array('#markup' => $action_value); } } $form['balance'] = array('#type' => 'item', '#title' => t('Current balance'), '#theme' => 'uc_price', '#price' => $total); if ($account->hasPermission('manual payments')) { $form['payments']['new']['received'] = array('#type' => 'date', '#default_value' => array('month' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'n'), 'day' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'j'), 'year' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', 'Y'))); $form['payments']['new']['user'] = array('#markup' => '-'); $form['payments']['new']['method'] = array('#type' => 'select', '#title' => t('Method'), '#title_display' => 'invisible', '#options' => $this->paymentMethodManager->listOptions()); $form['payments']['new']['amount'] = array('#type' => 'textfield', '#title' => t('Amount'), '#title_display' => 'invisible', '#size' => 6); $form['payments']['new']['balance'] = array('#markup' => '-'); $form['payments']['new']['comment'] = array('#type' => 'textfield', '#title' => $this->t('Comment'), '#title_display' => 'invisible', '#size' => 32, '#maxlength' => 256); $form['payments']['new']['action'] = array('#type' => 'actions'); $form['payments']['new']['action']['action'] = array('#type' => 'submit', '#value' => $this->t('Enter')); } return $form; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('uc_payment.settings')->set('methods', $form_state->getValue('methods'))->save(); $this->paymentMethodManager->clearCachedDefinitions(); parent::submitForm($form, $form_state); }