-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev/financial#33 Add in Hook postIPNProcess to allow Extensions to do c… #12928
dev/financial#33 Add in Hook postIPNProcess to allow Extensions to do c… #12928
Conversation
(Standard links)
|
@seamuslee001 we have some tests for alterPaymentProcessorParams in our suite - can we get a similar one for this |
Thanks @seamuslee001 for the new hook implementation. I have extension that does need to perform some validation and alter to ipn's $_REQUEST before they are processed. I used config hook as an alternate method but alterIPNData seems to be most generic. |
@eileenmcnaughton i have added in a unit test now |
CRM/Utils/Hook.php
Outdated
* @param array $IPNData - Array of IPN Data | ||
* @return mixed | ||
*/ | ||
public static function alterIPNData($IPNData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 did you missed & here or there is a reason you don't want to pass by reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At dev/financial/issues/33, @seamuslee001 writes
We could also ensure that the original data not get modified by not passing by reference so that the hook could only do its own processing without affecting the original data
The intention needs to be clarified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to pass by reference - a hook should be able to alter
@seamuslee001 Except for that minor change I mentioned on the patch, can you please submit a doc PR? against https://github.com/civicrm/civicrm-dev-docs |
CRM/Core/Payment/PayPalImpl.php
Outdated
@@ -745,6 +745,7 @@ public function cancelSubscription(&$message = '', $params = array()) { | |||
*/ | |||
static public function handlePaymentNotification() { | |||
$params = array_merge($_GET, $_REQUEST); | |||
CRM_Utils_Hook::alterIPNData($_REQUEST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to pass $params here not $_REQUEST
/** | ||
* Store Custom data passed in from the PayPalIPN in a custom field | ||
*/ | ||
public function HookCiviCRMAlterIPNData($data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trivial point - lower case h I think
extern/authorizeIPN.php
Outdated
@@ -38,6 +38,7 @@ | |||
|
|||
require_once '../civicrm.config.php'; | |||
$config = CRM_Core_Config::singleton(); | |||
CRM_Utils_Hook::alterIPNData($_REQUEST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should add hooks into these deprecated paths - there is some risk of them not working from previous nightmares with these bits of code so I'd rather not touch (also people should stop using them)
extern/ipn.php
Outdated
@@ -41,6 +41,7 @@ | |||
/* Cache the real UF, override it with the SOAP environment */ | |||
|
|||
$config = CRM_Core_Config::singleton(); | |||
CRM_Utils_Hook::alterIPNData($_REQUEST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also deprecated path
extern/pxIPN.php
Outdated
@@ -19,6 +19,7 @@ | |||
require_once 'CRM/Core/Config.php'; | |||
|
|||
$config = CRM_Core_Config::singleton(); | |||
CRM_Utils_Hook::alterIPNData($_REQUEST); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def deprecated - hopefully this processor is disabled on install
@seamuslee001 @mattwire I think we can call this hook (once only) from CRM_Core_Payment::handlePaymentMethod (somewhere after logPayment) - all the new style ipns hit that. It would be a little trickier for unit testing - but not unresolvable I'm sure |
@eileenmcnaughton @mattwire i have made the changes as has been requested, I have also managed to get the unit test updated for handlePaymentMethod. I have put the hook after the main processing so that there isn't any chance of issues being caused from the hook preventing normal processing of the IPN |
6c6b5e4
to
8fac610
Compare
@seamuslee001 so just working through this - it's not really an alterIPNData hook is it - it's basically a listener / post hook |
Yeh pretty much @eileenmcnaughton
…On Thu, 18 Oct 2018 at 5:20 pm, Eileen McNaughton ***@***.***> wrote:
@seamuslee001 <https://github.com/seamuslee001> so just working through
this - it's not really an alterIPNData hook is it - it's basically a
listener / post hook
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12928 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGe_FW1VX-gC9O6S2KpG5rZVIWPYyXkTks5umB3AgaJpZM4XYmsg>
.
|
@seamuslee001 should we rename it then? If the logNotification method called a hook then it would achieve the same thing but it doesn't from the looks |
@eileenmcnaughton maybe but I think we are still potentially altering data
or something? Maybe postIPNProcess instead?
…On Thu, 18 Oct 2018 at 5:27 pm, Eileen McNaughton ***@***.***> wrote:
@seamuslee001 <https://github.com/seamuslee001> should we rename it then?
If the logNotification method called a hook then it would achieve the same
thing but it doesn't from the looks
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12928 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGe_FVA1Yf9DsqLcB_VeqZXC6wpHoYafks5umB9JgaJpZM4XYmsg>
.
|
@seamuslee001 yeah I think that makes sense - we aren't altering the ipn data from what I can see - although we may take a data related action in the hook. I added a comment on gitlab - I think we should give people a chance to process that |
…ustom processing of the IPN Data Add in unit test of alterIPNData hook and ensure that it is called in all styles of IPN Notifications Shift hook call to be done in handlePaymentMethod function as per Eileen's comment and remove the hook from deprecated pathways and passbyrefeence in hook Change name to be postIPNProcess to be more explicit about the purpose of the hook
8fac610
to
2d39b9c
Compare
@eileenmcnaughton i have now updated the name of the hook (i'll change the PR title as well shortly) however i think we are now pretty much there right? |
Jenkins re test this please |
@seamuslee001 I know I'm late to that party on this one.... Agree with it being called postIPNProcess as it's not allowing anything to be altered. However, some IPN classes don't return, they call So I wonder if it makes sense to actually call the hook before processing the IPN, though we'd need to be sure any hook didn't block (as, for example, Sagepay requires a response to the IPN request within 1 second). On the other hand we are logging the IPN to systemlog anyway.. I'm just seeing an extension in my head that passes the IPN to another system or something (eg. an accounting system) which might be interested in that IPN even if CiviCRM fails to process it. |
@mattwire i think that should be the concern of another hook or at the very least an expansion of hook in terms of when it is processed. I think there could be opportunities to improve this but I don't think it should hold this up @eileenmcnaughton this PR has now been waiting for about a week since we made the change to the name, i note that i don't think anyone in the lab has objected to this and i'm not seeing Matt's comment as a blocker to this PR being merged thoughts? |
@seamuslee001 OK - I'll merge this - it will not be 100% reliable for the reason @mattwire mentions & I think calling a pre-hook when we log to the system log makes sense - but I think this also solves a need & should not add a mtce burden due to the tes |
@seamuslee001 can you address documentation for this - I just closed the issue |
@eileenmcnaughton yep about to work on it now |
…ustom processing of the IPN Data
Overview
This adds in a hook alterIPNData which would allow extension authors the ability to do custom processing on IPNs as they come in
Before
No Hook on the IPN data
After
Hook exists, meaning custom processing such as sending google analytics information based on the IPN data can occur
ping @eileenmcnaughton @monishdeb @johntwyman