Commit 4f463dfa authored by jenlampton's avatar jenlampton

Catch Transaction errors even when Response is 'Ok'. Log debug info.

parent 193700a9
......@@ -399,16 +399,52 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
$response_array = json_decode(trim($post_response), TRUE);
if ($response_array['messages']['resultCode'] == 'Ok') {
$text = t('Your payment has been processed, thank you.');
if (array_key_exists('subscriptionId', $response_array)) {
$id = $response_array['subscriptionId'];
$text .= ' ' . t('Your subscription ID is @id', array('@id' => $id));
}
drupal_set_message($text);
// Extracn the response info we need for our records.
// Extrat the response info we need for our records.
$response_info = $response_array['transactionResponse'];
//dpm($response_info);
$failure = FALSE;
// Decliend || Error.
if ($response_info['responseCode'] == 2 || $response_info['responseCode'] == 3) {
$failure = TRUE;
}
else {
// Add subscription info.
if (array_key_exists('subscriptionId', $response_array)) {
$id = $response_array['subscriptionId'];
$text .= ' ' . t('Your subscription ID is @id', array('@id' => $id));
}
// Success! Set the message.
drupal_set_message('Thank you. Your payment has been processed.');
}
// Failure :( Set the form error.
if ($failure) {
if (!empty($response_info['errors'])) {
foreach ($response_info['errors'] as $info) {
$code = $info['errorCode'];
$text = $info['errorText'];
// Log to watchdog.
$variables = array('@code' => $code, '@message' => $text);
watchdog('authorizenetwebform', 'transactionResponse error @code from Authorize.net: @message',
$variables, WATCHDOG_ERROR);
// Print to screen.
$string = $text . ' (Error code: ' . $code . ')';
drupal_set_message($string, 'error');
form_set_error(NULL, $string);
// Stop the submission.
$form_state['rebuild'] = TRUE;
}
}
form_set_error(NULL, $text);
// Stop the submission.
$form_state['rebuild'] = TRUE;
}
$response_code_options = array(
'1' => 'Approved',
......@@ -421,7 +457,16 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
$response_hash = $response_info['transHash'];
$response_cc_safe = $response_info['accountNumber'];
// Log data to watchdog based on the response.
// Get Transaction ID Component ID: webform field => component ID.
$node = node_load($nid);
$webform_field_name = $flipped_map['x_trans_id'];
$component_ids = _authorizenetwebform_get_component_ids($node);
$trans_cid = $component_ids[$webform_field_name];
// Update the webform submission Transaction ID.
$form_state['values']['submitted'][$trans_cid] = $response_id;
// Always log some response data to watchdog.
$message = 'Transaction !code. Transaction ID: !id. Transaction Hash: !hash. Credit card: !cc';
$variables = array(
'!code' => $response_code,
......@@ -431,42 +476,36 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
);
watchdog('authorizenetwebform', $message, $variables, WATCHDOG_NOTICE);
// Get Transaction ID Component ID: webform field => component ID.
$node = node_load($nid);
$webform_field_name = $flipped_map['x_trans_id'];
$component_ids = _authorizenetwebform_get_component_ids($node);
$trans_cid = $component_ids[$webform_field_name];
// Record the entire response if debug mode is on.
if (variable_get('authorizenetwebform_debug', FALSE)) {
$message = 'The complete response string from Auth.Net follows:<br/> !string';
$string = '<pre>' . print_r($data, TRUE) . '</pre>';
$variables = array('!string' => $string);
watchdog('authorizenetwebform', $message, $variables, WATCHDOG_INFO);
// Update the webform submission Transaction ID.
$form_state['values']['submitted'][$trans_cid] = $response_id;
// @todo: Save this data into a more permanent location than watchdog?
// Also print response to screen.
if (module_exists('devel')) {
dpm($response_array);
}
}
}
elseif ($response_array['messages']['resultCode'] == 'Error') {
foreach ($response_array['messages']['message'] as $info) {
$code = $info['code'];
$text = $info['text'];
// Log to watchdog.
$variables = array('@code' => $code, '@message' => $text);
watchdog('authorizenetwebform', 'Error @code from Authorize.net: @message',
$variables, WATCHDOG_ERROR);
// Print to screen.
drupal_set_message($code . ': ' . $text, 'error');
form_set_error(NULL, $code . ': ' . $text);
// Stop the submission.
$form_state['rebuild'] = TRUE;
}
}
else {
foreach ($response_array['messages']['message'] as $info) {
$info = reset();
$code = $info['code'];
$text = $info['text'];
$variables = array('@code' => $code, '@message' => $text);
watchdog('authorizenetwebform', 'Error @code from Authorize.net: @message',
$variables, WATCHDOG_WARNING);
drupal_set_message($code . ': ' . $text, 'warning');
// Stop the submission.
$form_state['rebuild'] = TRUE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment