You are here

function uc_paypal_ec_form_submit in Ubercart 5

Same name and namespace in other branches
  1. 6.2 payment/uc_paypal/uc_paypal.module \uc_paypal_ec_form_submit()
  2. 7.3 payment/uc_paypal/uc_paypal.module \uc_paypal_ec_form_submit()

File

payment/uc_paypal/uc_paypal.module, line 962
Integrates various PayPal payment services and Instant Payment Notifications (IPN) with Ubercart!

Code

function uc_paypal_ec_form_submit($form_id, $form_values) {
  global $user;
  $items = uc_cart_get_contents();
  if (!is_array($items) || count($items) == 0) {
    drupal_set_message(t('You do not have any items in your shopping cart.'));
    return;
  }
  list($desc, $subtotal) = _uc_paypal_product_details($items);
  $order = uc_order_new($user->uid);
  $nvp_request = array(
    'METHOD' => 'SetExpressCheckout',
    'RETURNURL' => url('cart/echeckout/review', NULL, NULL, TRUE),
    'CANCELURL' => url('uc_paypal/wps/cancel', NULL, NULL, TRUE),
    'AMT' => uc_currency_format($subtotal, FALSE, FALSE, '.'),
    'CURRENCYCODE' => variable_get('uc_paypal_wpp_currency', 'USD'),
    'PAYMENTACTION' => variable_get('uc_paypal_wpp_payment_action', 'Sale'),
    'DESC' => substr($desc, 0, 127),
    'INVNUM' => $order->order_id . '-' . time(),
    'REQCONFIRMSHIPPING' => variable_get('uc_paypal_ec_rqconfirmed_addr', 0),
    'BUTTONSOURCE' => 'Ubercart_ShoppingCart_EC_US',
    'NOTIFYURL' => url('uc_paypal/ipn/' . $order->order_id, NULL, NULL, TRUE),
  );
  $order->products = $items;
  uc_order_save($order);
  $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp'));
  $_SESSION['cart_order'] = $order->order_id;
  $_SESSION['TOKEN'] = $nvp_response['TOKEN'];
  if (strpos(variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp'), 'sandbox') > 0) {
    $sandbox = 'sandbox.';
  }
  header('Location: https://www.' . $sandbox . 'paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $_SESSION['TOKEN']);
  exit;
}