I'm creating an interface to allow switching between various direct debit providers.
I've hit a stumbling block with the way that they / SOAP APIs require the updating of a record, they require you to pass in the whole object rather than just update a single value.
The issue here is that the different API's use different names for their fields, take the following example:
$directDebitInterface->updateAccount($reference, [
'AccountName' => 'NEW ACCOUNT NAME',
]);
Now, the current direct debit provider uses 'AccountName' but another references 'AccountHolderName'.
If I'm passing in the field to be updated but I don't know which provider I'll be interfacing to, how do I know which field to map this to?
Is there a technique that maps the field names for each provider?
My first thought is to use constants in each provider's class that inherits the interface (what is the name for that btw?)
E.g.
Provider 1
const ACCOUNT_NAME = 'AccountHolderName';
public function update($newValue)
{
// logic to post, pseudo array
[
self::ACCOUNT_NAME => $newValue
]
}
My issue now comes down to how to pass in the correct field as it ends up the same issue, I'll need to create some sort of mapping between what I call a field and how it is on the provider's end.
Thanks,
You should stick to one name in your code base. The communication to the external entity (direct debit provider) should be in one class per provider, and those classes need to implement an interface so it doesn't matter in the rest of the code which class is actually used.
The connector class (or whatever you want to call it) needs to do the mapping from your naming scheme to the scheme of the external party when sending data, and back when receiving data. The naming scheme of the external party should not leak into the rest of your code.