You are here

function commerce_paypal_checkout_review_pane_checkout_form_submit in Commerce PayPal 7.2

Submit handler for the PayPal Checkout review and confirm page.

1 string reference to 'commerce_paypal_checkout_review_pane_checkout_form_submit'
commerce_paypal_checkout_review_pane_checkout_form in modules/checkout/includes/commerce_paypal_checkout.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/checkout/includes/commerce_paypal_checkout.checkout_pane.inc, line 176
Checkout pane callback functions for the PayPal Checkout module.

Code

function commerce_paypal_checkout_review_pane_checkout_form_submit($form, &$form_state) {
  $order = $form_state['order'];
  $payment_method = commerce_payment_method_instance_load($order->data['payment_method']);

  // Update the order in PayPal to make sure it reflects the current state of
  // the order in Drupal.
  // If the order could not be updated in PayPal, stop here.
  if (!commerce_paypal_checkout_update_order($order, $payment_method)) {
    drupal_set_message(t('We could not complete your payment with PayPal. Please try again or contact us if the problem persists.'), 'error');
    watchdog('commerce_paypal_checkout', 'Could not update the PayPal order for order @order_number.', array(
      '@order_number' => $order->order_number,
    ), WATCHDOG_ERROR);
    return;
  }

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

    // 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);
  }
}