Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

mattwire
Copy link
Contributor

Overview

  • Map additional legacy params to propertyBag standard params.
  • Add in billingStateProvince and getter/setter which is required for full billingAddress coverage.
  • Ensure that property "getter" is used instead of generic getter (so we don't skip special handling eg. default for getIsRecur()).
  • For billing address fields make sure we actually return the "new"/propertyBag name if we have a legacy property.
  • Add default for non "essential" property description = ''
  • 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.

Before

Missing functionality and some bugs

After

More functionality and less bugs

Technical Details

Comments

@civibot
Copy link

civibot bot commented Sep 18, 2021

(Standard links)

@civibot civibot bot added the master label Sep 18, 2021
Civi/Payment/PropertyBag.php Outdated Show resolved Hide resolved
Civi/Payment/PropertyBag.php Outdated Show resolved Hide resolved
Comment on lines +187 to +196
// 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');
Copy link
Contributor Author

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()).

Copy link
Contributor

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() {
(I think)?

Civi/Payment/PropertyBag.php Outdated Show resolved Hide resolved
Comment on lines +759 to +761
if (!$this->has('description')) {
return '';
}
Copy link
Contributor Author

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.

Copy link
Contributor

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 ?

Comment on lines +849 to +851
if (!$this->has('invoiceID')) {
$this->set('invoiceID', $label, md5(uniqid(mt_rand(), TRUE)));
}
Copy link
Contributor Author

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.

Copy link
Contributor

@artfulrobot artfulrobot Sep 18, 2021

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.

Copy link
Contributor

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.

@mattwire
Copy link
Contributor Author

mattwire commented Sep 23, 2021

@artfulrobot I've pulled out the more straightforward stuff into #21583

@mattwire mattwire changed the title Multiple fixes/improvements to \Civi\Payment\PropertyBag WIP Multiple fixes/improvements to \Civi\Payment\PropertyBag Feb 17, 2022
@mattwire mattwire marked this pull request as draft February 17, 2022 23:48
@mattwire mattwire closed this May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants