-
-
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 billingStateProvince and standardized property names #21583
Conversation
(Standard links)
|
b678bfc
to
8b72c69
Compare
$newName = substr($prop, 0, -2); | ||
$billingAddressProp = substr($prop, 0, -2); | ||
$newName = static::$propMap[$billingAddressProp] ?? NULL; | ||
if ($newName === TRUE) { | ||
// Good, modern name. | ||
return $billingAddressProp; | ||
} |
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.
It turns out we already have good test coverage on this - if you add the properties without this change you get errors like invalid function getBilling_state_province
8b72c69
to
51bbea1
Compare
51bbea1
to
f7519c3
Compare
Merging per approval from @artfulrobot on #21527 |
I confess that the implications of the property bag are eluding me, but in my payment processor code for iats, I'm using code like this to convert params into something similar to pass off to the payment processor but with different array keys. I'd guess most payment processors have some similar code in them.
Since this patch breaks it, I'm guessing that the isset test has stopped working, and that there should be a different way of testing whether a property of params is set. What's the correct and backwards compatible way to replace this test? |
@adixon In short, the equivalent to your code would be: <?php
foreach ($convert as $r => $p) {
if ($params->has($r)) {
$request[$r] = htmlspecialchars($params->getter($r));
}
} An opinionionated view might be:
So, back to your code, let's assume that name, invoiceID, zip code and card details are required but all the other address details are not, it could be reworked like: <?php
/** @var \Civi\Payment\PropertyBag $params */
// The IATS processor always requires the following data; if we don't have that we cannot proceeed.
$params->require([
'firstName', 'lastName', 'invoiceID', 'billingPostalCode', /* Standardised properties */
'cvv2', 'credit_card_number' /* our custom properties */
]);
// Map the values we've got into IATS request format:
$mapIatsToPropertyName = [
'firstName' => 'firstName',
'lastName' => 'lastName',
'address' => 'billingStreetAddress',
'city' => 'billingCity',
'state' => 'billingStateProvince',
'zipCode' => 'billingPostalCode',
'country' => 'billingCountry',
'invoiceNum' => 'invoiceID',
'creditCardNum' => 'creditCardNum',
'cvv2' => 'cvv2',
];
$request = [];
foreach ($map as $iats => $propertyName) {
if ($params->has($propertyName)) {
$request[$iats] = htmlspecialchars($params->getter($propertyName));
}
} There was a big discussion about credit card details and whether they should be standardised fields or not. They're not, in the end (not common enough across processors).Though this being Civi, there never really is an 'end' ;-) What this means is that when property bag gets Ideally, custom fields should all be prefixed, e.g. Hope this is helpful. |
Thanks, super helpful! Opinionated is good! And thanks for spearheading the propertybag initiative! Aside from being too lazy to dig into documentation, my other concern was about backwards compatibility, i.e. at what core version can I start safely accessing params as a property bag? [Okay, not as lazy as I claimed, I see you posted the link and that it was 5.24 which seems reasonable to asssume in my next release!]. As an aside, my fear here is that there's too much magic. I kind of like when things were simpler. Magic is great when it works, and when it doesn't, trying to debug it makes my hair fall out. So any new magic should first of all assume that it might not work all the time and account for humans trying to figure out why (e.g. well documented debugging mechanisms all along the pathways ...). No reply required, this is just me thinking out loud. |
The magic is what we're moving away from. We're moving away from 'magic' that meant that 'contact_id', 'contactID' and 'contactId' all worked - if you were lucky., and that each payment processor chose a different version to rely on. The only remaining magic is explicitly for the purposes of backwards compat. You're not supposed to rely on the magic any more, hence all the very strict getters and setters. The best thing to do in your
as seen at https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Payment.php#L1366 And then work with that instead of The idea is that the UI (e.g. quickform) is decoupled from the payment system. So we can implement other payment UIs and still use Civi for processing them. Of course different processors place requirements on the UI and need different fields. e.g. you need This requires there to be a mapping from whatever the UI generates to what payment processors can work with. At the moment, it's assumed that |
Thanks for this. |
With specific decimal separator settings this pr causes contribution checksum link payments to fail: I opened up an issue for this: https://lab.civicrm.org/dev/core/-/issues/3413 |
@@ -26,13 +26,23 @@ class PropertyBag implements \ArrayAccess { | |||
|
|||
protected static $propMap = [ | |||
'amount' => TRUE, | |||
'total_amount' => 'amount', |
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.
This line may have caused a regression - https://lab.civicrm.org/dev/core/-/issues/3413 - it appears to be treating total_amount
as amount
when both are passed - I think this was probably done by accident since I think amount
was consolidated quite a long time ago
Just noting that this has been reported as causing a regression (per my comment above) - |
Overview
Extracted from #21527. These are the simple bits that have been approved by @artfulrobot
Before
After
Technical Details
Comments