Пример #1
0
 /**
  * Creates an order for the specified user, and redirects to the edit page.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user to create the order for.
  */
 public function createForUser(UserInterface $user)
 {
     $order = Order::create(['uid' => $user->id(), 'order_status' => uc_order_state_default('post_checkout')]);
     $order->save();
     uc_order_comment_save($order->id(), \Drupal::currentUser()->id(), $this->t('Order created by the administration.'), 'admin');
     return $this->redirect('entity.uc_order.edit_form', ['uc_order' => $order->id()]);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function create(array $values = array())
 {
     $store_config = \Drupal::config('uc_store.settings');
     // Set the primary email address.
     if (empty($values['primary_email']) && !empty($values['uid'])) {
         if ($account = User::load($values['uid'])) {
             $values['primary_email'] = $account->mail;
         }
     }
     // Set the default order status.
     if (empty($values['order_status'])) {
         $values['order_status'] = uc_order_state_default('in_checkout');
     }
     // Set the default currency.
     if (empty($values['currency'])) {
         $values['currency'] = $store_config->get('currency.code');
     }
     // Set the default country codes.
     if (empty($values['billing_country'])) {
         $values['billing_country'] = $store_config->get('address.country');
     }
     if (empty($values['delivery_country'])) {
         $values['delivery_country'] = $store_config->get('address.country');
     }
     // Set the created time to now.
     if (empty($values['created'])) {
         $values['created'] = REQUEST_TIME;
     }
     return parent::create($values);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function completeSale($order, $login = FALSE)
 {
     // Empty that cart...
     $this->emptyCart();
     // Force the order to load from the DB instead of the entity cache.
     // @todo Remove this once uc_payment_enter() can modify order objects?
     // @todo Should we be overwriting $order with this newly-loaded db_order?
     $db_order = \Drupal::entityTypeManager()->getStorage('uc_order')->loadUnchanged($order->id());
     $order->data = $db_order->data;
     // Ensure that user creation and triggers are only run once.
     if (empty($order->data->complete_sale)) {
         $this->completeSaleAccount($order);
         // Move an order's status from "In checkout" to "Pending".
         if ($order->getStateId() == 'in_checkout') {
             $order->setStatusId(uc_order_state_default('post_checkout'));
         }
         $order->save();
         // Invoke the checkout complete trigger and hook.
         $account = $order->getOwner();
         \Drupal::moduleHandler()->invokeAll('uc_checkout_complete', array($order, $account));
         // rules_invoke_event('uc_checkout_complete', $order);
     }
     $type = $order->data->complete_sale;
     // Log in new users, if requested.
     if ($type == 'new_user' && $login && $this->currentUser->isAnonymous()) {
         $type = 'new_user_logged_in';
         user_login_finalize($order->getOwner());
     }
     $message = \Drupal::config('uc_cart.messages')->get($type);
     $message = \Drupal::token()->replace($message, array('uc_order' => $order));
     $variables['!new_username'] = isset($order->data->new_user_name) ? $order->data->new_user_name : '';
     $variables['!new_password'] = isset($order->password) ? $order->password : t('Your password');
     $message = strtr($message, $variables);
     return array('#theme' => 'uc_cart_complete_sale', '#message' => array('#markup' => $message), '#order' => $order);
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order, array $form, FormStateInterface $form_state)
 {
     db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
     if (!$form_state->isValueEmpty(['panes', 'comments', 'comments'])) {
         uc_order_comment_save($order->id(), 0, $form_state->getValue(['panes', 'comments', 'comments']), 'order', uc_order_state_default('post_checkout'), TRUE);
     }
     return TRUE;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $states = uc_order_state_options_list();
     $statuses = OrderStatus::loadMultiple();
     $form['order_states'] = array('#type' => 'details', '#title' => t('Order states'));
     $form['order_states']['order_states'] = array('#type' => 'table', '#header' => array(t('State'), t('Default order status')));
     foreach ($states as $state_id => $title) {
         $form['order_states']['order_states'][$state_id]['title'] = array('#markup' => $title);
         // Create the select box for specifying a default status per order state.
         $options = array();
         foreach ($statuses as $status) {
             if ($state_id == $status->getState()) {
                 $options[$status->id()] = $status->getName();
             }
         }
         if (empty($options)) {
             $form['order_states']['order_states'][$state_id]['default'] = array('#markup' => t('- N/A -'));
         } else {
             $form['order_states']['order_states'][$state_id]['default'] = array('#type' => 'select', '#options' => $options, '#default_value' => uc_order_state_default($state_id));
         }
     }
     $form['order_statuses'] = array('#type' => 'details', '#title' => t('Order statuses'), '#open' => TRUE);
     $form['order_statuses']['order_statuses'] = array('#type' => 'table', '#header' => array(t('ID'), t('Title'), t('List position'), t('State'), t('Remove')));
     foreach ($statuses as $status) {
         $form['order_statuses']['order_statuses'][$status->id()]['id'] = array('#markup' => $status->id());
         $form['order_statuses']['order_statuses'][$status->id()]['name'] = array('#type' => 'textfield', '#default_value' => $status->getName(), '#size' => 32, '#required' => TRUE);
         $form['order_statuses']['order_statuses'][$status->id()]['weight'] = array('#type' => 'weight', '#delta' => 20, '#default_value' => $status->getWeight());
         if ($status->isLocked()) {
             $form['order_statuses']['order_statuses'][$status->id()]['state'] = array('#markup' => $states[$status->getState()]);
         } else {
             $form['order_statuses']['order_statuses'][$status->id()]['state'] = array('#type' => 'select', '#options' => $states, '#default_value' => $status->getState());
             $form['order_statuses']['order_statuses'][$status->id()]['remove'] = array('#type' => 'checkbox');
         }
     }
     return parent::buildForm($form, $form_state);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     switch ($form_state->getValue('customer_type')) {
         case 'search':
             $uid = $form_state->getValue(['customer', 'uid']);
             break;
         case 'create':
             // Create new account.
             $email = trim($form_state->getValue(['customer', 'email']));
             $fields = array('name' => uc_store_email_to_username($email), 'mail' => $email, 'pass' => user_password(), 'status' => $this->config('uc_cart.settings')->get('new_customer_status_active') ? 1 : 0);
             $account = \Drupal\user\Entity\User::create($fields);
             $account->save();
             $uid = $account->id();
             if ($form_state->getValue(['customer', 'sendmail'])) {
                 // Manually set the password so it appears in the e-mail.
                 $account->password = $fields['pass'];
                 \Drupal::service('plugin.manager.mail')->mail('user', 'register_admin_created', $email, uc_store_mail_recipient_langcode($email), array('account' => $account), uc_store_email_from());
                 drupal_set_message(t('A welcome message has been e-mailed to the new user.'));
             }
             break;
         default:
             $uid = 0;
     }
     $order = \Drupal\uc_order\Entity\Order::create(array('uid' => $uid, 'order_status' => uc_order_state_default('post_checkout')));
     $order->save();
     uc_order_comment_save($order->id(), \Drupal::currentUser()->id(), t('Order created by the administration.'), 'admin');
     $form_state->setRedirect('entity.uc_order.edit_form', ['uc_order' => $order->id()]);
 }
Пример #7
0
/**
 * Builds and proceses a pane defined by hook_uc_checkout_pane().
 *
 * @param $op
 *   The operation the pane is performing. Possible values are "view",
 *   "process", "review", and "settings".
 * @param $order
 *   The order being viewed or edited.
 * @param $form
 *   The order's edit form. NULL for non-edit ops.
 * @param &$form_state
 *   The form state array of the edit form. NULL for non-edit ops.
 *
 * @return
 *   Varies according to the value of $op:
 *   - view: An array with two keys, "contents" and an optional "description".
 *     "contents" is a form array to collect the checkout data for the pane. The
 *     description provides help text for the pane as a whole.
 *   - process: A boolean indicating that checkout should continue. During this
 *     op, $order should be modified with the values in
 *     $form_state['values']['panes'][PANE_ID].
 *   - review: An array containing review sections. A review section contains
 *     "title" and "data" keys which have HTML to be displayed on the checkout
 *     review page.
 *   - settings: A settings form which can be used with system_settings_form().
 */
function uc_checkout_pane_callback($op, $order, $form = NULL, &$form_state = NULL)
{
    // uc_checkout_pane_comments()
    switch ($op) {
        case 'view':
            $description = t('Use this area for special instructions or questions regarding your order.');
            if (!empty($order->order_id)) {
                $default = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $order->order_id))->fetchField();
            } else {
                $default = NULL;
            }
            $contents['comments'] = array('#type' => 'textarea', '#title' => t('Order comments'), '#default_value' => $default);
            return array('description' => $description, 'contents' => $contents);
        case 'process':
            if ($form_state['values']['panes']['comments']['comments']) {
                db_delete('uc_order_comments')->condition('order_id', $order->order_id)->execute();
                uc_order_comment_save($order->order_id, 0, $form_state['values']['panes']['comments']['comments'], 'order', uc_order_state_default('post_checkout'), TRUE);
            }
            return TRUE;
        case 'review':
            $review = NULL;
            $result = db_query("SELECT message FROM {uc_order_comments} WHERE order_id = :id", array(':id' => $order->order_id));
            if ($comment = $result->fetchObject()) {
                $review[] = array('title' => t('Comment'), 'data' => check_plain($comment->message));
            }
            return $review;
    }
}
function uc_ideal_payment_api_statreq_call($arg1, $arg2)
{
    $transaction_id = $_GET['trxid'];
    $order_id = $_GET['ec'];
    //echo $transaction_id;
    /*START ThinMPI code for TransrReq*/
    require_once drupal_get_path('module', 'ideal_payment_api') . "/lib/ThinMPI.php";
    require_once drupal_get_path('module', 'ideal_payment_api') . "/lib/AcquirerStatusRequest.php";
    //Create StatusRequest
    $q_data =& new AcquirerStatusRequest();
    $transID = str_pad($transaction_id, 16, "0");
    $q_data->setTransactionID($transID);
    //Create ThinMPI instance and process request
    $rule = new ThinMPI();
    $result = $rule->ProcessRequest($q_data);
    if (!$result->isOK()) {
        //StatusRequest failed, let the consumer click to try again
        $Msg = $result->getErrorMessage();
        drupal_set_message(t('We could not verify the payment status automaticaly, we will check your payment manualy, pleas contact us regarding this. IDEAL error:')) . '<br>' . $Msg;
        drupal_goto('ideal');
    } else {
        if (!$result->isAuthenticated()) {
            //Transaction failed, inform the consumer
            drupal_set_message(t('Your IDEAL payment has been canceled by you or by the IDEAL process. Please try again or go back to select another payment method.'), 'ERROR');
            if ($order_id == $_SESSION['ideal_payment_api_order_id']) {
                //Check if orer_id is valid
                // This lets us know it's a legitimate access of the review page.
                $_SESSION['do_review'] = TRUE;
                // Ensure the cart we're looking at is the one that payment was attempted for.
                $_SESSION['cart_order'] = uc_cart_get_id();
                drupal_goto('ideal/review');
            } else {
                drupal_goto('cart');
            }
        } else {
            drupal_set_message(t('Thank you for shopping with us, your payment is processed sucessfuly'));
            $transactionID = $result->getTransactionID();
            //Here you should retrieve the order from the database, mark it as "payed"
            $order = uc_order_load($order_id);
            if ($order == FALSE) {
                //Check if order exist
                watchdog('ideal_api', t('iDeal payment completion attempted for non-existent order.'), WATCHDOG_ERROR);
                return;
            }
            //uc_order_update_status($order_id, 1);   *Uitgezet 281107 KK
            uc_order_update_status($order->order_id, uc_order_state_default('post_checkout'));
            //Todo??
            //uc_payment_enter($order_id, 'ideal_payment_api', $payment_amount, $order->uid, NULL, $comment);
            //uc_cart_complete_sale($order);
            //uc_order_comment_save($order_id, 0, t('iDeal Pro reported a payment of !amount !currency.', array('!amount' => uc_currency_format($payment_amount, FALSE), '!currency' => $payment_currency)), 'admin');
            unset($_SESSION['ideal_payment_api_order_id']);
            // This lets us know it's a legitimate access of the complete page.
            $_SESSION['do_complete'] = TRUE;
            drupal_goto('ideal/complete');
            exit;
        }
    }
}
Пример #9
0
 public function testOrderState()
 {
     $this->drupalLogin($this->adminUser);
     // Check that the default order state and status is correct.
     $this->drupalGet('admin/store/config/orders');
     $this->assertFieldByName('order_states[in_checkout][default]', 'in_checkout', 'State defaults to correct default status.');
     $this->assertEqual(uc_order_state_default('in_checkout'), 'in_checkout', 'uc_order_state_default() returns correct default status.');
     $order = $this->ucCreateOrder($this->customer);
     $this->assertEqual($order->getStateId(), 'in_checkout', 'Order has correct default state.');
     $this->assertEqual($order->getStatusId(), 'in_checkout', 'Order has correct default status.');
     // Create a custom "in checkout" order status with a lower weight.
     $this->drupalGet('admin/store/config/orders');
     $this->clickLink('Create custom order status');
     $edit = array('id' => strtolower($this->randomMachineName()), 'name' => $this->randomMachineName(), 'state' => 'in_checkout', 'weight' => -15);
     $this->drupalPostForm(NULL, $edit, 'Create');
     $this->assertEqual(uc_order_state_default('in_checkout'), $edit['id'], 'uc_order_state_default() returns lowest weight status.');
     // Set "in checkout" state to default to the new status.
     $this->drupalPostForm(NULL, array('order_states[in_checkout][default]' => $edit['id']), 'Save configuration');
     $this->assertFieldByName('order_states[in_checkout][default]', $edit['id'], 'State defaults to custom status.');
     $order = $this->ucCreateOrder($this->customer);
     $this->assertEqual($order->getStatusId(), $edit['id'], 'Order has correct custom status.');
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public static function preCreate(EntityStorageInterface $storage, array &$values)
 {
     parent::preCreate($storage, $values);
     // Set default values.
     $store_config = \Drupal::config('uc_store.settings');
     $values += ['order_status' => uc_order_state_default('in_checkout'), 'currency' => $store_config->get('currency.code'), 'billing_country' => $store_config->get('address.country'), 'delivery_country' => $store_config->get('address.country'), 'created' => REQUEST_TIME];
     // Take the primary email address from the user, if necessary.
     if (empty($values['primary_email']) && !empty($values['uid'])) {
         if ($account = User::load($values['uid'])) {
             $values['primary_email'] = $account->getEmail();
         }
     }
 }