VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Payment VM 1.1 => Topic started by: chopstik on May 20, 2009, 03:39:06 am

Title: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik 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 (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 (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...


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]
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: jaddi01 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
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: mike_g 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.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik on June 09, 2009, 21:02:39 pm
Much appreciated mike_g.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: Swaino 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
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: Swaino 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!
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: Lee1 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
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: dilby 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.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik 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!

Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: qbic 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
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik 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.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: dilby 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.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik 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']);
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: dilby 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);
    }
   
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik 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>
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: cormicar on November 30, 2009, 16:10:36 pm
Hey All,
My site is hosted with my local ISP.It's a Joomla/Virtuemart site.I want to get SagePay working with Direct integration(i.e. the user doesn't leave my site to complete the payment). I'm currently applying for a Sagepay account but can anyone tell me if there is a way to avoid paying for an SSL cert that is required to use Sagepay with direct Integration.My ISP are charging €99 per year per domain.Thanks~!
 
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik on November 30, 2009, 21:20:52 pm
Why avoid paying for an SSL cert? They're a necessary tool to keep your customers' dats safe. Trustico do certs for as little as £30 - http://tr.im/Genx - although I  prefer the QuickSSL® Premium for £60.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: cormicar on December 01, 2009, 16:59:07 pm
Thanks Chopstik. I have never used ssl certs and am a bit anxious about using them. I have found an SSL cert on godaddy for under €10. Now I just need to pay €25 for a dedicated ip address and I can get started on doing this.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: cormicar on December 04, 2009, 19:35:27 pm
Hi Chopstik. I have bought a dedicated IP and successfully installed my SSL cert. I then tried copying your files into the directories you specified but when a user tries to pay, the card details disappear and the order doesn't seem to go through. I have set the sage config to TEST in the checkout file and still nothing. I rang Sagepay and they advised that the transactions are going through but that they are invalid. Have you any idea how to fix that. I presume I am not posting some info that I should be.Thanks.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: cormicar on December 05, 2009, 14:56:54 pm
Thanks to Chopstik for your great work on this. Finally got your code working. Because I am operating out of Ireland I had to send my post info across in euro rather than pounds. I just changed the GBP to EUR in the checkout file and voila. Thanks again!
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: s.k on December 18, 2010, 00:11:46 am
hello all can I use this this for direct sagepay integration , help will be appericiated
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: dgh1981 on December 30, 2010, 16:57:45 pm
I have a strange problem with this, at the end of transaction the credit/debit card details form shows once, entered details then comes up again?

Then even when entered second time the payment doesn't go through?

Any ideas would be most appreciated: www.igfitwear.com is the website.
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: Sydiom on November 16, 2011, 14:17:25 pm
Hello Chopstix

Will this work with J1.7 and VM2?
Title: Re: Sage Pay (Protx) Direct Virtuemart Payment Module
Post by: chopstik on August 13, 2013, 23:40:16 pm
For those looking for the original files you need to be a logged in member of this forum.
In any case I've created a github repo with the code as well. That can be found here:
https://github.com/chopstik/sagepay-virtuemart (https://github.com/chopstik/sagepay-virtuemart)
I've not used the module in Joomla v1.7 or anything other than v1.5, perhaps others working with newer Joomla versions might fork the repo and add to the codebase.
Cheers, chopstik |/