-
-
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
WIP Multiple fixes/improvements to \Civi\Payment\PropertyBag #21527
Conversation
(Standard links)
|
// These lines are here (and not in try block) because the catch must only | ||
// catch the case when the prop is custom. | ||
$getter = 'get' . ucfirst($prop); | ||
if (!$this->getSuppressLegacyWarnings()) { | ||
CRM_Core_Error::deprecatedFunctionWarning( | ||
"get" . ucfirst($offset) . "()", | ||
"PropertyBag array access for core property '$offset'" | ||
); | ||
} | ||
return $this->get($prop, 'default'); | ||
return $this->$getter('default'); |
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.
Ensure that property "getter" is used instead of generic getter (so we don't skip special handling eg. default for getIsRecur()).
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.
Looks important. Could we have a test for this? Maybe add a case to
public function otherParamsDataProvider() { |
if (!$this->has('description')) { | ||
return ''; | ||
} |
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.
Add default for non "essential" property description = ''
There is no reason to fail if we don't have a description set. This makes it easier to use getDescription()
when filling parameter arrays without having to check it's set first.
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.
There is no reason to fail if we don't have a description set.
Says who? Can't the same be said of anything else, e.g. getBillingStateProvince ?
if (!$this->has('invoiceID')) { | ||
$this->set('invoiceID', $label, md5(uniqid(mt_rand(), TRUE))); | ||
} |
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.
Add default for invoiceID - generate per CiviCRM core if not defined - makes invoiceID generation consistent if using propertyBag for payment and does not rely on calling code to make sure it has been generated. Calling code can generate if it wants to.
This is a property that is generated by calling code in various places using the same logic. In many cases it is not actually used at all and this reduces coding requirements when submitting payments using propertyBag because it will always have a default if not set manually.
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.
Hmmm. The purist in me thinks this is problematic, along the lines of: PB is supposed to ensure well-formed, structured inputs, not to generate content, defaults or default-providers.
I can see that it's a handy place to put in a shortcut though and can't bring to mind any practical problems it would cause. I suppose it feels wrong though if you had code like:
pseudo code:
$someParams = ['this' => 'that'];
$pb1 = PropertyBag::from($someParams);
$pb2 = PropertyBag::from($someParams);
// You should expect pb1 == pb2 but it's not:
$this->assertEquals($pb1->getInvoiceID(), $pb2->getInvoiceID());
Or maybe:
// Civi core something
$contrib = creatependingcontrib();
$pb = new PropertyBag();
$pb->setBlah('blah');
$processor->doPayment($pb);
// in the processor:
callThirdPartyApi([
'amount' =>$pb->getAmount(),
'ourRef'=> $pb->getInvoiceID(),
]);
// Civi core
// ...
i.e. core has not set an invoiceID; the processor created one and sent it to a third party but then did not write it to the Contribution.
I'd be happier with this function somewhere else. e.g. a generateNewInvoiceID() in the Contribution BAO or something - so we're explicit when we're generating it.
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.
↑ maybe a PropertyBag->generateInvoiceID()
would be better, then it's explicit when it gets created.
2879e80
to
250864c
Compare
@artfulrobot I've pulled out the more straightforward stuff into #21583 |
250864c
to
b6e0289
Compare
Overview
billingStateProvince
and getter/setter which is required for full billingAddress coverage.getIsRecur()
).description
= ''invoiceID
- generate per CiviCRM core if not defined - makes invoiceID generation consistent if using propertyBag for payment and does not rely on calling code to make sure it has been generated. Calling code can generate if it wants to.Before
Missing functionality and some bugs
After
More functionality and less bugs
Technical Details
Comments