2

Has anyone had any luck using SagePay Direct with CI-Merchant? So far the only response I am getting is:

Merchant_response Object
(
    [_status:protected] => failed
    [_message:protected] => 
    [_reference:protected] => 
    [_data:protected] => 
    [_redirect_url:protected] => 
    [_redirect_method:protected] => GET
    [_redirect_message:protected] => 
    [_redirect_data:protected] => 
)

I haven't used SagePay before and need to get this working urgently. I have added my IP address to the SagePay testing area but am not testing on https as am just on my localhost at the moment.

My code looks like:

public function process_payment()
    {

        $settings = array (
            'vendor' => 'XXX',
            'test_mode' => TRUE,
            'simulator_mode' => FALSE,
        );

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

        //get customer details
        $this->load->library('custom_cart');
        $customer = $this->custom_cart->get_customer_invoice_info();
        $customer_name = '';
            if ( ! empty($customer['title'])) $customer_name .= $customer['title'] .' ';
        $customer_name .= $customer['forename'];
        $customer_name .= $customer['surname'];

        $customer_street = $customer['address1'];
        $customer_street2 = $customer['address2'];
            if ( ! empty($customer['address3'])) $customer_street2 .= $customer['address3'];

        //order details
        $amt = $this->custom_cart->order_total();

        $get_curr = $this->custom_cart->get_currency();
        $currencycode = $get_curr['name'];

        $shippingamt = $this->custom_cart->shipping_cost();

        $itemamt = $this->custom_cart->order_subtotal();
        $taxamt = '0';
        $invnum = $this->custom_cart->customer_order_no();

         $params = array(
            'description'=> 'Online order',
            'currency'=> $currencycode,
            'transaction_id'=> $invnum,
            'email'=> $customer['email_address'],
            'first_name'=> $customer['forename'],
            'last_name'=> $customer['surname'],
            'address1'=> $customer_street,
            'address2'=> $customer_street2,
            'city'=> $customer['town_city'],
            'postcode'=> $customer['postcode'],
            'country'=> $customer['country'],
            'region'=> $customer['county'],
            'phone'=> $customer['phone'],

            'Amount'=> $amt,
            'card_no'=> $this->input->post('creditcard'), 
            'name'=> $customer_name, 
            'card_type' => $this->input->post('creditcardtype'), 
            'exp_month'=> $this->input->post('cardmonth'),
            'exp_year' => $this->input->post('cardyear'), 
            'csc'=> $this->input->post('cardsecurecode')
        );


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

        echo '<pre>';
        print_r($response);


    }

(all the values for the params are valid and I have checked the correct values are passed to them. Vendor name is masked here)

JoJo
  • 161
  • 1
  • 12
  • As an update, I have moved the code onto the server with a full SSL certificate so I am running my tests from https. I have also switched to using the simulator (https://test.sagepay.com/Simulator/) but am still getting the same response message and also cannot see my transactions so am not even sure if it's even getting to the SagePay server? – JoJo Jan 29 '13 at 14:56
  • It's very strange that it's not returning any error at all. This might not be the problem, but can you try changing the `Amount` parameter to lowercase? If that doesn't work, you might need to add some debugging to `merchant_sagepay_base.php`, e.g. add `print_r($response)` on line 148 right after `$this->post_request()` to have a look at the raw response. – Adrian Macneil Jan 30 '13 at 00:54
  • I have tried both of these approaches and even using the `print_r($response);` I don't get anything else? I think I must be missing a trick here! I should point out I called the library in my __construct function, .e.g, `public function __construct() { parent::__construct(); $this->load->helper('language'); $this->load->library('merchant'); $this->merchant->load('sagepay_direct'); }` I'm not getting any other errors either! – JoJo Jan 30 '13 at 13:40
  • I have also tried using the code example from the SagePay Direct integration kit and this seems to work just fine! – JoJo Jan 30 '13 at 13:42

1 Answers1

1

Finally tracked down the problem - I was passing through two digits for the year and this is where it was failing (I forgot on my previous merchant I was adding in the 20 prefix)! Thank you for your help. (If anyone has a similar problem I tracked it down by echoing a response from each function in the function trail)

JoJo
  • 161
  • 1
  • 12