-
Notifications
You must be signed in to change notification settings - Fork 67
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
A more versatile solution to field naming #149
Conversation
Looks good, but we'd need some way to get the fields mapped to their respective Omnipay parameters. The Omnipay parameters are named Example: The shop module just uses the |
Any suggestions? :) |
The validator field names could also be wrapped in $fieldFactory = GatewayFieldsFactory::create();
RequiredFields::create($fieldFactory->getFieldNames([
'type', 'name', 'number'
])); Then the required-fields instance would be initialized with the correct field names… To normalize data for a gateway, maybe a method |
@bummzack Where would said |
I don't see too much problems with altering silvershop, since these are internals and don't affect the public API. Also, the default configuration should not change any form-fields, so unless a user configures special field-names for omnipay, everything will behave as it did previously. Candidates for |
Excellent, will submit a new PR soon / tomorrow |
…e the effects of custom field name support
You can comment out the entire |
Thanks for all the work you're putting into this. I really don't agree with having test-data in the actual methods though… you can just use the config API in your tests to test different configurations, eg. in your test, do this: Config::inst()->update('GatewayFieldsFactory', 'rename', [
'prefix' => 'prefix_',
'name' => 'testName',
'number' => 'testNumber',
'expiryMonth' => 'testExpiryMonth',
'expiryYear' => 'testExpiryYear'
]); |
Happy to help :) and I did feel weird putting it in there to be honest haha. (I only started with SilverStripe a couple months ago) |
Thanks! |
It seems, that rules are generally not merged. So if I have: GatewayFieldsFactory:
rename:
prefix: 'global_'
name: 'globalName'
number: 'globalNumber'
Stripe:
prefix: 'stripe_'
cvv: 'stripeCVV' And I use the
And with
Not sure, if this is what a developer might expect? My first assumption was, that the global config would be global and could be overridden with specific configurations. So if there was a field that's not defined for the gateway, it would fall back to the global one:
What's really confusing here is the prefix and name mixing though… So, to bring this one to a conclusion: Do we need both, a prefix and individual renaming options? It might be sufficient to just have a prefix, maybe with the possibility to override the prefix on a per-gateway basis? |
I noticed another problem with converting the field-values back to their correct names. I've updated your I've pushed the changed test to my fork of the module: So, |
When looking through the current implementation I was also thinking about ways to improve readability and performance. I think Then field renaming would be as simple as looking up the field-name in the rename-map (if it exists) and prefix the name with the prefix… Reverting fields back should also be simpler than the current implementation, what do you think? |
This is indeed the intention and gateways should definitely be falling back to their global parents so will get this resolved. Though I didn't prepare for gateways themselves to have prefix, noted this is definitely a mistake and will get that implemented.
My reasoning was simply versatility, where one would be interested in just prefixing all fields, others may be interested in renaming specific fields, though this does seem a little convoluted and you have my vote for reducing functionality to purely prefix where the gateways prefix is prioritised
I'll take this into consideration during my edits to resolve the above |
Field renaming support :)
Let me know what you think