You are here

function commerce_paypal_ec_redirect_form in Commerce PayPal 7.2

Payment method callback: redirect form.

File

modules/ec/commerce_paypal_ec.module, line 708
Implements PayPal Express Checkout in Drupal Commerce checkout.

Code

function commerce_paypal_ec_redirect_form($form, &$form_state, $order, $payment_method) {

  // If we didn't get a valid redirect token...
  if (empty($order->data['commerce_paypal_ec']['token'])) {

    // Clear the payment related information from the data array.
    unset($order->data['payment_method']);
    unset($order->data['commerce_paypal_ec']);

    // Show an error message and go back a page.
    drupal_set_message(t('Redirect to PayPal Express Checkout failed. Please try again or contact an administrator to resolve the issue.'), 'error');
    commerce_payment_redirect_pane_previous_page($order, t('Redirect to PayPal Express Checkout failed.'));
  }
  elseif (!in_array(arg(3), array(
    'back',
    'return',
  ))) {

    // Otherwise go ahead and redirect to PayPal.
    drupal_goto(commerce_paypal_ec_checkout_url($payment_method['settings']['server'], $order->data['commerce_paypal_ec']['token']));
  }
}