Commit c2582796 authored by jenlampton's avatar jenlampton

Update payment nonce with Transaction ID at submission time.

parent 6b620a1a
......@@ -218,7 +218,6 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
$last_key = $flipped_map['x_last_name'];
// Get keys for other submitted fields.
$field_keys = _authorizenetwebform_get_data_keys($flipped_map);
//extract($field_keys);
// Establish data to send to AuthNet.
if ($field_values[$type_key] == 'one-time') {
......@@ -352,19 +351,20 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
);
}
// Add everything else as UuserFields (API only supports One-Time transactions)
// Add everything else as UserFields (API only supports One-Time transactions)
if ($field_values[$type_key] == 'one-time' && !empty($field_keys)) {
$data[$top_key][$second_key]['userFields'] = array();
$data[$top_key][$second_key]['userFields']['userField'] = array();
$count = 1;
foreach ($field_keys as $remaining_key) {
foreach ($field_keys as $rkey => $remaining_key) {
// Optionally add additional custom fields, if they have values.
if (!empty($field_values[$field_keys[$remaining_key]])) {
$data[$top_key][$second_key]['userFields']['userField'][] = array(
'name' => $remaining_key,
'value' => $field_values[$field_keys[$remaining_key]],
);
unset($field_keys[$rkey]);
}
if ($count >= 20) { // API is limited to 20 items.
break;
......@@ -404,14 +404,48 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
$text .= ' ' . t('Your subscription ID is @id', array('@id' => $id));
}
drupal_set_message($text);
// Extracn the response info we need for our records.
$response_info = $response_array['transactionResponse'];
//dpm($response_info);
$response_code_options = array(
'1' => 'Approved',
'2' => 'Declined',
'3' => 'Error',
'4' => 'Held for Review',
);
$response_code = $code_options[$response_info['responseCode']];
$response_id = $response_info['transId'];
$response_hash = $response_info['transHash'];
$response_cc_safe = $response_info['accountNumber'];
// Log data to watchdog based on the response.
$message = 'Transaction !code. Transaction ID: !id. Transaction Hash: !hash. Credit card: !cc';
$variables = array(
'!code' => $response_code,
'!id' => $response_id,
'!hash' => $response_hash,
'!cc' => $response_cc_safe,
);
watchdog('authorizenetwebform', $message, $variables, WATCHDOG_NOTICE);
// Get Transaction ID Component ID: webform field => component ID.
$node = node_load($nid);
$component_ids = _authorizenetwebform_get_component_ids($node);
$trans_cid = $component_ids[$flipped_map['x_trans_id']];
// Update the webform submission Transaction ID.
$form_state['values']['submitted'][$trans_cid] = $response_id;
}
elseif ($response_array['messages']['resultCode'] == 'Error') {
foreach ($response_array['messages']['message'] as $info) {
$code = $info['code'];
$text = $info['text'];
$variables = array('@code' => $code, '@message' => $text);
watchdog('authorizenetwebform', 'Error @code from Authorize.net: @message',
array('@code' => $code, '@message' => $text));
$variables, WATCHDOG_ERROR);
drupal_set_message($code . ': ' . $text, 'error');
form_set_error(NULL, $code . ': ' . $text);
......@@ -425,8 +459,9 @@ function authorizenetwebform_webform_client_form_submit($form, &$form_state) {
$info = reset();
$code = $info['code'];
$text = $info['text'];
$variables = array('@code' => $code, '@message' => $text);
watchdog('authorizenetwebform', 'Error @code from Authorize.net: @message',
array('@code' => $code, '@message' => $text));
$variables, WATCHDOG_WARNING);
drupal_set_message($code . ': ' . $text, 'warning');
......@@ -678,3 +713,21 @@ function _authorizenetwebform_get_data_keys($flipped_map) {
return $keys;
}
/**
* Get webform components ids keyed by form key.
*
* @param stdClass $node
* The webform node
*
* @return Array
* form_key => cid
*/
function _authorizenetwebform_get_component_ids($node) {
$component_ids = array();
if (!empty($node->webform)) {
foreach ($node->webform['components'] as $component) {
$component_ids[$component['form_key']] = $component['cid'];
}
}
return $component_ids;
}
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