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,