/** * {@inheritdoc} */ public function orderSubmit(OrderInterface $order) { if ($order->getTotal() >= 0.01) { return array(array('pass' => FALSE, 'message' => t('We cannot process your order without payment.'))); } uc_payment_enter($order->id(), 'free_order', 0, 0, NULL, t('Checkout completed for a free order.')); }
/** * {@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(); }
/** * {@inheritdoc} */ public function orderSubmit(OrderInterface $order) { $max = $this->configuration['max_order']; if ($max > 0 && $order->getTotal() > $max) { $result[] = array('pass' => FALSE, 'message' => $this->t('Your final order total exceeds the maximum for COD payment. Please go back and select a different method of payment.')); return $result; } }
/** * {@inheritdoc} */ public function buildRedirectForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL) { $country = \Drupal::service('country_manager')->getCountry($order->getAddress('billing')->country); $data = array('sid' => $this->configuration['sid'], 'mode' => '2CO', 'card_holder_name' => Unicode::substr($order->getAddress('billing')->first_name . ' ' . $order->getAddress('billing')->last_name, 0, 128), 'street_address' => Unicode::substr($order->getAddress('billing')->street1, 0, 64), 'street_address2' => Unicode::substr($order->getAddress('billing')->street2, 0, 64), 'city' => Unicode::substr($order->getAddress('billing')->city, 0, 64), 'state' => $order->getAddress('billing')->zone, 'zip' => Unicode::substr($order->getAddress('billing')->postal_code, 0, 16), 'country' => $country ? $country->getAlpha3() : 'USA', 'email' => Unicode::substr($order->getEmail(), 0, 64), 'phone' => Unicode::substr($order->getAddress('billing')->phone, 0, 16), 'purchase_step' => 'payment-method', 'demo' => $this->configuration['demo'] ? 'Y' : 'N', 'lang' => $this->configuration['language'], 'merchant_order_id' => $order->id(), 'pay_method' => 'CC', 'x_receipt_link_url' => Url::fromRoute('uc_2checkout.complete', ['cart_id' => \Drupal::service('uc_cart.manager')->get()->getId()], ['absolute' => TRUE])->toString(), 'total' => uc_currency_format($order->getTotal(), FALSE, FALSE, '.'), 'currency_code' => $order->getCurrency(), 'cart_order_id' => $order->id()); $i = 0; foreach ($order->products as $product) { $i++; $data['li_' . $i . '_type'] = 'product'; $data['li_' . $i . '_name'] = $product->title->value; // @todo: HTML escape and limit to 128 chars $data['li_' . $i . '_quantity'] = $product->qty->value; $data['li_' . $i . '_product_id'] = $product->model->value; $data['li_' . $i . '_price'] = uc_currency_format($product->price->value, FALSE, FALSE, '.'); } if ('direct' == $this->configuration['checkout_type']) { $form['#attached']['library'][] = 'uc_2checkout/2checkout.direct'; } $form['#action'] = $this->configuration['server_url']; foreach ($data as $name => $value) { $form[$name] = array('#type' => 'hidden', '#value' => $value); } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit order')); return $form; }
/** * {@inheritdoc} */ public function orderSubmit(OrderInterface $order) { $cod_config = \Drupal::config('uc_payment_pack.cod.settings'); $max = $cod_config->get('max_order'); if ($max > 0 && $order->getTotal() > $max) { $result[] = array('pass' => FALSE, 'message' => t('Your final order total exceeds the maximum for COD payment. Please go back and select a different method of payment.')); return $result; } }