-
-
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
Add Payment PropertyBag for payment processor method arguments #15697
Add Payment PropertyBag for payment processor method arguments #15697
Conversation
(Standard links)
|
test this please |
@artfulrobot you will need to rebase your branch as
|
I don't understand why the tests are failing - is this me or something outside of me? There's no logs when you click the details links! |
@artfulrobot it can't apply the PR ontop of master that is why it is failing |
@seamuslee001 interesting. Applies FF for me:
any ideas? |
@artfulrobot i would try when your on |
242de3b
to
93c01ec
Compare
CRM/Core/Payment.php
Outdated
} | ||
|
||
/** | ||
* Get payment instrument id. | ||
* Legacy wrapper. Better for a method to work on its own PropertyBag. |
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.
@artfulrobot we don't need to add the legacy wrappers back in now do we? I mean they are wrappers that never were from a release POV
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.
@eileenmcnaughton do you ever sleep?! isn't it 4am where you are?!
Ah, that's interesting. See the ones that are left are ones that weren't added by the commit you reversed. So I left them in. Some of them work a bit weird.
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.
Sleep not so good tonight....I'm pretty sure I DID add getContactID
Updated status to WIP - I lost loads of code doing the rebase. Trying to play catchup. |
@eileenmcnaughton @artfulrobot It would be nice to see this in 5.20 as there's lots of payment related changes there. But perhaps we can merge early in the RC rather than rushing this or delaying to 5.21. As far as I can tell this will be an "optional" feature initially that processors can use (ie not going to break anything existing) and the sooner it's available the better! |
In theory yes, although until I get all tests passing I live in fear of it causing grief. |
Just FYI: I've had to stop work on this because everything is against me. First the power cut, then the router, now buildkit won't ... you know build ... so I don't have a working dev env any more. If anyone has any advice on this buildkit bug pls ping @artfulrobot on MM. |
@artfulrobot I had decided this would miss 5.20 & we should maybe prioitise getting it right over the next couple of weeks. Basically my civi priorities over the next 2 weeks are this, any 5.19 regressions & chipping away at #15706 |
@eileenmcnaughton good call, this isn't nearly ready. I've got buildkit reinstalled now (thanks to recent core fix by Tim) but the normal Civi tests won't run now because of |
1ffe98d
to
996ea35
Compare
OK, I'm back up and running. I think I've fixed the un-passing tests. Notes:
|
done rebase |
4c8cccc
to
efa589c
Compare
Small aside (and not to increase the pressure...)... when you get past the WIP stage, I'd encourage a think on the comms ( |
9b188de
to
f2dd7b2
Compare
WIP: proof of concept for payment property bag WIP: keep civilint happy WIP: keep civilint happy again Add other getters, setters, tests Add require() method and test some wip code linter fixes remove :void from function declaration in Civi/Payment/PropertyBag fix PropertyBagTest.php tests fix linter Re-do payment code lost in rebase linting fixes More WIP on payment property bag one day i'll run civilint before committing WIP checkin Correct test which referred to Credit card instead of Credit Card causing a fail with new property bag which is stricter Payment PropertyBag: allow week as recurFrequencyUnit; accept ZLS for feeAmount for legacy sake CRM_Core_Payment: remove stuff cut from release remove test no longer needed remove un-needed code because feature dropped before it was released remove comment Remove/disarm payment instrument setter restore getPaymentInstrumentID behaviour remove not required function set x
f2dd7b2
to
47c9685
Compare
Assuming the tests pass, I'll remove the WIP from this and update the description as @totten suggests, along the lines of:
|
@artfulrobot sounds good to me - we need some best practice recommendations in the PR template and / or docs |
4fbf25a
to
b76a6ec
Compare
I've updated the PR description at the top. I propose that (tests allowing) this gets merged and we move on to implementing PropertyBag in a new PR. |
I'm going to merge this because I think it provides us with a good basis for improving our code. I'm still not entirely comfortable with the custom properties portion but I think if we can mark that as 'experimental' in the docs we can work through that with this code merged over the next little bit |
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
…n get a fatal We added the new property bag in civicrm#15697 but in the back & forth the call to the function getDescription was retained but the function was removed. This would leave the core processor that calls it (Paypal std) with a fatal. The known external processor using it (Omnipay) also hits a notice because the signature changed ($params became optional). From the Omnipay pov I think it makes sense just to stop overriding the function - hence I am sneaking a tiny change into this to make that possible. Note the doPayment function ensures that propertyBag is set. There is a small chance that an external processor is fully overriding doPayment AND calling this - that would be the case for Omnipay except I'll remove the override in conjunction with this - so I've added a few lines to ensure it is set. Note the test would fail with the changes to Payment_Dummmy & not the changes to Core_Payment so it provides test cover
Summary
Below is a long thread that nobody should have to suffer, and also see https://lab.civicrm.org/dev/financial/issues/82 but I've edited this description as a PR summary/overview.
This PR adds a new class,
Civi\Payment\PropertyBag
which will eventually replace the wild$params
array that gets thrown at payment processors, with a standardised, at least minimally validated and type cast object. It has a test class, too, and is designed for backwards compatibility with older processor code that expect arrays as inputs.This PR only actually uses this class in one very minimal way at present (to validate currencies), and as such it should not cause any grief or changes to UI/UX or APIs, but it paves the way for a bigger PR to follow.
The rest of the PR is comment updates.
I am working on documentation, but that can't really come out until the PropertyBag is properly used in core, but here's a static copy of that draft documentation to give you an idea of what the problem is and why we solved it this way. again, note that the stuff below can't happen until more changes are made in core, which are out of scope for this PR.
Introducing
PropertyBag
objectsCurrently as of 5.19
$params
is a sprawling array with who-knows-what keys. From 5.xx, a better way is to pass in aCivi\Payment\PropertyBag
object instead.This object has getters and setters that enforce standardised property names and a certain level of validation and type casting. For example, the property
contactID
(note capitalisation) hasgetContactID()
andsetContactID()
.For backwards compatibility, this class implements
ArrayAccess
which means if old code does$propertyBag['contact_id'] = '123'
or$propertyBag['contactID'] = 123
it will translate this to the newcontactID
property and use that setter which will ensure that accesing the property returns the integer value 123. When this happens deprecation messages are emitted to the log file. New code should not use array access.Checking for existence of a property
Calling a getter for a property that has not been set will throw a
BadMethodCall
exception.Code can require certain properties by calling
$propertyBag->require(['contactID', 'contributionID'])
which will throw anInvalidArgumentException
if any property is missing. These calls should go at the top of your methods so that it's clear to a developer.You can check whether a property has been set using
$propertyBag->has('contactID')
which will returnTRUE
orFALSE
.Multiple values, e.g. changing amounts
All the getters and setters take an optional extra parameter called
$label
. This can be used to store two (or more) different versions of a property, e.g. 'old' and 'new'This means the value is still validated and type-cast as an amount (in this example).
Custom payment processor-specific data
Sometimes a payment processor will requrie custom data. e.g. Stripe may use a
paymentMethodID
and apaymentIntentID
on itsdoPayment()
method.Property names should be prefixed, e.g.
stripe_paymentMethodID
and set usingPropertyBag->setCustomProperty($prop, $value, $label = 'default')
.The payment class is responsible for validating such data; anything is allowed by
setCustomProperty
, includingNULL
.Where support for custom properties is needed for a method, e.g.
doPayment()
, you should implement a method as follows: