Despite #2337561: Add an alter data hook to all Paypal Payment methods requesting a hook for all payment methods that issue seems to have been closed after only providing a hook for PPS.

It would be good if we could also have a hook to alter the NVP requests that the EC method uses so that we can make use of NVP fields such as PAYMENTREQUEST_n_NOTETEXT.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

morbiD’s picture

Status: Active » Needs review
FileSize
2.43 KB

How does this patch look?

The only thing I wondered about is whether it matters which function called paymentNVP(). If somebody implementing the hook needs to know whether the request is a setExpressCheckout() or a doExpressCheckoutPayment() then the hook would need to be supplied with some context about that, or perhaps there should be separate hooks for each request function?

morbiD’s picture

I realised the hook parameters were the wrong way round. The drupal_alter() documentation specifies that the data to be altered should come first with context items afterwards.

Amended patch attached.

I think the PPS hook added in #2337561: Add an alter data hook to all Paypal Payment methods actually has the same problem should you wish to correct it (not that it makes any practical difference).

morbiD’s picture

I did some further work to split this out into separate hooks since there are differences in the NVP field specifications for SetExpressCheckout and DoExpressCheckoutPayment, plus I added links to PayPal's NVP field documentation in my hook documentation.

I also decided to pass a cloned $payment object to the hooks so that hook implementations can't modify the original payment object.