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) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • How to set IPN callback for extensions?
Pages: [1] 2

Author Topic: How to set IPN callback for extensions?  (Read 4889 times)

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
How to set IPN callback for extensions?
September 13, 2011, 09:55:19 pm
I'm looking to bundle a processor we've been using for a while (Flo2Cash) as a pair of extensions (for three- and two-party versions).

But I don't see how IPN works yet. How do I provide an IPN callback from my extension? Will CiviCRM direct the IPN call to the extensions directory?

I've had a test with the Google Checkout extension (to enable which I had to remove the default version from the DB), but it doesn't seem to reference googleNotify.php in the extension code, and Google doesn't call the IPN (notify) file after I transact.

Pointers welcome!

Thanks
@xurizaemon ● www.fuzion.co.nz

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: writeable, executable, accessible extensions directory
September 14, 2011, 12:22:02 pm
OK, so Google's IPN needs configuration in the merchant admin. Thanks Donald for the reminder :)

I might have missed something here ... first time I've played with extensions.

As far as I can tell, the CiviCRM extensions directory is intended to be writeable to your webserver, so that extensions can be retrieved and installed automatically. But the extensions dir may also contain IPN callback files, and this combination rings alarm bells for me - executable code in a webserver-writeable directory.

It means there's a place where any exploit of the webserver can store and execute code later. Generally I use Apache's sethandler to prevent execution in any directory which the webserver may write to for this reason.

I can live without CiviCRM being able to install extensions itself. But I wonder if we can find a way to do this which doesn't mean CiviCRM is encouraging writeable, executable directories.

If extensions can add their own callback paths to CiviCRM (eg: ?q=civicrm/googleNotify or ?q=civicrm/ipn/PayPal) then we can handle this in the extension. That way the extensions directory could include PHP classes only, and we can prevent exec entirely via sethandler.
« Last Edit: September 14, 2011, 04:24:43 pm by grobot »
@xurizaemon ● www.fuzion.co.nz

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How to set IPN callback for extensions?
September 14, 2011, 01:43:56 pm
Hmm - I thought the key idea behind extensions was handling the extern folder. My understanding is that Lobo was keen to stop accepting payment processors into core & a cunning plan was hatched that would prevent us from whinging about them breaking every upgrade. The ipn files were always the main problem as the custom php directory was adequate for the other files.  I guess they still are
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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: How to set IPN callback for extensions?
September 14, 2011, 03:46:33 pm
As I said ... it's possible I'm missing something. I had a go with the PayFlow extension as well, but it looked like it was going to take a bit of work before I'd be able to test out IPN there either.

Two ideas on how extensions might remove the need for adding separate scripts to the extern/ folder -

  • Allow extensions to provide custom callbacks, eg ?q=civicrm/googleNotify style. This offers a lot more flexibility for extensions generally, and it's quite possible this is already available but I haven't found it yet.
  • Create an IPN interface which payment processor extensions can implement (eg defined method like CRM_Core_Payment_myprocessor::handleNotify()), and have CiviCRM expose ?q=civicrm/notify which the processor would call with a parameter to specify the appropriate class to call that method in (?q=civicrm/notify&processor=myprocessor&blah=blah).

But if what you say is true, I expect there's already a means to work around the issue I'm having. And *maybe* it's one of the above! I'll go re-read the "implementing a payment processor extension" page again :D
« Last Edit: September 14, 2011, 04:20:32 pm by grobot »
@xurizaemon ● www.fuzion.co.nz

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Bootstrapping CiviCRM from IPN callbacks (a secondary issue)
September 14, 2011, 04:27:29 pm
There's a secondary issue with the current code, in that most of the IPN.php style implementations start with something like this -

Code: [Select]
<?php
session_start
( );
require_once 
'../../../civicrm.config.php';
require_once 
'CRM/Core/Config.php';

The above code won't work unless the extensions directory is in a specific location (inside the civicrm directory), placing googleNotify.php somewhere like modules/civicrm/[extensions]/org.civicrm.payment.googlecheckout/googleNotify.php - which means that a CiviCRM upgrade risks zapping the extensions folder.

If IPN callbacks are .php files in the extensions folder, those scripts each need to contain a method of discerning the correct CiviCRM module folder if the extensions folder is located anywhere else. Yuck.

If IPN callbacks are embedded in CiviCRM already (eg via one of the previous suggested methods), this problem is solved.
« Last Edit: September 14, 2011, 04:31:00 pm by grobot »
@xurizaemon ● www.fuzion.co.nz

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: How to set IPN callback for extensions?
September 14, 2011, 05:06:02 pm

u definitely should not place the extensions folder under modules/civicrm to avoid upgrade / delete issues

maybe the recommended place could be modules/civicrm.extensions

Since extension install / uninstall will not be too often, how about recommending that (if u have shell access)

1. People only make them web-writable when installing/un-installing an extension

2. if the extension directory is writable, we emit a warning on the admin page stating so

I think we might want to consider making the IPN part of the civicrm url structure (and this invoked via the CMS). This will solve the issue of: "where is the civicrm directory located etc"

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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: How to set IPN callback for extensions?
September 14, 2011, 05:56:54 pm
CiviCRM warns if the extensions directory is not writeable for the webserver, and it looks like there is code to automatically retrieve extensions from extdir.civicrm.org. Requiring shell access to enable/disable easy installation of extensions seems like a step backwards - "here's a nice GUI, but before using it ..."

Agreed that nothing should go in modules/civicrm - I was flagging that the current org.civicrm.googlecheckout example processor seems to expect a specific location under there for googleNotify.php.

We generally install CiviCRM something like this -

Code: [Select]
sites/all/modules/contrib/civicrm/               base civicrm code, typically in 'contrib' subdir unless patched

sites/example.org/civicrm/
                          custom_tpl             site-customised code which may be executed, read-only for webserver
                          custom_php             

sites/example.org/files/civicrm/                 non-executable files, writeable for webserver
                                custom
                                persist
                                templates_c
                                upload

The idea behind this layout is:
  • modules go in modules/ and are sorted into contrib, custom or patched
  • only one directory, files, is writeable to the webserver, and it has execution disabled
  • custom code lives in the site dir; it's executable so it's read-only for www

If CiviCRM wants to install extensions, which requires write access, then by the above model extensions go to files/civicrm for write access.

In the files directory, Drupal's SetHandler fix for SA-2006-006 will prevent .php files in extensions directories from being writeable.

I don't see a way we can site webserver-writeable, executable code in an accessible directory and not have it be a security concern (please do try to convince me if you think I'm wrong).

I believe we need CiviCRM to provide a means for extensions to expose IPN functionality. I've opened this as: http://issues.civicrm.org/jira/browse/CRM-8872
« Last Edit: September 14, 2011, 06:08:20 pm by grobot »
@xurizaemon ● www.fuzion.co.nz

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: How to set IPN callback for extensions?
September 15, 2011, 04:56:43 am
Wow, tons of great thinking in this thread. :-)

From what I remember, original idea was to have an extern/ script, which would be always called by payment processor with a parameter identifying its type - so practically the same as you propose (not counting your improvement around IPN interface). I even thought it was actually implemented, but from quick look at the repository code, I don't see it anywhere. There were three of us digging around "extensioning" payment processors and it was during code sprint, so maybe this part slipped somewhere in between conversations/work division.

I would love to take a closer look at this as soon as possible, but I'm a bit behind with projects and need time until end of this week to catch up. Seems like I have raising queue of extensions issues (which means more people start using them, hurray) and plan to spend some uninterrupted time on fixing problems/introducing improvements at the beginning of next week. Part of that would be checking what's going on with IPN thingy and making it work.

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How to set IPN callback for extensions?
September 15, 2011, 12:18:01 pm
Code: [Select]
Wow, tons of great thinking in this thread. :-)
Chris - I think you just got an endorsement for talking to yourself  ;D
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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: How to set IPN callback for extensions?
September 15, 2011, 06:05:43 pm
Thanks. I like to call it "peerless programming" when I'm yakking away to myself in public.

OK, so accepting that this not yet available in 3.4/4.0, I've done a couple of things -

In Flo2CashDonate class, I've added a paymentNotify() method which is really just a wrapper for Flo2CashDonateIPN::main(). I think we want to have this go via the processor, so CiviCRM has a clean interface against the payment processor rather than expecting a second file with magic 'IPN' suffix.

I'd love to talk further about whether we can / should standardise such a method for payment processors to implement. Eileen I think I saw in PayFlow that you had different notification handler for single and recurrent contribs, for example?

Here's what I've kicked off with anyway - a two-line wrapper ;)

https://github.com/GiantRobot/nz.co.giantrobot.flo2cashdonate/blob/master/Flo2CashDonate.php#L276

Also, in the processor's __construct(), I added a check to see if the notify handler has been copied to extern/ ... This means admins will get a pointer in the right direction, at least until we handle this better. I was expecting this would trigger a warning on the payment processor notification page, but seems it only does it on the actual contribution page (and again in demo mode). Warning is for admin eyes only.

https://github.com/GiantRobot/nz.co.giantrobot.flo2cashdonate/blob/master/Flo2CashDonate.php#L81

Keen to discuss the best way to add a handler eg: civicrm/paymentnotify which we can use to fire the paymentNotify() method in the relevant extension as well.
« Last Edit: May 20, 2012, 12:19:26 am by grobot »
@xurizaemon ● www.fuzion.co.nz

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How to set IPN callback for extensions?
September 15, 2011, 08:31:56 pm
If you stuck a generic paymentnotify handler in the extern how would it know which processor type was calling it - they are all quite different - the buggers.
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

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: How to set IPN callback for extensions?
September 16, 2011, 03:00:48 am
"two ideas" here: http://forum.civicrm.org/index.php/topic,21543.msg90361.html#msg90361

Then sll the different parts sit inside ::paymentnotify()
« Last Edit: September 16, 2011, 03:03:36 am by grobot »
@xurizaemon ● www.fuzion.co.nz

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: How to set IPN callback for extensions?
September 16, 2011, 07:16:20 am
Quote from: Eileen on September 15, 2011, 08:31:56 pm
If you stuck a generic paymentnotify handler in the extern how would it know which processor type was calling it - they are all quite different - the buggers.

I think we'll go with Grobot's second proposal - unless PPs cannot handle callback url with params? (doubt it) - however, I do feel tempted to investigate custom callback option... :-)

Do you guys want to have quick IRC chat on Monday? :-)

m


Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

Chris Burgess

  • Ask me questions
  • ****
  • Posts: 675
  • Karma: 59
Re: How to set IPN callback for extensions?
September 16, 2011, 11:54:33 am
If someone has their heart set on combining a hosting environment without mod_rewrite/clean url support *and* a payment processor which doesn't handle params, they will need to use something like this f2c_ipn.php which is just a file wrapper for something::paymentNotify() anyway.
@xurizaemon ● www.fuzion.co.nz

RobertPattinson

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • moovieland
    • watch mission impossible 4 online
  • CiviCRM version: 3.4
  • CMS version: 4.0
  • MySQL version: 5.0
  • PHP version: 5.2.4
Re: How to set IPN callback for extensions?
December 01, 2011, 04:59:09 am

I can live without CiviCRM being able to install extensions itself. But I wonder if we can find a way to do this which doesn't mean CiviCRM is encouraging writeable, executable directories.

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • How to set IPN callback for extensions?

This forum was archived on 2017-11-26.