JoJo
JoJo

Reputation: 161

Checking out with Cardsave 3D secure

Has anyone successfully integrated Cardsave using CI-Merchant and 3D Secure?

I've now managed to get the 3D Secure to respond to my website (it would appear you need to add 'return_url' as a parameter to the params for anyone else having problems), but the transactions always come back as failed using either a real card or a test 3D secure card with authorisation successful.

Unfortunately there isn't any documentation for the Cardsave driver on the CI-Merchant website, only an example for Paypal.

The failed transactions aren't showing up anywhere in my Cardsave account so I'm not even sure if CI-Merchant is communicating with Cardsave at that point.

Here's an example of the code I am using for a test:

public function test_live_payment()
    {
        $this->load->library('merchant');

        $creditcard = $this->input->post('creditcard');
        $creditcardtype = $this->input->post('creditcardtype');
        $cardmonth = $this->input->post('cardmonth');
        $cardyear = $this->input->post('cardyear');
        $cardsecurecode = $this->input->post('cardsecurecode');
        $cardnameon = $this->input->post('cardnameon');
        $address1 = $this->input->post('address1');
        $address2 = $this->input->post('address2');
        $city = $this->input->post('city');
        $postcode = $this->input->post('postcode');


        $data['status'] = '';
        $data['message'] = '';

        $test = TRUE;

            if ($test) :

                  $settings = array (
                    'merchant_id' => 'TEST ACCOUNT',
                    'password' => 'XXXX'
                );



            else :

                $settings = array (
                    'merchant_id' => 'LIVE ACCOUNT',
                    'password' => 'XXXX'
                );


            endif;


        if ($_POST) :

            $this->merchant->load('cardsave');


            $this->merchant->initialize($settings);

            $data['transaction_id'] = '999' . rand(1, 999);

            $params = array(
                            'amount' => '1.00',
                            'currency' => 'GBP',
                            'card_no' => $creditcard,
                            'name' => $cardnameon,
                            'exp_month' => $cardmonth,
                            'exp_year' => 20 . $cardyear,
                            'csc' => $cardsecurecode,
                            'transaction_id' => $data['transaction_id'],
                            'description' => 'Test payment',
                            'address1' => $address1,
                            'address2' => $address2,
                            'city' => $city,
                            'postcode' => $postcode,
                            'return_url' => site_url('/test-payment')
                 );

                 $response = $this->merchant->purchase($params);


                if ($response->success()) :
                    $gateway_reference = $response->reference();

                    $data['status'] = 'Success';
                    $data['message'] = 'The transaction was successfully processed';

                else :

                    $message = $response->message();

                    $data['status'] = 'Failed';

                    if ( ! empty($message)) :
                        $data['message'] = $message;
                    else :
                        $data['message'] = 'Transaction failed. No further details received.';
                    endif;

                endif;



        endif;


        $this->load->view('test_payment_form', $data);


    }

Upvotes: 1

Views: 161

Answers (1)

JoJo
JoJo

Reputation: 161

Seemed to have solved my own problem by, 1. making sure I was passing a return URL, and 2. sending the return URL to a new function which included the purchase_return() function. Here's my complete (test) code:

public function test_live_payment()
    {
        $this->load->library('merchant');

        $creditcard = $this->input->post('creditcard');
        $creditcardtype = $this->input->post('creditcardtype');
        $cardmonth = $this->input->post('cardmonth');
        $cardyear = $this->input->post('cardyear');
        $cardsecurecode = $this->input->post('cardsecurecode');
        $cardnameon = $this->input->post('cardnameon');
        $address1 = $this->input->post('address1');
        $address2 = $this->input->post('address2');
        $city = $this->input->post('city');
        $postcode = $this->input->post('postcode');


        $data['status'] = '';
        $data['message'] = '';

        $test = TRUE;

            if ($test) :

                  $settings = array (
                    'merchant_id' => 'TEST ACCOUNT',
                    'password' => 'XXXX'
                );



            else :

                $settings = array (
                    'merchant_id' => 'LIVE ACCOUNT',
                    'password' => 'XXXX'
                );


            endif;


        if ($_POST) :

            $this->merchant->load('cardsave');


            $this->merchant->initialize($settings);

            $data['transaction_id'] = '999' . rand(1, 999);

            $data['transaction_id'] = '999' . rand(1, 999);

            $newdata = array(
                   'transaction_id'  => $data['transaction_id']
                   );

           $this->session->set_userdata($newdata);

            $params = array(
                            'amount' => '1.00',
                            'currency' => 'GBP',
                            'card_no' => $creditcard,
                            'name' => $cardnameon,
                            'exp_month' => $cardmonth,
                            'exp_year' => 20 . $cardyear,
                            'csc' => $cardsecurecode,
                            'transaction_id' => $data['transaction_id'],
                            'description' => 'Test payment',
                            'address1' => $address1,
                            'address2' => $address2,
                            'city' => $city,
                            'postcode' => $postcode,
                            'return_url' => site_url('/test-payment-response')
                 );

                 $response = $this->merchant->purchase($params);


                if ($response->success()) :
                    $gateway_reference = $response->reference();

                    $data['status'] = 'Success';
                    $data['message'] = 'The transaction was successfully processed';

                else :

                    $message = $response->message();

                    $data['status'] = 'Failed';

                    if ( ! empty($message)) :
                        $data['message'] = $message;
                    else :
                        $data['message'] = 'Transaction failed. No further details received.';
                    endif;

                endif;



        endif;


        $this->load->view('test_payment_form', $data);


    }



    public function test_response()
    {
        $settings = array (
                    'merchant_id' => 'TEST ACCOUNT',
                    'password' => 'XXXX'
                );


        $this->load->library('merchant');
        $this->merchant->load('cardsave');
        $this->merchant->initialize($settings);

        $data['transaction_id'] = $this->session->userdata('transaction_id');


        $params = array(
                            'amount' => '1.00',
                            'currency' => 'GBP',
                            'transaction_id' => $data['transaction_id']

                 );

        $response = $this->merchant->purchase_return($params);

        if ($response->success()) :
                    $gateway_reference = $response->reference();

                    $data['status'] = 'Success';
                    $data['message'] = 'The transaction was successfully processed';

                else :

                    $message = $response->message();

                    $data['status'] = 'Failed';

                    if ( ! empty($message)) :
                        $data['message'] = $message;
                    else :
                        $data['message'] = 'Transaction failed. No further details received.';
                    endif;

                endif;


        $this->load->view('test_payment_form', $data);



    }

Upvotes: 1

Related Questions