vendredi 19 avril 2019

I am refactoring payments module for my site. It has got many providers, modes and operation and they keep on adding. Need advice on its architecture

The payments module currently written uses if-else blocks to perform operations for different payments providers, payment modes, and operations. When there is a requirement to add another of these providers or modes or operation, people were just copying and pasting another else-if.

I am refactoring it by using commands for each operation for each provider. Say, a command for 'credit card authentication by some provider A' and a command for 'net banking sales by provider B' and so on.

But the problem is commands don't return values but i have made them do it. Now there is no strict type checking on the return types. In the service i am invoking commands from i have to do explicit typecasting, something like this:

PaymentCommand command = commandsManager.getFactory(emiScheme.getPaymentProvider().getCode())
                .create(PaymentActionEnum.EMI_SCHEME_VALIDATION.name());

        return (EmiSchemeValidationResult) command.execute(schemeValidationRequest);

Is it a legit side-effect of using commands here? Or should I use commands in some other way to return results? Or should i use something else to solve my problem?

Aucun commentaire:

Enregistrer un commentaire