/** * 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; } }
/** * This function will process payment for pending orders * @return array|bool */ public static function runCron($order, $check_pass = FALSE) { module_load_include('inc', 'commerce_recurring', 'commerce_recurring.rules'); module_load_include('inc', 'mp_order', 'mp_order.rules'); if ($check_pass == FALSE) { $payment_method = commerce_payment_method_instance_load('commerce_stripe|commerce_payment_commerce_stripe'); $card_details = commerce_cardonfile_load_multiple_by_uid($order->uid, $payment_method['instance_id'], TRUE); foreach ($card_details as $key) { $card_data = commerce_cardonfile_load($key->card_id); $card_data->remote_id = ''; commerce_cardonfile_save($card_data); } } $card_response = commerce_cardonfile_rules_action_order_select_default_card($order); $order_total = field_get_items('commerce_order', $order, 'commerce_order_total'); $response = commerce_cardonfile_rules_action_order_charge_card($order, $order_total[0], $card_response['select_card_response']); return new Response(TRUE, $response, ""); }