CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Trying to write a Sagepay Forms Payment processor - advice needed
Pages: [1] 2

Author Topic: Trying to write a Sagepay Forms Payment processor - advice needed  (Read 7717 times)

EdP

  • I post frequently
  • ***
  • Posts: 260
  • Karma: 7
  • CiviCRM version: 4.4
  • CMS version: Joomla 2.5.x
Trying to write a Sagepay Forms Payment processor - advice needed
July 31, 2009, 07:39:10 am
Sagepay (was Protx) has various options, one of which is their forms protocol. Some info here:
http://www.sagepay.com/developers/integration_manual/form_introduction.asp

Since I can't find anyone who has written one of these before (I did find some Sagepay Direct code, but that's not what I need and didn't appear to work), I'm (foolishly) plunging in to try myself.

I've read the advice here:
http://wiki.civicrm.org/confluence/display/CRMDOC/Creating+Additional+Payment+Processor+Plugins
Which is helpful but only gets me so far. Please bear with me on this - this is the first thing I've ever tried to code in PHP.

I've started my code, but currently have a couple of questions:
1. Sagepay requries that "The final confirmation page on your web site should contain an HTML FORM with the Action set to the Sage Pay Form submission URL and the following 4 hidden fields as part of that Form." How can I add hidden fields to the relevant pages (in Contribute and Event, presumably) - I know generally how to code hidden fields, but which pages am I adding this to and how?

2. Sagepay then do their stuff and "The system will append to the SuccessURL or FailureURL a field called CRYPT, [sets out format of the return URL ? fields].  The SuccessURL and FailureURL field should point to scripts on your server that extract the information in the crypt field and use it to update your database (if you have one) and/or format an appropriate response page for the customer."
Obviously I can create a script for these to point back to, and I think I know how to get the script to pull the required information out of those fields, but how does the script "tell" CiviCRM that the transaction was a success/failure and what page do they forward them to (i.e. the equivalent of the thank you page when you use the "pay later" option?)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trying to write a Sagepay Forms Payment processor - advice needed
July 31, 2009, 02:09:52 pm
Hi,

I'll take a longer look at your questions later but I think the starting point for q 2 is to look at the IPN files in civicrm/extern - eg. pxIPN (I think it's called) - it basically just receives the return url and passes information from it to the main processing script for that payment processor
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trying to write a Sagepay Forms Payment processor - advice needed
July 31, 2009, 02:17:01 pm
Re point 1 - I have a feeling from a quick look that the Forms integration is not the way to go and that server integration is.

This is more the sort of thing I'd be wanting to work from if I was coding it.

http://www.sagepay.com/developers/integration_manual/server_protocol.asp

Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trying to write a Sagepay Forms Payment processor - advice needed
July 31, 2009, 02:32:20 pm
Actually- when I get a chance I'll check those options a little more
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

EdP

  • I post frequently
  • ***
  • Posts: 260
  • Karma: 7
  • CiviCRM version: 4.4
  • CMS version: Joomla 2.5.x
Re: Trying to write a Sagepay Forms Payment processor - advice needed
August 01, 2009, 01:25:21 pm
Thanks for your various replies. I have to admit that because we use Sagepay Forms with our current online system I assumed we had to use them again. I'll check with our treasurer though, what our account with Sagepay is as it may be that we can use whichever variant we like. Note, though, that we cannot take payments or credit card details on our own site (shared hosting, shared SSL etc) which I think the server protocol requires.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trying to write a Sagepay Forms Payment processor - advice needed
August 05, 2009, 01:03:12 am
I don't think using server requires ssl - the credit card data is still entered on the SAGE pay site.

You set up the transaction with their site using HTTPS prior to re-directing the customer but you only need CURL on your site (which is already there with CiviCRM) - the encryption for the communication between your site & SAGE's is encrypted by virtue of their SSL certificate.

Note that you do need a static IP & to configure it in your account at Sage
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Parvez

  • I post occasionally
  • **
  • Posts: 91
  • Karma: 7
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 02, 2009, 07:12:36 am
Hi

Have you got any further with this?

We may be able to help and conrtibute back as we need to create an interface with ProtX for a client we're working with.

Thanks

Parvez

EdP

  • I post frequently
  • ***
  • Posts: 260
  • Karma: 7
  • CiviCRM version: 4.4
  • CMS version: Joomla 2.5.x
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 02, 2009, 12:27:13 pm
I did start, but to be honest I got a bit dispirited by how difficult it was to find the documentation about how to do it - although the help on the board was exemplary. In the end I spoke to our treasurer about what we were going to do and she told me that she was planning to move away from Sagepay anyway, so I've just let the problem lie for the time being until she decides what she will do next.

Parvez

  • I post occasionally
  • **
  • Posts: 91
  • Karma: 7
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 02, 2009, 01:35:25 pm
ok, I've started the process and will be getting the integration to work with the server version of Sage Pay. Will update this post when done, have got the PHP kit downloaded and am in the process of using the Paypal integration as a basis for the server integration.

Parvez

  • I post occasionally
  • **
  • Posts: 91
  • Karma: 7
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 03, 2009, 05:21:58 am
Made some progress with this but need some guidance for the next steps.

Based on previous posts have used the Server integration method.
Have got it to the stage, using Paypal as cloned codebase, where the request is being posted successfully to the Sage Pay servers and the user is being redirected to the payment page.

Need to do the following and could do with pointers on if its been done before, where to look for code snippets etc.

1. Sage Pay responds with a unique transaction when the first submission is made, it also supplies the URL to send the user to for payment at this point. At the moment I'm not doing anything with this information but I'm guessing what I need to do is update the contribution record with this reference. Any tips or code snippets on how to do this?

2. Once the end user has completed their payment details and Sage has processed them it posts back the results to CiviCRM for verification i.e. the unique transaction reference etc. What Civi needs to do is process this request and respond back with a URL to redirect to which Sage will then do. I have no idea how to do this in Civi or if there is another code base to use to find examples.

Any direction would be appreciated, this is one of our first (of many I hope!) contributions we'd like to make back to the community and any guidance would be much appreciated. Even if its just pointing me in the direction of code I'm more then happy to have a look and pull out the bits that are of interest!

Thanks

Parvez

Parvez

  • I post occasionally
  • **
  • Posts: 91
  • Karma: 7
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 03, 2009, 09:16:47 am
Final update for the day!

Decided not to use the Sage Pay transaction ref at this point i.e. on handshake I will not be updating the contribution record yet. I may do this as an enhancement later down the line but seeing as the invoice id is unique anyway I'll use this instead.

So, I have the contribution page carrying out the handshake to Sage Pay.
CiviCRM redirecting the client to the Sage Pay pages
Sage pay completing and requesting an update to the contribution much like the Paypal IPN code

This is where there is a difference. Sage Pay is expecting the processing to respond back to Sage Pay with some information i.e. the Status, RedirectURL, StatusDetail. Its only when Sage Pay gets this info does it actually redirect back to CiviCRM. So, anyone know how to do this in CiviCRM?

The example PHP code they supply does this (after checking and updating all the relevant tables in their example)

Code: [Select]
ob_flush();
header("Content-type: text/plain");
echo "Status=INVALID" . $eoln;

/** Only use the Internal FQDN value during development.  In LIVE systems, always use the actual FQDN **/
if ($strConnectTo=="LIVE")
echo "RedirectURL=" . $strYourSiteFQDN . $strVirtualDir . "/orderFailed.php?reasonCode=002" . $eoln;
else
echo "RedirectURL=" . $strYourSiteInternalFQDN . $strVirtualDir . "/orderFailed.php?reasonCode=002" . $eoln;

echo "StatusDetail=Cannot match the MD5 Hash. Order might be tampered with." . $eoln;
exit();

Any help would be appreciated!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 03, 2009, 12:09:54 pm

hey parvez

might be easier to chat about this on IRC. is this the right flow:

1. CiviCRM sends a GET request to sage with ??? information. Sage responds with a URL and a unique transaction ID

2. I would store the transaction ID in civicrm_contribution as trxn_id

3. CiviCRM redirects to SAGE to the above URL.

4. When Sage is done, its calls a CiviCRM URL (put this in the bin/SagePayInterface.php directory). The question is what info does SagePay call you with, can this URL be dynamic. For paypal we construct a dynamic URL and send it over

5. How does Civi know about status/status detail? seems like sage pay does the processing and should know it?

is there a brief description of this on the sage pay website that we can quickly look thru

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Parvez

  • I post occasionally
  • **
  • Posts: 91
  • Karma: 7
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 03, 2009, 12:27:07 pm
Hi Lobo

How are you? Good to hear from you!

1. CiviCRM sends a GET request to sage with Huh information. Sage responds with a URL and a unique transaction ID
Not quite. I've got CiviCRM posting out to Sage Pay. Sage Pay returns a MD5'd string which is the handshake security key.

2. I would store the transaction ID in civicrm_contribution as trxn_id
I'm stoing the resultant transaction ID into this field, not the security key.

3. CiviCRM redirects to SAGE to the above URL.
Yes.

4. When Sage is done, its calls a CiviCRM URL (put this in the bin/SagePayInterface.php directory). The question is what info does SagePay call you with, can this URL be dynamic. For paypal we construct a dynamic URL and send it over.
Have done this. Yes, the URL is dynamic and contains information that was sent out in step 1, effectively the notify URL. Its also at this point that the status of the transaction is exposed to Civi in the call. I've got it so that Civi is updating the relevant details, as it does with Paypal.

5. How does Civi know about status/status detail? seems like sage pay does the processing and should know it?
See above.

This is the stage that I've got to. Sage Pay expects some information presented back from its post to CiviCRM with the results of the transaction, effectively to let it know that we received the information ok and where to go next.

This is the point that I'm stuck at - does Paypal also do this?

Thanks

P.S - I dont have an IRC client at the moment.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 03, 2009, 02:52:58 pm

PayPalIPN does make a callback when the transaction is complete (its asynchronous, so does not involve the user). It also does not expect a response

but the code PayPalIPN.php can be easily modified to provide a response if so desired. So i think modifying the script to provide a response in the expected format should not be too hard

You can use your browser as an IRC client. There is an IRC link in the menu bar at the top of every page

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Trying to write a Sagepay Forms Payment processor - advice needed
September 03, 2009, 05:16:24 pm
Hi, I think the PaymentExpress code might be a bit more generic - I based it on the paypal code but there were some paypal specific things in there so you may find it a more helpful base
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Trying to write a Sagepay Forms Payment processor - advice needed

This forum was archived on 2017-11-26.