protected function generateTax($amount = 1)
 {
     // Create a tax rate of Salex Type.
     $this->createDummyTaxRate(array('' => ''));
     $taxed = array();
     // Login with normal user.
     $this->drupalLogin($this->normal_user);
     for ($i = 0; $i < $amount; $i++) {
         // Create a dummy order in cart status.
         $order = $this->createDummyOrder($this->normal_user->uid);
         // Get the checkout url and navigate to it.
         $links = commerce_line_item_summary_links();
         // Checkout order
         $this->drupalPost($links['checkout']['href'], array('customer_profile_billing[commerce_customer_address][und][0][name_line]' => $this->randomName(), 'customer_profile_billing[commerce_customer_address][und][0][thoroughfare]' => $this->randomName(), 'customer_profile_billing[commerce_customer_address][und][0][locality]' => $this->randomName()), t('Continue to next step'));
         $this->drupalPost(NULL, array('commerce_payment[payment_details][name]' => $this->randomName()), t('Continue to next step'));
         $orders = commerce_order_load_multiple(array($order->order_id), array(), TRUE);
         $order = reset($orders);
         foreach ($order->commerce_order_total[LANGUAGE_NONE][0]['data']['components'] as $component) {
             if (!empty($component['price']['data']['tax_rate'])) {
                 if (empty($taxed[$component['price']['data']['tax_rate']['name']])) {
                     $taxed[$component['price']['data']['tax_rate']['name']] = 0;
                 }
                 $taxed[$component['price']['data']['tax_rate']['name']] += $component['price']['amount'] / 100;
             }
         }
         $this->orders[] = $order;
     }
     return $taxed;
 }
Esempio n. 2
0
/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function devis_form_commerce_stripe_cardonfile_create_form_alter(&$form, &$form_state, $form_id)
{
    global $user;
    $orders = commerce_order_load_multiple(array(), array('uid' => $user->uid, 'status' => 'checkout_checkout'));
    $stored_cards = commerce_cardonfile_load_multiple_by_uid($user->uid);
    // If it's the first card to add.
    if ($orders || !$stored_cards) {
        $form['credit_card']['cardonfile_instance_default']['#default_value'] = 1;
        $form['credit_card']['cardonfile_instance_default']['#access'] = FALSE;
    } else {
        $form['submit']['#suffix'] = l(t('Cancel'), 'user/' . $user->uid . '/cards', array('attributes' => array('class' => array('cancel_url'))));
    }
    if ($orders) {
        drupal_set_message(t(variable_get('trois_devis_third_step_message')), 'warning');
    }
    drupal_set_title(t('Add credit card'));
    $theme_path = drupal_get_path('theme', variable_get('theme_default', NULL));
    $form['#attached']['js'][] = $theme_path . '/js/easydropdown/jquery.easydropdown.min.js';
    $form['#attached']['css'][] = $theme_path . '/css/easydropdown.css';
    $form['errors']['#weight'] = -10;
    $form['card-info'] = array('#type' => 'fieldset', '#title' => t('Information'), '#weight' => 0);
    // Add images for powered by stripe and accepted payments.
    $image_options = array('path' => '/sites/default/files/pictures/stripe_powered.png', 'alt' => t('Powered by Stripe'), 'title' => t('Powered by Stripe'), 'width' => '180px', 'attributes' => array('class' => 'img-cc', 'id' => 'stripe_powered'));
    $image = theme('image', $image_options);
    $form['credit_card']['image_1'] = array('#markup' => $image, '#prefix' => '<div class="payment-images-wrapper"><div class="payment-img">', '#suffix' => '</div>', '#weight' => -999);
    $image_options = array('path' => '/sites/default/files/pictures/payment_cards.png', 'alt' => t('Accepted payments methods'), 'title' => t('Accepted payments methods'), 'width' => '180px', 'attributes' => array('class' => 'img-cc', 'id' => 'payment_cards'));
    $image = theme('image', $image_options);
    $form['credit_card']['image_2'] = array('#markup' => $image, '#prefix' => '<div class="payment-img">', '#suffix' => '</div></div>', '#weight' => -997);
    // Change labels.
    $form['credit_card']['owner']['#title'] = t('Credit card owner');
    $form['credit_card']['number']['#title'] = t('Credit card number');
    $form['credit_card']['exp_month']['#title'] = t('Expiration date');
    $form['credit_card']['exp_month']['#title_display'] = 'invisible';
    $form['credit_card']['exp_month']['#prefix'] .= '<label for="edit-credit-card-exp-month">' . t('Expiration date') . '</label>';
    $form['credit_card']['exp_month']['#prefix'] .= '<div class="dropdown-expiration-date">';
    $form['credit_card']['exp_month']['#suffix'] = '</div>' . $form['credit_card']['exp_month']['#suffix'];
    $form['credit_card']['exp_month']['#attributes']['class'][] = 'dropdown';
    $form['credit_card']['exp_year']['#prefix'] = '<div class="dropdown-expiration-date">';
    $form['credit_card']['exp_year']['#suffix'] = '</div>' . $form['credit_card']['exp_year']['#suffix'];
    $form['credit_card']['exp_year']['#attributes']['class'][] = 'dropdown';
    $form['submit']['#value'] = t('Validate');
    $form['submit']['#attributes']['class'] = array('card_submit');
    $form['submit']['#weight'] = 10;
    $form['credit_card']['cardonfile_instance_default']['#title'] = t('Set as your default credit card');
    $form['address']['country']['#access'] = FALSE;
    $form['address']['country']['#weight'] = 100;
    // This is now here as is not working on commerce stripe.
    $form['address']['country']['#attributes']['class'][] = 'dropdown';
    $form['address']['street_block']['thoroughfare']['#title'] = t('Address');
    $form['address']['street_block']['premise']['#attributes']['style'] = 'display: none;';
    $form['address']['street_block']['premise']['#title_display'] = 'invisible';
    $form['card-info']['credit_card'] = $form['credit_card'];
    $form['card-info']['address'] = $form['address'];
    unset($form['credit_card'], $form['address']);
    // Pass the default card to the next step in case there is one.
    $form['#submit'][] = 'devis_form_commerce_stripe_cardonfile_create_form_submit';
    $stored_cards = commerce_cardonfile_load_multiple_by_uid($user->uid, NULL, TRUE);
    if ($stored_cards) {
        $default_card = current($stored_cards);
        $form_state['default_card'] = $default_card;
    }
}