Author Topic: Sage Pay (Protx) Direct Virtuemart Payment Module  (Read 34488 times)

chopstik

  • Beginner
  • *
  • Posts: 9
    • Chopstik Internet
Sage Pay (Protx) Direct Virtuemart Payment Module
« on: May 20, 2009, 03:39:06 am »
Hi there, not sure if this will be of use to anyone, but I've developed a basic payment module that will allow you to use Sage Pay (ex. Protx) as your payment processor.

The only other option that I came across prior to writing my own was the Protx Direct Virtuemart Component from Ecom Solution (http://tr.im/lPHg). Not sure that its working fully with J v1.5.10 or VM 1.1.3 so I built this basic module instead which I know does.  Its live at http://www.tikidrums.com.

I've not packaged it as a module rather attaching the files and describing what I did. I've not implemented 3D authorisation or the included PayPal transaction types, although should you need them it would be quite easy to shoehorn in the necessary code. All I was interested in was basic card payments.

I started with the Direct Integration kit from Sage Pay (http://www.sagepay.com/developers/downloads/integration_kits/direct/PHP_Kit.zip). This is a standalone package that will create DB tables and allow you to process transactions in a stand alone environment. I grabbed various useful functions and pieces of code and placed it within this VM payment module.

Most payment processors allow you to provide a 'return url' that they will then post authorisation results back to.  Sage Pay is different as far as I can tell and requires you to post and have the posting script gather the immediate results. Most of the VM modules seem to like the former process and have a notification script waiting for that return url to be called and from there determine if the transaction has been authorised or not. I've not used a notify script rather adjusted /administrator/components/com_virtuemart/html/checkout.sagepay_result.php to do the donkey work and update our orders table.

To get it all working...

  • upload "ps_sagepay.cfg.php" to /administrator/components/com_virtuemart/classes/payment/
  • upload "ps_sagepay.php" to /administrator/components/com_virtuemart/classes/payment/
  • upload "checkout.sagepay_result.php" to /administrator/components/com_virtuemart/html/
  • In VM Administration / Store create a new payment method. Call it what ever you want to show on screen when a customer chooses it. Give it a code of 'SAGE' and choose 'ps_sagepay' from the drop down list of "Payment class name". For "Payment method type" choose 'HTML-Form based (e.g. PayPal)'.
  • Save it and then come back into it. In the Configuration tab add in your Vendor Name (provided by Sage Pay) and copy in the HTML included in the file `VM-SagePay-Form.php`

I think I've outlined all the steps, If I haven't, let me know and I can amend this list for all.

*Note: the JS form validation is not yet working at time of writing this. Anyone find where the problem with that is I'd appreciate the tip!

[attachment cleanup by admin]

jaddi01

  • Jr. Member
  • **
  • Posts: 52
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #1 on: May 20, 2009, 11:41:13 am »
Hello Chopstik

a group of us have been working on a similar thing.  Way back when it was Protx.  Based on VSP Forms.  I see yours is based on direct transaction handling through Virtuemart.

You can have a look at it here https://forum.virtuemart.net/index.php?topic=2079.msg182105#msg182105

mike_g

  • Beginner
  • *
  • Posts: 2
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #2 on: June 09, 2009, 13:52:29 pm »
Quote
*Note: the JS form validation is not yet working at time of writing this. Anyone find where the problem with that is I'd appreciate the tip!
THe quotes in the JS error message strings are not escaped in the code you posted:
Code: [Select]
    if (theForm.CardNumber.value == "")
    {
        alert("Please enter a value for the [color=red]"[/color] Card Number[color=red]"[/color]  field.");
        theForm.CardNumber.focus();
        return (false);
    }
   
    if (theForm.ExpiryDate.value == "")
    {
        alert("Please enter a value for the [color=red]"[/color] Expiry Date[color=red]"[/color] field.");
        theForm.ExpiryMonth.focus();
        return (false);
    }
Could be that joomla stripped the escape char. When changed to single quotes I don't get any error messages in FF.

chopstik

  • Beginner
  • *
  • Posts: 9
    • Chopstik Internet
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #3 on: June 09, 2009, 21:02:39 pm »
Much appreciated mike_g.

Swaino

  • Beginner
  • *
  • Posts: 11
    • http://www.data.org.uk
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #4 on: July 21, 2009, 15:55:04 pm »
Hello Chopstik and Everyone

Firstly, i'd like to say thankyou for creating these scripts. Im a bit of a novice when it comes to building online shops and have no programming experience so it's quite daunting making a direct payment webshop. However stuff like this helps me figure it out in my head.

I am going to install your scripts to the site (www.data.org.uk) as i also do not need 3DS. Just wondering if there's anything i should be aware of and where abouts i should change the URL's should i do testing first and then go live...? Im guessing this would be changed inside the scripts themselves as this isn't a packaged module.

Just any warnings or additional info would be great, has any one else used these scripts? Thanks again!!

Paul

Swaino

  • Beginner
  • *
  • Posts: 11
    • http://www.data.org.uk
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #5 on: July 23, 2009, 13:24:03 pm »
Just wanted to say thanks to all involved on the threads about direct and VSP methods. Chopstik - used your scripts and didnt have asingle problem, the site transactions went to Sage and back again with no problems.

Anyway, just wanted to say a massive thanks!

Lee1

  • Beginner
  • *
  • Posts: 6
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #6 on: October 14, 2009, 15:05:23 pm »
Hi,

I followed Chopstick's instructions down to a T, but I'm getting an error message when subitting payment.

Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\myjoomla\administrator\components\com_virtuemart\html\checkout.sagepay_result.php on line 23

I'm assuming this is just because I'm working with XAMPP, and when the site moves to a live server, this error will be rectified?

Thanks in advance,
Lee

dilby

  • Beginner
  • *
  • Posts: 31
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #7 on: October 23, 2009, 15:47:14 pm »
Hi - Many thanks for this. Works fine for live server, however how do I get this to work for test server? Protx won't authroise payment until I first use this with the test server. I've looked somwhere to change the subdomain in the url from live to test, but I cannot find a url anywhere!

Thanks again though.

chopstik

  • Beginner
  • *
  • Posts: 9
    • Chopstik Internet
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #8 on: October 27, 2009, 04:02:39 am »
Hey there dilby,

About line 138 of the "checkout.sagepay_result.php" script you'll be able to set a flag from "LIVE" to "TEST".  By doing that any transactions you put through - presumably testing transactions - will be posted to the SagePay TEST URL's listed in an array on line 183 instead of the LIVE url's. Hope that answers your question, let me know if it doesn't.

Hi - Many thanks for this. Works fine for live server, however how do I get this to work for test server? Protx won't authroise payment until I first use this with the test server. I've looked somwhere to change the subdomain in the url from live to test, but I cannot find a url anywhere!


qbic

  • Beginner
  • *
  • Posts: 3
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #9 on: October 29, 2009, 20:58:33 pm »
Hi

I am getting this error with this sage pay mod if anyone can help me out.  This is going through to Sage pay ok but on returning back to my site i get this error


Warning: include(/home/bluesky2/public_html/includes/protx_functions.php) [function.include]: failed to open stream: No such file or directory in /home/blu/public_html/administrator/components/com_virtuemart/html/checkout.protx_cpi_result.php on line 32

Warning: include() [function.include]: Failed opening '/home/bluesky2/public_html/includes/protx_functions.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/blu/public_html/administrator/components/com_virtuemart/html/checkout.protx_cpi_result.php on line 32

Fatal error: Call to undefined function simplexor() in /home/blu/public_html/administrator/components/com_virtuemart/html/checkout.protx_cpi_result.php on line 69

chopstik

  • Beginner
  • *
  • Posts: 9
    • Chopstik Internet
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #10 on: October 30, 2009, 18:46:17 pm »
That doesn't look like an error with the mod, that's a php coding error. You're referencing the "simplexor()" function from the file "protx_functions.php" in "checkout.protx_cpi_result.php on line 69". protx_functions.php isn't where PHP think's it should be.

dilby

  • Beginner
  • *
  • Posts: 31
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #11 on: November 05, 2009, 21:26:10 pm »
Hey there dilby,

About line 138 of the "checkout.sagepay_result.php" script you'll be able to set a flag from "LIVE" to "TEST".  By doing that any transactions you put through - presumably testing transactions - will be posted to the SagePay TEST URL's listed in an array on line 183 instead of the LIVE url's. Hope that answers your question, let me know if it doesn't.

Hi - Many thanks for this. Works fine for live server, however how do I get this to work for test server? Protx won't authroise payment until I first use this with the test server. I've looked somwhere to change the subdomain in the url from live to test, but I cannot find a url anywhere!



thank you so much for your help - it worked perfectly!

I have one more question for you if you would be so kind -

Is there a way to remove the 'follow this link to view order details' link and when someone pays instead of it showing the purchase order, for it to forward to a custom landing page? I don't want to use the purchase order, or have the logo appear at the top etc. I have made a landing page that I want people to see once they pay.

I hope this makes sense.

chopstik

  • Beginner
  • *
  • Posts: 9
    • Chopstik Internet
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #12 on: November 05, 2009, 22:38:41 pm »
Yeah I'm sure there is. On line 184 of "checkout.sagepay_result.php" you could adjust that and re-direct to wherever you want. All the important stuff happens prior to that re-direct.

Code: [Select]
vmRedirect(SECUREURL."index.php?option=com_virtuemart&page=account.order_details&order_id=".$d['order_id']);

dilby

  • Beginner
  • *
  • Posts: 31
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #13 on: November 10, 2009, 13:29:06 pm »
Thanks Chopstik! Worked a treat - very helpful.

What is the situation with the JS validation - I have read the above post regarding single quotes, but not sure where this is meant to go. Currently, even if I change these and a popup message does pop up telling me to fill in a form, I am redirected to payment result page.

There is also no validation for the cv2 field. I tried this - but no luck. What is the proper code for this whole validation section, taking into account Mike_g's improvements.

Code: [Select]
  if (theForm.CV2.value == "")
    {
        alert("Please enter a value for the "CV2" field.");
        theForm.CV2.focus();
        return (false);
    }
   

chopstik

  • Beginner
  • *
  • Posts: 9
    • Chopstik Internet
Re: Sage Pay (Protx) Direct Virtuemart Payment Module
« Reply #14 on: November 10, 2009, 21:51:46 pm »
Mike_g was referring to the quotation marks (") in the alert messages, they should be either escaped like \" or replace them with single apostrophes ('). Try this script instead...

Code: [Select]
<script type="text/javascript">
<!--

var ClickedTwice = false

function formValidator(theForm)
{
    if (theForm.CardHolder.value == "")
    {
        alert("Please supply the Name that apears on your Credit Card.");
        theForm.CardHolder.focus();
        return (false);
    }
   
    if (theForm.CardNumber.value == "")
    {
        alert("Please enter a value for the 'Card Number' field.");
        theForm.CardNumber.focus();
        return (false);
    }
   
    if (theForm.ExpiryDate.value == "")
    {
        alert("Please enter a value for the 'Expiry Date' field.");
        theForm.ExpiryMonth.focus();
        return (false);
    }
   
if (theForm.CV2.value == "")
    {
        alert("Please enter a value for the 'CV2' field.");
        theForm.CV2.focus();
        return (false);
    }
   
    // Simple check to avoid multiple sends if the user get impatient
    if (ClickedTwice)
        return (false);
    ClickedTwice = true;       

    return (true);
}
//-->
</script>