Commit b52ee2ad authored by obsidiandesign's avatar obsidiandesign

#450032 by amariotti: change the expiration date of the credit card to xx/xx...

#450032 by amariotti: change the expiration date of the credit card to xx/xx in the webform database; additionally, the 'x_card_code' is now a selectable field for mapping.
#450036 by amariotti: changed the way the component id #'s are looked up from an internal method to calling the webform function directly.  This prevents errors in mapping the field name to the numeric key in the submitted array.
New feature: the error messages from authorize.net are now used, so that it is more clear to the end user what the specific problem is with their credit card.
parent 711e6337
......@@ -37,7 +37,7 @@ Installation
<?php
require_once(drupal_get_path('module', 'authorizenetwebform') . '/authorizenetwebform.module');
$form_state = authorizenetwebform_process("validate", $form_id, $form_state);
$form_state = authorizenetwebform_process("validate", $node, $form_id, $form_state);
?>
Then, in the 'Additional Processing' box, add the following code, again removing the leading
......@@ -45,7 +45,7 @@ Installation
<?php
require_once(drupal_get_path('module', 'authorizenetwebform') . '/authorizenetwebform.module');
$form_state = authorizenetwebform_process("submit", $form_id, $form_state);
$form_state = authorizenetwebform_process("submit", $node, $form_id, $form_state);
?>
......
......@@ -226,6 +226,8 @@ function authorizenet_create_custom_field_spec($custom_fields) {
* @param $step
* Identify whether the webform is being validated ("validate") or submitted
* ("submit")
* @param $node
* The full webform object
* @param $form
* A form array
* @param $form_state
......@@ -233,7 +235,7 @@ function authorizenet_create_custom_field_spec($custom_fields) {
* @return $form_state
* A form state array
*/
function authorizenetwebform_process($step, $form, $form_state) {
function authorizenetwebform_process($step, $node, $form, $form_state) {
module_load_include('inc', 'authorizenetwebform', '/authorizenetwebform_fields');
$form_values = $form_state['values'];
......@@ -314,18 +316,12 @@ function authorizenetwebform_process($step, $form, $form_state) {
if ($response_array[2] > 1) {
watchdog('authorizenetwebform', 'Error response from Authorize.net: %resposne', array("%resposne" => "<pre>". print_r($response_array, TRUE) ."</pre>"));
//There was some type of error getting an authorization. Flag it
form_set_error('submitted][x_card_num', t('There was an error processing your credit card. Please ensure that you have entered the number and expiration date correctly. If the error persists, please try another card.'));
form_set_error('submitted][x_card_num', t('There was an error processing your credit card: %anetresponse. If the error persists, please try another card.', array("%anetresponse" => $response_array[3])));
}
if ($response_array[6] != "") {
//We have a transaction ID. Set it in the webform
$form_values['submitted_tree']['x_trans_id'] = $response_array[6];
//Figure out which key is the transaction id
foreach ($wfkeys as $keynum => $keyname) {
if ($keyname == "x_trans_id") {
$wfkeynum = $keynum;
}
}
$wfkeynum = webform_get_cid($node, 'x_trans_id', 0);
$form_values['submitted'][$wfkeynum] = $form_values['submitted_tree']['x_trans_id'];
//Not the greatest way to store the transaction id (kind of hackish), but the best we can do until #288199 is fixed.
$_SESSION['anwf_trans_id'] = $form_values['submitted_tree']['x_trans_id'];
......@@ -335,7 +331,7 @@ function authorizenetwebform_process($step, $form, $form_state) {
if ($response_array[2] > 1) {
watchdog('authorizenetwebform', 'Error response from Authorize.net: %resposne', array("%resposne" => "<pre>". print_r($response_array, TRUE) ."</pre>"));
//There was some type of error getting an authorization. Flag it
form_set_error('submitted][x_card_num', t('There was an error processing your credit card. Please ensure that you have entered the number and expiration date correctly. If the error persists, please try another card.'));
form_set_error('submitted][x_card_num', t('There was an error processing your credit card: %anetresponse. If the error persists, please try another card.', array("%anetresponse" => $response_array[3])));
}
else {
//blank out all but the last 4 CC #'s
......@@ -344,24 +340,25 @@ function authorizenetwebform_process($step, $form, $form_state) {
for ($i = 0; $i < $cclen; $i++) {
$form_values['submitted_tree']['x_card_num'][$i] = 'x';
}
//Now match it up in the submitted array
foreach ($wfkeys as $keynum => $keyname) {
if ($keyname == "x_card_num") {
$wfkeynum = $keynum;
}
}
$wfkeynum = webform_get_cid($node, 'x_card_num', 0);
$form_values['submitted'][$wfkeynum] = $form_values['submitted_tree']['x_card_num'];
//blank out the expiration date as well
$form_values['submitted_tree']['x_exp_date'] = 'xx/xx';
$wfkeynum = webform_get_cid($node, 'x_exp_date', 0);
$form_values['submitted'][$wfkeynum] = $form_values['submitted_tree']['x_exp_date'];
//blank out the security code as well - it's an optional field, so check if it's set first.
if (isset($form_values['submitted_tree']['x_card_code'])) {
$form_values['submitted_tree']['x_card_code'] = 'xxx';
$wfkeynum = webform_get_cid($node, 'x_card_code', 0);
$form_values['submitted'][$wfkeynum] = $form_values['submitted_tree']['x_card_code'];
}
if ($response_array[6] != "") {
//We have a transaction ID. Set it in the webform
$form_values['submitted_tree']['x_trans_id'] = $response_array[6];
//Figure out which key is the transaction id
foreach ($wfkeys as $keynum => $keyname) {
if ($keyname == "x_trans_id") {
$wfkeynum = $keynum;
}
}
$wfkeynum = webform_get_cid($node, 'x_trans_id', 0);
$form_values['submitted'][$wfkeynum] = $form_values['submitted_tree']['x_trans_id'];
}
}
......@@ -371,6 +368,4 @@ function authorizenetwebform_process($step, $form, $form_state) {
$form_state['values'] = $form_values;
return $form_state;
}
}
\ No newline at end of file
......@@ -23,8 +23,9 @@ function authorizenetwebform_available_fields() {
// Transaction Info
'x_amount' => 'Amount',
'x_card_num' => 'Card Number',
'x_exp_date' => 'Expiration Date (Digits Only)',
'x_card_code' => 'Card Security Code',
'x_description' => 'Transaction Description',
'x_exp_date' => 'Expiration Date (Digits Only)',
'x_trans_id' => 'Transaction ID (Must be Mapped - Hidden Field)',
//Cardholder Info
......
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