/** * {@inheritdoc} */ public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state) { $options = array(); $methods = PaymentMethod::loadMultiple(); uasort($methods, 'Drupal\\uc_payment\\Entity\\PaymentMethod::sort'); foreach ($methods as $method) { $options[$method->id()] = $method->label(); } $form['payment_method'] = array('#type' => 'select', '#title' => $this->t('Payment method'), '#default_value' => $order->getPaymentMethodId(), '#options' => $options, '#ajax' => array('callback' => array($this, 'ajaxCallback'), 'progress' => array('type' => 'throbber'), 'wrapper' => 'payment-details')); $form['payment_details'] = array('#tree' => TRUE, '#prefix' => '<div id="payment-details">', '#suffix' => '</div>'); $method = $form_state->getValue('payment_method') ?: $order->getPaymentMethodId(); if ($method && ($details = PaymentMethod::load($method)->getPlugin()->orderEditDetails($order))) { if (is_array($details)) { $form['payment_details'] += $details; } else { $form['payment_details']['#markup'] = $details; } } 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 = $this->currentUser(); if ($payments !== FALSE) { foreach ($payments as $payment) { $form['payments'][$payment->receipt_id]['received'] = array('#markup' => \Drupal::service('date.formatter')->format($payment->received, 'short')); $form['payments'][$payment->receipt_id]['user'] = array('#theme' => 'uc_uid', '#uid' => $payment->uid); $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 == '' ? '-' : $payment->comment); if ($account->hasPermission('delete payments')) { $form['payments'][$payment->receipt_id]['action'] = array('#type' => 'operations', '#links' => array('delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_payments.delete', ['uc_order' => $this->order->id(), 'payment' => $payment->receipt_id])))); } else { $form['payments'][$payment->receipt_id]['action'] = array('#markup' => ''); } } } $form['balance'] = array('#type' => 'item', '#title' => $this->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' => '-'); $options = array(); foreach (PaymentMethod::loadMultiple() as $method) { $options[$method->id()] = $method->label(); } $form['payments']['new']['method'] = array('#type' => 'select', '#title' => $this->t('Method'), '#title_display' => 'invisible', '#options' => $options, '#default_value' => $this->order->getPaymentMethodId()); $form['payments']['new']['amount'] = array('#type' => 'textfield', '#title' => $this->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; }
/** * Get the payment url * * @param OrderInterface $order * @return string url */ public function getPaymentURL(OrderInterface $order) { $icepay_config = \Drupal::config("uc_icepay.settings"); $country = $icepay_config->get("country"); $language = $icepay_config->get("language"); $merchant_id = $icepay_config->get("merchant_id"); $secret_code = $icepay_config->get("secret_code"); $protocol = $icepay_config->get("https_protocol"); $paymentObj = new \Icepay_PaymentObject(); $paymentObj->setOrderID($order->id() . date('is'))->setReference($order->id())->setAmount(intval($order->getTotal() * 100))->setCurrency($order->getCurrency())->setCountry($country)->setLanguage($language); $payment_plugin_id = IcepayApi::getPaymentPluginId($order->getPaymentMethodId()); $payment_method = IcepayApi::paymentPluginToIcepayPaymentMethod($payment_plugin_id); $paymentObj->setPaymentMethod($payment_method); if (isset($order->payment_details['ideal_issuer'])) { $paymentObj->setIssuer($order->payment_details['ideal_issuer']); } $basicmode = \Icepay_Basicmode::getInstance(); $basicmode->setMerchantID($merchant_id)->setSecretCode($secret_code)->validatePayment($paymentObj); $protocol = $protocol == true ? 'https' : 'http'; $basicmode->setProtocol($protocol); return $basicmode->getURL(); }
/** * Returns an instance of the payment method plugin for a specific order. * * @param \Drupal\uc_order\OrderInterface $order * The order from which the plugin should be instantiated. * * @return \Drupal\uc_payment\PaymentMethodPluginInterface * A fully configured plugin instance. */ public function createFromOrder(OrderInterface $order) { return PaymentMethod::load($order->getPaymentMethodId())->getPlugin(); }
/** * Returns the payment method entity for a specific order. * * @param \Drupal\uc_order\OrderInterface $order * The order from which the payment method should be loaded. * * @return static|null * The entity object or NULL if there is no valid payment method. */ public static function loadFromOrder(OrderInterface $order) { if ($method = $order->getPaymentMethodId()) { return static::load($method); } return NULL; }
/** * Returns an instance of the payment method plugin for a specific order. * * @param \Drupal\uc_order\OrderInterface $order * The order from which the plugin should be instantiated. * * @return \Drupal\uc_payment\PaymentMethodPluginInterface * A fully configured plugin instance. */ public function createFromOrder(OrderInterface $order) { return $this->createInstance($order->getPaymentMethodId()); }
/** * {@inheritdoc} */ public function orderView(OrderInterface $order) { $build = array(); // Add the hidden span for the CC details if possible. $account = \Drupal::currentUser(); if ($account->hasPermission('view cc details')) { $rows = array(); if (!empty($order->payment_details['cc_type'])) { $rows[] = $this->t('Card type') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_type']); } if (!empty($order->payment_details['cc_owner'])) { $rows[] = $this->t('Card owner') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_owner']); } if (!empty($order->payment_details['cc_number'])) { $rows[] = $this->t('Card number') . ': ' . uc_credit_display_number($order->payment_details['cc_number']); } if (!empty($order->payment_details['cc_start_month']) && !empty($order->payment_details['cc_start_year'])) { $rows[] = $this->t('Start date') . ': ' . $order->payment_details['cc_start_month'] . '/' . $order->payment_details['cc_start_year']; } if (!empty($order->payment_details['cc_exp_month']) && !empty($order->payment_details['cc_exp_year'])) { $rows[] = $this->t('Expiration') . ': ' . $order->payment_details['cc_exp_month'] . '/' . $order->payment_details['cc_exp_year']; } if (!empty($order->payment_details['cc_issue'])) { $rows[] = $this->t('Issue number') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_issue']); } if (!empty($order->payment_details['cc_bank'])) { $rows[] = $this->t('Issuing bank') . ': ' . SafeMarkup::checkPlain($order->payment_details['cc_bank']); } $build['cc_info'] = array('#markup' => implode('<br />', $rows) . '<br />'); } // Add the form to process the card if applicable. if ($account->hasPermission('process credit cards')) { $build['terminal'] = ['#type' => 'link', '#title' => $this->t('Process card'), '#url' => Url::fromRoute('uc_credit.terminal', ['uc_order' => $order->id(), 'uc_payment_method' => $order->getPaymentMethodId()])]; } return $build; }