0

I have the following case:

  • If the user is in the UK, the server needs to validate the bank details as Account number and Sort code number
  • If the user is in France, the server needs to validate the bank details as IBAN and BIC numbers

So how would you design the API for this?

One idea is to add as part of the payload every option and a flag e.g.

{
  "iban": string,
  "bic": string,
  "accountNumber": number,
  "sortCode": string,
  "country": "UK"
}

In the validation function I would then write the code along the line of this pseudo code

if country is France
   throw error if accountNumber and sortCode are present
   throw error if iban and bic are not valid
   continue flow
if country is UK
   throw error if iban and bic are present
   throw error if accountNumber and sortCode are not valid
   continue flow

Any thoughts on this or any better approaches following best practises?

Thank you for your opinion

8
  • 1
    What does "I am in the UK" mean? Who or what exactly does "I" refer to?
    – bdsl
    May 6 at 10:25
  • read the rest of the question May 6 at 10:29
  • 1
    I read the whole question. But it wasn't clear whether "I" means the organisation running the server, or the authenticated user, or the owner of the bank account, or the bank account itself, or something else. I think the answer could be different depending what it means.
    – bdsl
    May 6 at 10:33
  • 1
    how about something like {"uk": {"accountNumber": string, "sortCode": string}, "fr": {"iban": string, "bic": string}}. At least I would probably not allow mixed bank info properties in a single bank account object. Maybe instead of keys "uk" and "fr" use "ibanBankAccount" and however that is called for uk. May 6 at 11:11
  • 2
    The you might use {"whatever-that-in-the-uk-is-called": {"accountNumber": string, "sortCode": string}, "ibanBankAccount": {"iban": string, "bic": string}} and for other countries also using iban you would reuse ibanBankAccount. And if there is coming in another option then just add "this-other-option" besides "ibanBankAccount". May 6 at 12:29

1 Answer 1

0

This is a business logic concern. “clean architecture”

In a typical "clean architecture" it would belong in the application layer.

Your API receives a request, it forwards the request to an application layer, the application layer responds by a result object that contains either success of failure. If failure, then you would include in your response object a list of validation messages. If success, then you would include in your response the result of your operation.

1
  • Hi Philip, thanks but I don't think that gives an opinion on the actual payload structure and validation May 6 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.