3

I'm integrating Securepay DirectPost for a client, which sends the customer off to Securepay and then back again - all is working except no text is appearing on the return page (eg, thanks for your order). I get the emails ok though, just no text, can anyone think of what might be going wrong? I use this function to update the order - $this->checkout_complete_offsite($auth, $refid); If I use this one - $this->gateway_order_update($auth,$refid) I just get a blank page (eg, no content at all). I get a 'payment authorised' on the order in admin but I do see that the transaction id has not updated (I put this in the $auth array).

Thanks in advance.

Jill

Add: I have tried the extload.php file as you mentioned but putting $this->response_script(ucfirst(get_class($this))) as my return_url just caused an error at securepay and the extload($post) function did not get any post variables returned to it, even if I ran $this->relaunch_cart_snapshot($txnid) inside it (that was empty too). So I put it back to the return_url $this->get_notify_url(ucfirst(get_class($this)),'success') and it then runs the success function I wrote and updates the database and orders go through, but we're back to the no 'thanks for your order' displaying. Just missing a tiny step!

5

Usually when creating a gateway that uses an html form to post directly to the payment service, we use both of the functions you mentioned. Here's the general overview:

Inside the charge method

  • Create the security hash/fingerprint if required
  • For the return/redirect URL in the html form, use $this->response_script(__CLASS__) this will make use of a file called extload.php and an extload method in your gateway. (Make sure that file is set up correctly with your system path. By default this file is in themes/third_party/cartthrob/lib/ )
  • Add $this->gateway_exit_offsite(NULL, $url=FALSE, $jump_url= FALSE); This basically does some maintenance functions to prepare the cart for going offsite.
  • Echo out the html form with the required fields

    Example of how to use a second credit card form that submits directly to the payment service:

    public function charge($credit_card_number)
    {
        // Do whatever you need to do here before the credit card form.
        // Usually this will include a security hash generation or
        // data formatting that needs to be passed along to the payment service
    
        // create an array for the credit card form
        $jump_html[] =  "<form method='post' action='YOUR_FORM_ACTION'>";
    
        // add your form fields
        $jump_html[] = "<input type='hidden' name='SECURITY' value='YOUR_HASH' />";
        $jump_html[] = "<input type='text' name='SOMEFIELD' value='' />";
        $jump_html[] = "<input type='submit' value='submit' />";
        $jump_html[] = "</form>";
    
        // this is called for maintenance functions.
        // You'll note that we're telling it not to do any redirection or jump pages.
        $this->gateway_exit_offsite(NULL, $url=FALSE, $jump_url= FALSE);
    
        // echo out the form    
        foreach ($jump_html as $line)
        {
            echo $line; 
        }
        exit;
    }
    

To handle the response from the payment service

  • You'll be using a method called extload to handle the response function extload($post){} That $post variable will contain the payment service's response. All of the following items take place inside that extload method.
  • You generally need to relaunch the cart snapshot you saved earlier when you called the gateway_exit_offsite method. The gateway should be returning your order id in its response, in your example I'm guessing the order id is refid.

    $this->relaunch_cart_snapshot($post['refid']);
    
  • Use the $post response to create an array of responses to use with the {exp:cartthrob:submitted_order_info} tag. The values contained in the $post response varies by payment service, but there's usually some kind of status code that tells you if the payment is authorized or if there are errors.

    Example of the response array:

    $auth = array(
        'authorized' => FALSE,
        'error_message' => NULL,
        'failed' => TRUE,
        'declined' => FALSE,
        'transaction_id' => NULL, 
        'processing' => FALSE
    );
    

    Those values would need to be updated based on the response returned.

  • Return that array and redirect to your Thank you page using:

    $this->gateway_order_update($auth, $this->order('order_id'), $this->order('return'));
    exit;
    
6
  • Nice answer! Very detailed. – Anna_MediaGirl Jan 24 '14 at 9:07
  • Unfortunately I can't say what I wanted to say (not enough room) but $this->relaunch_cart_snapshot($post['refid']) is blank (even though $post['refid'] is not) and still if I use $this->checkout_complete_offsite($auth, $refid); the order is processed but no 'thank you' text is displayed and if I use $this->gateway_order_update($auth,$refid,'template'); (using either $refid or $this->order('order_id')) I get a blank page and the order does not process. – user2226547 Jan 24 '14 at 22:47
  • I think the problem might be that the URL is still saying Securepay, because if I click the return_url link in the debug email I get the success message displayed but I can't do any header("Location:") redirects in the script. How do I set the $this->order('return')? I tried to change in the charge function but got an error that I couldn't write to it. – user2226547 Jan 25 '14 at 23:12
  • Have managed to fix it, but have now realised I will need to split the order form into two pages, one for the order/customer details to go into the database, and one for the credit card info which must go straight to Securepay for PCI compliance, and not via the cart/database (as $jump_url does). Any ideas/suggestions on how to do that would be appreciated! – user2226547 Jan 26 '14 at 22:59
  • I added an example of how to add the credit card form to the original answer. – CartThrob - Barrett Jan 27 '14 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.