=== modified file 'payment/uc_paypal/uc_paypal.module'
--- payment/uc_paypal/uc_paypal.module 2009-04-23 18:17:23 +0000
+++ payment/uc_paypal/uc_paypal.module 2009-05-28 18:25:54 +0000
@@ -392,48 +392,70 @@ function uc_paypal_wpp_charge($order_id,
$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();
- if ($nvp_response['ACK'] != 'Success') {
- $message = t('@type failed.
@severity: @error', array('@type' => $types[$data['txn_type']], '@severity' => $nvp_response['L_SEVERITYCODE0'], '@error' => $nvp_response['L_ERRORCODE0'] .'. '. $nvp_response['L_LONGMESSAGE0']));
- if ($data['txn_type'] != UC_CREDIT_PRIOR_AUTH_CAPTURE) {
- $message .= '
'. t('Address: @avscode', array('@avscode' => _uc_paypal_avscode_message($nvp_response['AVSCODE'])));
- if (variable_get('uc_credit_cvv_enabled', TRUE)) {
- $message .= '
'. t('CVV2: @cvvmatch', array('@cvvmatch' => _uc_paypal_cvvmatch_message($nvp_response['CVV2MATCH'])));
- }
- }
- $result = array(
- 'success' => FALSE,
- 'message' => $message,
- 'uid' => $user->uid,
- );
- }
- else {
- $message = t('@type
Success: @amount @currency', array('@type' => $types[$data['txn_type']], '@amount' => uc_price($nvp_response['AMT'], $context, array('sign' => FALSE)), '@currency' => $nvp_response['CURRENCYCODE']));
- if ($data['txn_type'] != UC_CREDIT_PRIOR_AUTH_CAPTURE) {
- $message .= '
'. t('Address: @avscode', array('@avscode' => _uc_paypal_avscode_message($nvp_response['AVSCODE'])));
- if (variable_get('uc_credit_cvv_enabled', TRUE)) {
- $message .= '
'. t('CVV2: @cvvmatch', array('@cvvmatch' => _uc_paypal_cvvmatch_message($nvp_response['CVV2MATCH'])));
+ switch ($nvp_response['ACK']) {
+ case 'SuccessWithWarning':
+ watchdog('uc_payment', '@type succeeded with a warning.'. _uc_paypal_build_error_messages($nvp_response),
+ array(
+ '@type' => $types[$data['txn_type']],
+ ),
+ WATCHDOG_WARNING,
+ l(t('view order'), 'admin/store/orders/'. $order_id)
+ );
+ // fall through
+ case 'Success':
+ $message = t('@type
Success: @amount @currency', array('@type' => $types[$data['txn_type']], '@amount' => uc_price($nvp_response['AMT'], $context, array('sign' => FALSE)), '@currency' => $nvp_response['CURRENCYCODE']));
+ if ($data['txn_type'] != UC_CREDIT_PRIOR_AUTH_CAPTURE) {
+ $message .= '
'. t('Address: @avscode', array('@avscode' => _uc_paypal_avscode_message($nvp_response['AVSCODE'])));
+ if (variable_get('uc_credit_cvv_enabled', TRUE)) {
+ $message .= '
'. t('CVV2: @cvvmatch', array('@cvvmatch' => _uc_paypal_cvvmatch_message($nvp_response['CVV2MATCH'])));
+ }
}
- }
- $result = array(
- 'success' => TRUE,
- 'comment' => t('PayPal transaction ID: @transactionid', array('@transactionid' => $nvp_response['TRANSACTIONID'])),
- 'message' => $message,
- 'data' => check_plain($nvp_response['TRANSACTIONID']),
- 'uid' => $user->uid,
- );
+ $result = array(
+ 'success' => TRUE,
+ 'comment' => t('PayPal transaction ID: @transactionid', array('@transactionid' => $nvp_response['TRANSACTIONID'])),
+ 'message' => $message,
+ 'data' => check_plain($nvp_response['TRANSACTIONID']),
+ 'uid' => $user->uid,
+ );
- // If this was an authorization only transaction...
- if ($data['txn_type'] == UC_CREDIT_AUTH_ONLY) {
- // Log the authorization to the order.
- uc_credit_log_authorization($order_id, $nvp_response['TRANSACTIONID'], $nvp_response['AMT']);
- }
- elseif ($data['txn_type'] == UC_CREDIT_PRIOR_AUTH_CAPTURE) {
- uc_credit_log_prior_auth_capture($order_id, $data['auth_id']);
- }
+ // If this was an authorization only transaction...
+ if ($data['txn_type'] == UC_CREDIT_AUTH_ONLY) {
+ // Log the authorization to the order.
+ uc_credit_log_authorization($order_id, $nvp_response['TRANSACTIONID'], $nvp_response['AMT']);
+ }
+ elseif ($data['txn_type'] == UC_CREDIT_PRIOR_AUTH_CAPTURE) {
+ uc_credit_log_prior_auth_capture($order_id, $data['auth_id']);
+ }
- // Log the IPN to the database.
- db_query("INSERT INTO {uc_payment_paypal_ipn} (order_id, txn_id, txn_type, mc_gross, status, receiver_email, payer_email, received) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', %d)",
+ // Log the IPN to the database.
+ db_query("INSERT INTO {uc_payment_paypal_ipn} (order_id, txn_id, txn_type, mc_gross, status, receiver_email, payer_email, received) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', %d)",
$order->order_id, $nvp_response['TRANSACTIONID'], 'web_accept', $amount, 'Completed', '', $order->primary_email, time());
+
+ break;
+ case 'FailureWithWarning':
+ // fall through
+ case 'Failure':
+ $message = t('@type failed.', array('@type' => $types[$data['txn_type']])) . _uc_paypal_build_error_messages($nvp_response);
+ if ($data['txn_type'] != UC_CREDIT_PRIOR_AUTH_CAPTURE) {
+ $message .= '
'. t('Address: @avscode', array('@avscode' => _uc_paypal_avscode_message($nvp_response['AVSCODE'])));
+ if (variable_get('uc_credit_cvv_enabled', TRUE)) {
+ $message .= '
'. t('CVV2: @cvvmatch', array('@cvvmatch' => _uc_paypal_cvvmatch_message($nvp_response['CVV2MATCH'])));
+ }
+ }
+ $result = array(
+ 'success' => FALSE,
+ 'message' => $message,
+ 'uid' => $user->uid,
+ );
+ break;
+ default:
+ $message = t('Unexpected acknowledgement status: @status', array('@status' => $nvp_response['ACK']));
+ $result = array(
+ 'success' => NULL,
+ 'message' => $message,
+ 'uid' => $user->uid,
+ );
+ break;
}
uc_order_comment_save($order_id, $user->uid, $message, 'admin');
@@ -446,6 +468,19 @@ function uc_paypal_wpp_charge($order_id,
return $result;
}
+/**
+ * Build error message(s) from PayPal failure responses.
+ */
+function _uc_paypal_build_error_messages($nvp_response) {
+ $code = 0;
+ $message = '';
+ while (array_key_exists('L_SEVERITYCODE'. $code, $nvp_response)) {
+ $message .= '
'. $nvp_response['L_SEVERITYCODE'. $code] .': '. $nvp_response['L_ERRORCODE'. $code] .': '. $nvp_response['L_LONGMESSAGE'. $code];
+ $code++;
+ }
+ return $message;
+}
+
// Handles the Website Payments Standard payment method.
function uc_payment_method_paypal_wps($op, &$arg1) {
switch ($op) {