Page 1 of 2

SagePay FailureURL

Posted: Fri Feb 19, 2010 9:50 pm
by babyewok
Hi,

I Have Opencart 1.4 and I am just testing SagePay on my local test server on my computer and I've managed to clear up and Invalid problem I was having with CustomerName, Postcode, etc by using the solution at the end of this thread: http://forum.opencart.com/viewtopic.php ... d&start=15

Now, the only error I am getting is "The FailureURL field should be between 1 and 2000 characters long." which suggest that no Failure URL is specified. Looking at sagepay.php, it is referrenced here on line 33:

Code: Select all

if ($this->request->get['route'] != 'checkout/guest_step_3') {
			$this->data['FailureURL'] = $this->url->https('checkout/payment');
		} else {
			$this->data['FailureURL'] = $this->url->https('checkout/guest_step_2');
		}
Why is SagePay simulator returning this error?

Re: SagePay FailureURL

Posted: Fri Feb 19, 2010 10:53 pm
by Miguelito
Have you cheched the page source before pushing Confirm order how the FailureURL is defined there?

Re: SagePay FailureURL

Posted: Sat Feb 20, 2010 2:24 am
by babyewok
Couldn't see any reference to it, but then there is also no explicit referrence to SuccessURL either and Sage Pay doean't seem to have a problem with that.

Re: SagePay FailureURL

Posted: Sat Feb 20, 2010 8:49 pm
by babyewok
Please help! I have to get this completed for my client ASAP!

Re: SagePay FailureURL

Posted: Sat Feb 20, 2010 11:39 pm
by Miguelito
Is your site available from internet/outside so I could take a look?

Re: SagePay FailureURL

Posted: Sat Feb 20, 2010 11:53 pm
by babyewok
No, not yet

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 12:15 am
by babyewok
What do you need to look at? Maybe I can post some code.

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 12:49 am
by babyewok
What is FailureURL supposed to be? Where is it suppoed to redirect to? I can see that SucessURL is:

Code: Select all

$data['SuccessURL'] = $this->url->https('payment/sagepay/success&order_id=' . $this->session->data['order_id']);
and there is a function for success in Sagepay.php.

I am using opencart v 1.4 by the way and have done nothing to the sagepay.php file except the edits mentioned earlier (and even before that the FailureURL wasn't working anyway)

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 4:04 am
by Miguelito
What about you sagepay.tpl file in catalog? Does it has the variable $FailureURL set as FailureURL?

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 7:42 pm
by babyewok
No. All it has is:

Code: Select all

<form action="<?php echo $action; ?>" method="post" id="checkout">
  <input type="hidden" name="VPSProtocol" value="2.23" />
  <input type="hidden" name="TxType" value="<?php echo $transaction; ?>" />
  <input type="hidden" name="Vendor" value="<?php echo $vendor; ?>" />
  <input type="hidden" name="Crypt" value="<?php echo $crypt; ?>" />
</form>
<div class="buttons">
  <table>
    <tr>
      <td align="left"><a onclick="location='<?php echo $back; ?>'" class="button"><span><?php echo $button_back; ?></span></a></td>
      <td align="right"><a onclick="$('#checkout').submit();" class="button"><span><?php echo $button_confirm; ?></span></a></td>
    </tr>
  </table>
</div>
I tried adding

Code: Select all

<input type="hidden" name="FailureURL" value="<?php echo $FailureURL; ?>" />
but that made no difference.

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 8:21 pm
by Miguelito
You don't need to add the FailureURL to the tpl file because it seems that all the data (including FailureURL) is put into an array called data and then somewhere in line 110 in sagepay.php there's:

Code: Select all

$this->data['crypt'] = base64_encode($this->simpleXor(http_build_query($data), $password));
So the actual problem is with lines 33-37 in sagepay.php which is:

Code: Select all

if ($this->request->get['route'] != 'checkout/guest_step_3') {
			$this->data['FailureURL'] = $this->url->https('checkout/payment');
		} else {
			$this->data['FailureURL'] = $this->url->https('checkout/guest_step_2');
		}
And it should be:

Code: Select all

if ($this->request->get['route'] != 'checkout/guest_step_3') {
			$data['FailureURL'] = $this->url->https('checkout/payment');
		} else {
			$data['FailureURL'] = $this->url->https('checkout/guest_step_2');
		}
Hope this solves your problem :)

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 8:40 pm
by babyewok
Well that worked just fine (could have sworn I had tried that before!).

Now I can go through to the simulator, but when I click OK (to return an order success result), I get this:

Notice: Undefined index: order_id in C:\UniServer5_5a\UniServer\www\Opencart\catalog\controller\payment\sagepay.php on line 146Notice: Undefined index: order_id in C:\UniServer5_5a\UniServer\www\Opencart\catalog\controller\payment\sagepay.php on line 190Warning: Cannot modify header information - headers already sent by (output started at C:\UniServer5_5a\UniServer\www\Opencart\index.php:67) in C:\UniServer5_5a\UniServer\www\Opencart\system\engine\controller.php on line 22

Thanks so much for your help so far.

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 9:06 pm
by Miguelito
I think the problem is with public function success which has a line:

Code: Select all

$this->model_checkout_order->confirm($this->request->get['order_id'], $this->config->get('sagepay_order_status_id'));
And it should be:

Code: Select all

$this->model_checkout_order->confirm($data['VendorTxCode'], $this->config->get('sagepay_order_status_id'));
<- this is ok if Sagepay returns the sent order_id in VendorTxCode. If it's some other variable then you should change that one instead of 'VendoTxCode'.

Also remember to change the same variable/field in the same function to:
$this->model_checkout_order->update($this->request->get['order_id'], $this->config->get('sagepay_order_status_id'), $message, FALSE);

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 9:08 pm
by babyewok
OK, so not claiming to actually know what on earth I am doing here, I looked at the teh files for som of the other payment gateways and changed

line 146 from:

Code: Select all

$this->model_checkout_order->confirm($this->request->get['order_id'], $this->config->get('sagepay_order_status_id'));


to:

Code: Select all

$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('sagepay_order_status_id'));
and line 191 from:

Code: Select all

$this->model_checkout_order->update($this->request->get['order_id'], $this->config->get('sagepay_order_status_id'), $message, FALSE);
to:

Code: Select all

$this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('sagepay_order_status_id'), $message, FALSE);
which seemed to resolve that problem to reveal anoother! I then got and error about an undefined index 'name' in catalog/model/checkout/order.php. The line sin question were with in the Text mail section, both reading:

Code: Select all

$text .= $language->get('text_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
I simply commented them out as I couldn't see a a reference to 'text_order_status' in the HTML email section. That seemed to do the trick.

Were those lines left in by accident form an older version or do I need to figure out how to get them working again?

Re: SagePay FailureURL

Posted: Sun Feb 21, 2010 9:13 pm
by babyewok
We seemed to reply at teh same time there! I tried your solution - didn't seem to work, so maybe I actually got it right myself?!!

Re: SagePay FailureURL

Posted: Mon Feb 22, 2010 4:48 am
by Miguelito
Have you checked that your orders are inserted into Opencart only after the customer has completed the payment through Sagepay or are orders inserted into Opencart before the customer has completed the payment? Just wondering how your fix worked out in end-to-end perspective...

Re: SagePay FailureURL

Posted: Mon Feb 22, 2010 6:01 pm
by babyewok
Just went through SagePay simulator and returned a Not Authorised result and the order was not placed. Tried again as Success and the order was placed.

Seems to be working fine. Thanks for checking - you help has been invaluable!

Re: SagePay FailureURL

Posted: Wed Feb 24, 2010 12:35 am
by httpsNOVICE
for those of use that at some stage might get this problem, maybe a update could be put together to help who might need it!?

Re: SagePay FailureURL

Posted: Wed Feb 24, 2010 3:21 am
by babyewok
OK, so now it's all working properly, I should really point out that the Failure URL does nothing but return the user to the 2nd page of the guest checkout - there is no actual warning to the user that there has been a problem. They woudl just end up going around in circles.

Is that what's supposed to happen?

Re: SagePay FailureURL

Posted: Tue Mar 02, 2010 12:32 am
by babyewok
So is there just not supposed to be any actual error message? FailureURL is just to satisfy SagePay?