You are here

function commerce_paypal_ec_review_pane_checkout_form_validate in Commerce PayPal 7.2

Validate handler for the Express Checkout review and confirm page.

1 string reference to 'commerce_paypal_ec_review_pane_checkout_form_validate'
commerce_paypal_ec_review_pane_checkout_form in modules/ec/includes/commerce_paypal_ec.checkout_pane.inc
Checkout pane callback: returns a pane allowing the customer to review the final details of the order and provide any final information required.

File

modules/ec/includes/commerce_paypal_ec.checkout_pane.inc, line 137
Checkout pane callback functions for the PayPal Express Checkout module.

Code

function commerce_paypal_ec_review_pane_checkout_form_validate($form, &$form_state) {
  $order = $form_state['order'];
  $form_validate = TRUE;

  // Loop through the enabled checkout panes included in this page to validate
  // and submit them.
  foreach (commerce_paypal_ec_embedded_checkout_panes() as $embedded_pane_id) {
    $embedded_pane_validate = TRUE;

    // Load the checkout pane to find its checkout pane validate callback.
    $embedded_checkout_pane = commerce_checkout_pane_load($embedded_pane_id);

    // If it has a validate callback.
    if ($callback = commerce_checkout_pane_callback($embedded_checkout_pane, 'checkout_form_validate')) {

      // Give it a chance to process the submitted data.
      $embedded_pane_validate &= $callback($form, $form_state, $embedded_checkout_pane, $order);
    }

    // Submit the pane if it validated.
    if ($embedded_pane_validate && ($callback = commerce_checkout_pane_callback($embedded_checkout_pane, 'checkout_form_submit'))) {
      $callback($form, $form_state, $embedded_checkout_pane, $order);
    }

    // A failed pane makes the form fail.
    $form_validate &= $embedded_pane_validate;
  }

  // Save the updated order object.
  commerce_order_save($order);

  // If a pane failed validation or the form state has otherwise been altered to
  // initiate a rebuild, return without moving to the next checkout page.
  if (!$form_validate || $form_state['rebuild']) {
    $form_state['rebuild'] = TRUE;
  }
}