function uc_paypal_ec_review in Ubercart 6.2
Same name and namespace in other branches
- 5 payment/uc_paypal/uc_paypal.module \uc_paypal_ec_review()
- 7.3 payment/uc_paypal/uc_paypal.pages.inc \uc_paypal_ec_review()
1 string reference to 'uc_paypal_ec_review'
- uc_paypal_menu in payment/
uc_paypal/ uc_paypal.module - Implements hook_menu().
File
- payment/
uc_paypal/ uc_paypal.pages.inc, line 190 - Paypal administration menu items.
Code
function uc_paypal_ec_review() {
if (!isset($_SESSION['TOKEN']) || ($order = uc_order_load($_SESSION['cart_order'])) == FALSE) {
unset($_SESSION['cart_order']);
unset($_SESSION['have_details']);
unset($_SESSION['TOKEN'], $_SESSION['PAYERID']);
drupal_set_message(t('An error has occurred in your PayPal payment. Please review your cart and try again.'));
drupal_goto('cart');
}
if ($_SESSION['have_details'][$order->order_id] !== TRUE) {
$nvp_request = array(
'METHOD' => 'GetExpressCheckoutDetails',
'TOKEN' => $_SESSION['TOKEN'],
);
$nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp'));
$_SESSION['PAYERID'] = $nvp_response['PAYERID'];
$shipname = check_plain($nvp_response['SHIPTONAME']);
if (strpos($shipname, ' ') > 0) {
$order->delivery_first_name = substr($shipname, 0, strrpos(trim($shipname), ' '));
$order->delivery_last_name = substr($shipname, strrpos(trim($shipname), ' ') + 1);
}
else {
$order->delivery_first_name = $shipname;
$order->delivery_last_name = '';
}
$country_id = db_result(db_query("SELECT country_id FROM {uc_countries} WHERE country_iso_code_2 = '%s'", $nvp_response['SHIPTOCOUNTRYCODE']));
$zone = $nvp_response['SHIPTOSTATE'];
$zone_id = 0;
if (!empty($country_id) && !empty($zone)) {
$zone_id = db_result(db_query("SELECT zone_id FROM {uc_zones} WHERE zone_country_id = '%s' AND (zone_code = '%s' OR zone_name = '%s')", $country_id, $zone, $zone));
}
$order->delivery_street1 = check_plain($nvp_response['SHIPTOSTREET']);
$order->delivery_street2 = check_plain($nvp_response['SHIPTOSTREET2']);
$order->delivery_city = check_plain($nvp_response['SHIPTOCITY']);
$order->delivery_zone = !empty($zone_id) ? $zone_id : 0;
$order->delivery_postal_code = check_plain($nvp_response['SHIPTOZIP']);
$order->delivery_country = !empty($country_id) ? $country_id : 840;
$order->billing_first_name = check_plain($nvp_response['FIRSTNAME']);
$order->billing_last_name = check_plain($nvp_response['LASTNAME']);
$order->billing_street1 = check_plain($nvp_response['EMAIL']);
if (empty($order->primary_email)) {
$order->primary_email = $nvp_response['EMAIL'];
}
$order->payment_method = 'paypal_ec';
uc_order_save($order);
$_SESSION['have_details'][$order->order_id] = TRUE;
}
$output = t("Your order is almost complete! Please fill in the following details and click 'Continue checkout' to finalize the purchase.");
$output .= drupal_get_form('uc_paypal_ec_review_form', $order);
return $output;
}