--- uc_paypal/uc_paypal.module.orig 2010-08-12 03:52:20.000000000 +1000 +++ uc_paypal/uc_paypal.module 2011-10-07 13:08:02.000000000 +1100 @@ -404,9 +404,29 @@ } } + // + // DEBUG. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_wpp_charge: calling uc_paypal_api_request with:
@debug
', array('@debug' => _print_r_to_string($nvp_request))); + } + + // + // send request. + // $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); $types = uc_credit_transaction_types(); + // + // DEBUG. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_wpp_charge: response from uc_paypal_api_request:
@debug
', array('@debug' => _print_r_to_string($nvp_response))); + } + + // + // process response. + // switch ($nvp_response['ACK']) { case 'SuccessWithWarning': watchdog('uc_payment', '@type succeeded with a warning.!paypal_message', @@ -691,13 +711,37 @@ unset($nvp_request['ADDROVERRIDE']); } + // + // DEBUG: request. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_checkout: calling uc_paypal_api_request with:
@debug
', array('@debug' => _print_r_to_string($nvp_request))); + } + + // + // send request. + // $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); + // + // DEBUG: response. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_checkout: response from uc_paypal_api_request:
@debug
', array('@debug' => _print_r_to_string($nvp_response))); + } + + + // + // error + // if ($nvp_response['ACK'] != 'Success') { drupal_set_message(t('Error message from PayPal:
@message', array('@message' => $nvp_response['L_LONGMESSAGE0'])), 'error'); drupal_goto('cart/checkout'); } + // + // success + // $_SESSION['TOKEN'] = $nvp_response['TOKEN']; if (strpos(variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp'), 'sandbox') > 0) { @@ -769,8 +813,44 @@ $order->products = $items; uc_order_save($order); + // + // DEBUG: request. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_form_submit: calling uc_paypal_api_request with:
@debug
', array('@debug' => _print_r_to_string($nvp_request))); + } + + // + // send request. + // $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); + // + // DEBUG: response. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_form_submit: response from uc_paypal_api_request:
@debug
', array('@debug' => _print_r_to_string($nvp_response))); + } + + // + // unknown error. + // + if (!$nvp_response || !isset($nvp_response['ACK'])) { + drupal_set_message(t('Error:
uc_paypal_ec_form_submit: uc_paypal_api_request() returned unknown response'), 'error'); + drupal_goto('cart/checkout'); + } + + // + // failure. + // + if ($nvp_response['ACK'] != 'Success') { + drupal_set_message(t('Error message from PayPal:
@message', array('@message' => $nvp_response['L_LONGMESSAGE0'])), 'error'); + drupal_goto('cart/checkout'); + } + + // + // success. + // $_SESSION['cart_order'] = $order->order_id; $_SESSION['TOKEN'] = $nvp_response['TOKEN']; @@ -839,11 +919,50 @@ 'CURRENCYCODE' => variable_get('uc_paypal_wpp_currency', 'USD'), ); + // + // DEBUG: request. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_submit_form_submit: calling uc_paypal_api_request with:
@debug
', array('@debug' => _print_r_to_string($nvp_request))); + } + + // + // send request. + // $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); + // + // DEBUG: response. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_submit_form_submit: response from uc_paypal_api_request:
@debug
', array('@debug' => _print_r_to_string($nvp_response))); + } + + // + // unknown error. + // + if (!$nvp_response || !isset($nvp_response['ACK'])) { + drupal_set_message(t('Error:
uc_paypal_ec_submit_form_submit: uc_paypal_api_request() returned unknown response'), 'error'); + drupal_goto('cart/checkout'); + } + + // + // failure. + // + if ($nvp_response['ACK'] != 'Success') { + watchdog('uc_paypal', 'Request of IPN transaction FAILED: @message', array('@message' => $nvp_response['L_LONGMESSAGE0'])); + drupal_set_message(t('Error message from PayPal:
@message', array('@message' => $nvp_response['L_LONGMESSAGE0'])), 'error'); + drupal_goto('cart/checkout'); + } + + // + // success. + // unset($_SESSION['TOKEN'], $_SESSION['PAYERID']); $_SESSION['do_complete'] = TRUE; + watchdog('uc_paypal', 'Request of IPN transaction succeeded.'); + $form_state['redirect'] = 'cart/checkout/complete'; } @@ -1242,3 +1361,12 @@ function _uc_paypal_currency_array() { return drupal_map_assoc(array('AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'MYR', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD')); } + +function _print_r_to_string($object) { + ob_start(); + print_r($object); + $string = ob_get_contents(); + ob_end_clean(); + + return $string; +} --- uc_paypal/uc_paypal.pages.inc.orig 2011-10-07 13:18:21.000000000 +1100 +++ uc_paypal/uc_paypal.pages.inc 2011-10-07 12:53:55.000000000 +1100 @@ -171,8 +171,33 @@ 'TOKEN' => $_SESSION['TOKEN'], ); + // + // DEBUG. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_review_redirect: calling uc_paypal_api_request with:
@debug
', array('@debug' => _print_r_to_string($nvp_request))); + } + + // + // send request. + // $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); + // + // DEBUG. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_review_redirect: response from uc_paypal_api_request:
@debug
', array('@debug' => _print_r_to_string($nvp_response))); + } + + // + // error + // + if ($nvp_response['ACK'] != 'Success') { + drupal_set_message(t('Error message from PayPal:
@message', array('@message' => $nvp_response['L_LONGMESSAGE0'])), 'error'); + drupal_goto('cart/checkout'); + } + $_SESSION['PAYERID'] = $nvp_response['PAYERID']; drupal_goto('cart/checkout/review'); @@ -194,8 +219,36 @@ 'TOKEN' => $_SESSION['TOKEN'], ); + // + // DEBUG: request. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_review: calling uc_paypal_api_request with:
@debug
', array('@debug' => _print_r_to_string($nvp_request))); + } + + // + // send request. + // $nvp_response = uc_paypal_api_request($nvp_request, variable_get('uc_paypal_wpp_server', 'https://api-3t.sandbox.paypal.com/nvp')); + // + // DEBUG: response. + // + if (variable_get('uc_paypal_wps_debug_ipn', FALSE)) { + watchdog('uc_paypal', 'DEBUG: uc_paypal_ec_review: response from uc_paypal_api_request:
@debug
', array('@debug' => _print_r_to_string($nvp_response))); + } + + // + // error + // + if ($nvp_response['ACK'] != 'Success') { + drupal_set_message(t('Error message from PayPal:
@message', array('@message' => $nvp_response['L_LONGMESSAGE0'])), 'error'); + drupal_goto('cart/checkout'); + } + + // + // success. + // $_SESSION['PAYERID'] = $nvp_response['PAYERID']; $shipname = check_plain($nvp_response['SHIPTONAME']);