You are here

function uc_paypal_ec_submit_form_submit in Ubercart 5

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

File

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

Code

function uc_paypal_ec_submit_form_submit($form_id, $form_values) {
  if ($form_values['op'] == t('Back')) {
    unset($_SESSION['TOKEN'], $_SESSION['PAYERID']);
    return;
  }
  $order = uc_order_load($_SESSION['cart_order']);
  list($desc, $subtotal) = _uc_paypal_product_details($order->products);
  $shipping = 0;
  if (is_array($order->line_items)) {
    foreach ($order->line_items as $item) {
      if ($item['type'] == 'shipping') {
        $shipping += $item['amount'];
      }
    }
  }
  $tax = 0;
  if (module_exists('uc_taxes')) {
    foreach (uc_taxes_calculate($order) as $tax_item) {
      $tax += $tax_item['amount'];
    }
  }
  $subtotal = $order->order_total - $tax - $shipping;
  $country = uc_get_country_data(array(
    'country_id' => $order->billing_country,
  ));
  if ($country === FALSE) {
    $country = array(
      0 => array(
        'country_iso_code_2' => 'US',
      ),
    );
  }
  $nvp_request = array(
    'METHOD' => 'DoExpressCheckoutPayment',
    'TOKEN' => $_SESSION['TOKEN'],
    'PAYMENTACTION' => variable_get('uc_paypal_wpp_payment_action', 'Sale'),
    'PAYERID' => $_SESSION['PAYERID'],
    'AMT' => uc_currency_format($order->order_total, FALSE, FALSE, '.'),
    'DESC' => substr($desc, 0, 127),
    'INVNUM' => $order->order_id . '-' . time(),
    'BUTTONSOURCE' => 'Ubercart_ShoppingCart_EC_US',
    'NOTIFYURL' => url('uc_paypal/ipn/' . $order->order_id, NULL, NULL, TRUE),
    'ITEMAMT' => uc_currency_format($subtotal, FALSE, FALSE, '.'),
    'SHIPPINGAMT' => uc_currency_format($shipping, FALSE, FALSE, '.'),
    'TAXAMT' => uc_currency_format($tax, FALSE, FALSE, '.'),
    'CURRENCYCODE' => variable_get('uc_paypal_wpp_currency', 'USD'),
  );
  $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp'));
  unset($_SESSION['TOKEN'], $_SESSION['PAYERID']);
  $_SESSION['do_complete'] = TRUE;
  drupal_goto('cart/checkout/complete');
}