Exemplo n.º 1
0
function gffd_feed_is_active($form_id)
{
    if (gffd_feeds_get_form_feed_settings($form_id, 'as_object')->feed_active == 'active') {
        return true;
    } else {
        return false;
    }
}
    echo $required_field['gffd_index'];
    ?>
" name="gffd_form_feed_indexes[<?php 
    echo $required_field['gffd_index'];
    ?>
]" style="width:300px;">
							<option value=""><?php 
    _e("Choose a source for this data");
    ?>
</option>
							<option value="">--</option>
							<?php 
    foreach (gffd_is_array(gffd_get_form_fields(gffd_get_form(gffd_request('form_id')))) as $form_field) {
        ?>
								<option <?php 
        if (is_object(gffd_feeds_get_form_feed_settings(gffd_request('form_id'), 'as_object')->feed_indexes) && gffd_feeds_get_form_feed_settings(gffd_request('form_id'), 'as_object')->feed_indexes->{$required_field}['gffd_index'] == $form_field[0]) {
            ?>
									selected="selected"
								<?php 
        }
        ?>
 value="<?php 
        echo $form_field[0];
        ?>
"><?php 
        echo $form_field[1];
        ?>
</option>
							<?php 
    }
    ?>
function gffd_validation_and_payment($validation_result)
{
    $form_id = $validation_result['form']['id'];
    $the_submitted_form = $_REQUEST;
    //for easier reading.
    // Is this form supposed to be used by gffd?
    if (gffd_feed_is_active($form_id)) {
        // Validate all the fields.
        foreach (gffd_is_array(gffd_get_purchase_field_requirements()) as $required_field) {
            $gffd_feeds_get_form_feed_settings = gffd_feeds_get_form_feed_settings($form_id);
            // Get the feed index
            $gf_form_feed_index = $gffd_feeds_get_form_feed_settings['feed_indexes'][$required_field['gffd_index']];
            // Get the $_POST index by using value_to_post_input
            // so we can pull input_3_4 in GF style
            $gffd_convert_float_value_to_post_input = gffd_convert_float_value_to_post_input($gf_form_feed_index);
            // In the case when a required field is removed,
            // we need to test for it's value in $_POST.
            //
            // Test $required_field for it's $_POST
            // counterpart.
            if (isset($the_submitted_form[$gffd_convert_float_value_to_post_input])) {
                $gffd_is_valid_pre_format_feed_data = gffd_is_valid_pre_format_feed_data($required_field['gffd_index'], $the_submitted_form[$gffd_convert_float_value_to_post_input]);
                // If we have a good result, set the value to pass
                // to the purchasing functions.
                if ($gffd_is_valid_pre_format_feed_data) {
                    $gffd_fd_form_info[$required_field['gffd_index']] = $gffd_is_valid_pre_format_feed_data;
                    // If even one of the items fail, jump out,
                    // thrown an error and try again.
                } else {
                    // Fail the form.
                    $validation_result["is_valid"] = false;
                    $validation_result["form"] = gffd_get_form($form_id);
                    // Let's try and find out what failed by going through the
                    // form's fields.
                    foreach ($validation_result['form']['fields'] as &$field) {
                        if ($field['id'] == floor($gf_form_feed_index)) {
                            $field["failed_validation"] = true;
                            $field["validation_message"] = gffd_get_validation_message_feed_data($required_field['gffd_index']);
                        }
                    }
                    // Let's not return the validation result here,
                    // instead let's test for it after it's added
                    // messages to all fields.
                }
                // Okay, one of the fields were missing.
            } else {
                // If a field is missing, let's just do nothing and submit
                // the form. But, we will at least email the admin about it,
                // because we did not do the purchase.
            }
        }
        //end foreach
        // If something did not validate, throw the error
        // back to GF.
        if ($validation_result["is_valid"] == false) {
            return $validation_result;
            // If everything validated, let's try
            // and perform the purchase.
        } else {
            // Set the customer reference number on FD
            $gffd_fd_form_info['gffd_fd_customer_ref'] = gffd_fd_customer_ref($form_id);
            // Save the reference number to the DB temporarily so we can
            // get it later.
            update_option("gffd_fd_{$form_id}" . "_" . $_SERVER['REMOTE_ADDR'], $gffd_fd_form_info['gffd_fd_customer_ref']);
            // Run a purchase by form
            $result = gffd_fd_purchase_by_form($gffd_fd_form_info, 'as_original');
            if (gffd_is_array($result) && !$result['error_message'] && !defined('GFFD_DEBUG_FORM_SUBMIT') && $result['error']) {
                // Just show a simple error.
                wp_die(__("There was an error, but FirstData didn't\n\t\t\t\t\t\tsend back an error message."));
                // Want to see what the error is? Just set
                // define('GFFD_DEBUG_FORM_SUBMIT', true);
                // in wp-config.php and try again
            } else {
                // To debug just use define('GFFD_DEBUG_FORM_SUBMIT', true);
                // in wp-config.php
                if (defined('GFFD_DEBUG_FORM_SUBMIT')) {
                    echo "<pre>";
                    var_dump($result);
                    echo "</pre>";
                    exit;
                    // If the dev doesn't want to GFFD_DEBUG_FORM_SUBMIT
                } else {
                    // If there was an error, and we've submitted
                    // the data for purchase, let's see what the
                    // bank or FirstData class said.
                    if ($result['error'] === true) {
                        // Don't submit the entry.
                        $validation_result["is_valid"] = false;
                        // If there is a bank response, let's
                        // pass that to the CC field
                        if ($result['gffd_fd_instance']->getBankResponseMessage()) {
                            $validation_result = gffd_wp_die_by_fd_response($result, 'getBankResponseMessage');
                        } elseif ($result['gffd_fd_instance']->getErrorMessage()) {
                            // Try and see if there is just a generic
                            // error message.
                            $validation_result = gffd_wp_die_by_fd_response($result, 'getErrorMessage');
                        }
                        return $validation_result;
                        // If there was no bank response, but an error,
                        // we don't know what is wrong!
                    } else {
                        // Throw a general error message.
                        foreach ($validation_result['form']['fields'] as &$field) {
                            if ($field['type'] == 'creditcard') {
                                // Tell GF what field failed. Here,
                                // always the CC.
                                $field["failed_validation"] = true;
                                // Pass the bank response back to
                                // GF validation_message.
                                $field["validation_message"] = __("Sorry, but there was an error with the" . "information provided. Please correct and try again. " . "If this persists, contact the site owner.");
                            }
                        }
                        return $validation_result;
                    }
                }
            }
        }
    } else {
        // If the form is not a form with a feed, just ignore
        // and continue.
        return $validation_result;
    }
}