3

Can't quite believe I'm asking this question but here goes....

(Using PHP within Codeigniter)

I am integrating Barclays EPDQ into an e-commerce site for taking credit card payments. On successful payment EPDQ redirects back to the site passing query string parameters in the URL. I am looking for the orderID sent back from EPDQ, if its there I store a few things in the PHP session and redirect to the payment confirmation page. If the payment was unsuccessful the order ID won't be there and so I redirect to a payment failed method which shows a CI view file.

The condition for this check and session save routine is as follows:

$success = false;

if($_GET['orderID'])
{
    $_SESSION['payment']['order_id']  = $_GET['orderID'];
    $_SESSION['payment']['method']    = 'card';
    $_SESSION['payment']['ref']       = $_GET['PAYID'];
    $_SESSION['payment']['status']    = 'Completed';

    $success = true;
}

(please note the session is initialised and the payment array created prior to this code executing)

Pretty simple so far, right. The code for the directions then looks like this:

if(!$success)
{
    redirect('payment/card/fail');
}
else
{
    redirect('payment/confirmation');
}

The issue I am having is that this redirection doesn't work as I would expect. EPDQ reports successful payment and redirects back to our site as required. However when my script evaulates the GET parameters that it sends and goes to do the redirect it always uses the failed redirection............unless, and this is the bit that is really stumping me, I do this:

if(!$success)
{
    exit('Failed');
    redirect('payment/card/fail');
}
else
{
    redirect('payment/confirmation');
}

(note the added 'exit').

Once I include this exit the code executes as desired in all test cases and we start to see the payment success page. Removing the exit immediately reverts back to 100% tests failing.

Does anyone have any idea why this is happening as I've not ever seen this before?

9
  • 1
    Ah..aa..aah.. LOL! +1 for title! Commented Apr 9, 2013 at 11:46
  • can you show us the how controller.. Commented Apr 9, 2013 at 11:51
  • can you post the code for redirect() Commented Apr 9, 2013 at 11:52
  • @Adelphia redirect is Codeigniter help function Commented Apr 9, 2013 at 11:52
  • 1
    Maybe you miss an php exception when redirect() is called, check your php error config. Commented Apr 9, 2013 at 20:10

3 Answers 3

1

The only possible explanation is the case that $success is not updated and it is taking its preassigned value false. Check the value of $success by var_dump.

Sign up to request clarification or add additional context in comments.

1 Comment

This was one of the first things I actually checked. The use of the $success var was in fact a later update I added in in response to this issue. If you look in the success condition I am setting some session variables; Regardless of the inclusion of the exit these variables are set when a successful payment is made
1

The reason this was happening was as a result of a setting within Barclays EPDQ which was sending out a response ahead of the main payment response (this is a pre response repsonse allowing the site to be customised based on an incoming success or failure). This meant my function was being hit twice, once without the GET params on the first hit and once with them when the full payment response with params was returned. Putting in the exit meant that the failure redirection on the first hit wasn't executed and so the script was allowed to show the success condition. Removing/unsetting this pre-response from EPDQ now means all conditions execute as required.

In the end not really a PHP issue but worth noting in case anyone is working on integrating EPDQ and mistakenly sets this response within the admin interface of EPDQ.

Comments

0

Most likely, if the only way to reach redirect('payment/confirmation') is by adding a call to exit construct, I would assume redirection to failure route happens in all cases (even though the script is supposed to end successfully).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.