Welcome Guest, Not a member yet? Register   Sign In
Credit Card Processing / Validation
#1

[eluser]PV-Patrick[/eluser]
I am wondering if anyone has some suggestions on the best way to go about credit card processing/validation on a form. Here is what I have thought about so far...

I want to be able to authorize the transaction before it's converted to a sale; so if the user inputs the wrong CC information, the form will be displayed with everything filled out still and they can make the correction.

Currently, I thought about putting a callback rule on it and setting a session variable to the transaction ID I get from an AUTH_ONLY. However, that causes problems if there is any false validation returns. It will show up on the users CC statement and temporarily take the funds from their account; essentially leaving 5 transactions if they submit the form 5 times with errors.

My next thought would be to just validate the form with the validation class and then validate the card after. (on the TRUE side of form validation) However, I am not really sure how to repopulate the form, etc if their CC is declined for any reason. Can anyone shed some light on this and give some input? Thank you!
#2

[eluser]Pascal Kriete[/eluser]
Something like this might work:
Code:
$this->load->library('validation');
        
    $rules['username']    = "required";
    //... and any other rules
    
    $this->validation->set_rules($rules);
    
    $fields['username']    = 'Username';
    //... ditto here

    $this->validation->set_fields($fields);

    if($this->validation->run() == TRUE)
    {
        $credit_card_ok = //check the credit card

        if (count($_POST) > 1 && $credit_card_ok)
        {
            //redirect, success message, shutdown site now that you have the money, etc
        }
        else
        {
            // Form was good, but the credit card didn't come back positive.
            $this->validation->error_string = "Credit card invalid."
            $this->load->view('form_view');
        }
    }
    else
    {
        // First load, and if the form wasn't good.
        $this->load->view('form_view');
    }

This should refill the form and bypass your multiple credit card checks issue. Not the most elegant solution though.

To refill the form just do it the normal way with:
Code:
<?=$this->validation->fieldname;?>
Remember to run set_fields for this to work.

EDIT: The reason why this works is because CI runs set_fields before deciding on true or false. So even if the form validates, the object is already set...or so I hope (didn't test it Smile ).
#3

[eluser]PV-Patrick[/eluser]
Thanks for the reply!! I had something like that in-mind, I'm just not sure if it's the 'good' way to do it, but I guess whatever works... lol.




Theme © iAndrew 2016 - Forum software by © MyBB