You are here

function uc_paypal_ec_submit_form_submit in Ubercart 6.2

Same name and namespace in other branches
  1. 5 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()

Additional submit handler for uc_cart_checkout_review_form().

See also

uc_cart_checkout_review_form()

1 string reference to 'uc_paypal_ec_submit_form_submit'
uc_paypal_form_alter in payment/uc_paypal/uc_paypal.module
Implements hook_form_alter().

File

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

Code

function uc_paypal_ec_submit_form_submit($form, &$form_state) {
  $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',
      ),
    );
  }
  $context = array(
    'revision' => 'formatted-original',
    'type' => 'order_total',
    'subject' => array(
      'order' => $order,
    ),
  );
  $options = array(
    'sign' => FALSE,
    'thou' => FALSE,
    'dec' => '.',
  );
  $nvp_request = array(
    'METHOD' => 'DoExpressCheckoutPayment',
    'TOKEN' => $_SESSION['TOKEN'],
    'PAYMENTACTION' => variable_get('uc_pg_paypal_wpp_cc_txn_type', 'auth_capture') == 'authorize' ? 'Authorization' : 'Sale',
    'PAYERID' => $_SESSION['PAYERID'],
    'AMT' => uc_price($order->order_total, $context, $options),
    'DESC' => substr($desc, 0, 127),
    'INVNUM' => $order->order_id . '-' . time(),
    'BUTTONSOURCE' => 'Ubercart_ShoppingCart_EC_US',
    'NOTIFYURL' => url('uc_paypal/ipn/' . $order->order_id, array(
      'absolute' => TRUE,
    )),
    'ITEMAMT' => uc_price($subtotal, $context, $options),
    'SHIPPINGAMT' => uc_price($shipping, $context, $options),
    'TAXAMT' => uc_price($tax, $context, $options),
    '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;
  $form_state['redirect'] = 'cart/checkout/complete';
}