CreditCardInfo creditCard = value.credit_card;
CardValidator cardValidator = new (creditCard.credit_card_number, creditCard.credit_card_expiration_year,
creditCard.credit_card_expiration_month);
CardCompany|error cardValid = cardValidator.isValid();
if cardValid is CardValidationError {
log:printError("Credit card is not valid", 'error = cardValid);
return cardValid;
} else if cardValid is error {
log:printError("Error occured while validating the credit card", 'error = cardValid);
return cardValid;
}
The following isValid() method returns CardCompany|error. It should be renamed to something like getCardDetails().
CardCompany|error cardValid = cardValidator.isValid();
Btw, the usage of a class does not make sense here.
See this code snippet: https://github.com/ballerina-guides/gcp-microservices-demo/blob/main/payment/payment_service.bal#L37
The following
isValid()
method returnsCardCompany|error
. It should be renamed to something likegetCardDetails()
. CardCompany|error cardValid = cardValidator.isValid();Btw, the usage of a class does not make sense here.