You are here

function commerce_paypal_ec_review_pane_checkout_form_submit in Commerce PayPal 7.2

Submit handler for the Express Checkout review and confirm page.

1 string reference to 'commerce_paypal_ec_review_pane_checkout_form_submit'
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 177
Checkout pane callback functions for the PayPal Express Checkout module.

Code

function commerce_paypal_ec_review_pane_checkout_form_submit($form, &$form_state) {
  $order = $form_state['order'];
  $payment_method = commerce_payment_method_instance_load($order->data['payment_method']);
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  $charge = $order_wrapper->commerce_order_total
    ->value();

  // Attempt to process the payment.
  if (commerce_paypal_ec_do_payment($payment_method, $order, $charge)) {

    // Proceed to the next page if it succeeded.
    $order_status = commerce_order_status_load($order->status);
    $checkout_page = commerce_checkout_page_load($order_status['checkout_page']);
    $next_page = $checkout_page['next_page'];

    // Update the order status to the next checkout page.
    $order = commerce_order_status_update($order, 'checkout_' . $next_page, FALSE, FALSE);

    // Inform modules of checkout completion if the next page is completed.
    if ($next_page == 'complete') {
      commerce_checkout_complete($order);
    }

    // Redirect to the URL for the new checkout page.
    $form_state['redirect'] = commerce_checkout_order_uri($order);
  }
}