You are here

function uc_paypal_ec_submit_form_submit in Ubercart 7.3

Same name and namespace in other branches
  1. 5 payment/uc_paypal/uc_paypal.module \uc_paypal_ec_submit_form_submit()
  2. 6.2 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_uc_cart_checkout_review_form_alter in payment/uc_paypal/uc_paypal.module
Implements hook_form_FORM_ID_alter() for uc_cart_checkout_review_form().

File

payment/uc_paypal/uc_paypal.module, line 752
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',
      ),
    );
  }
  $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_currency_format($order->order_total, FALSE, FALSE, '.'),
    'DESC' => substr($desc, 0, 127),
    'INVNUM' => $order->order_id . '-' . REQUEST_TIME,
    'BUTTONSOURCE' => 'Ubercart_ShoppingCart_EC_US',
    'NOTIFYURL' => url('uc_paypal/ipn/' . $order->order_id, array(
      'absolute' => 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['uc_checkout'][$_SESSION['cart_order']]['do_complete'] = TRUE;
  $form_state['redirect'] = 'cart/checkout/complete';
}