public static string Authenticate(string CIF, AuthOptions transferAuth)
        {
            var profile = customerProfileService.GetCustomerProfile(CIF).Result;

            if (profile == null)
            {
                return("Unable to get customer profile");
            }

            if (profile.HasMessage)
            {
                return(profile.Message);
            }

            if (profile.Data.IsPinBlocked)
            {
                return("PIN BLOCKED");
            }
            if (AuthenticationType.Pin == transferAuth.AuthenticationType)
            {
                var authResponse = customerProfileService.VerifyPin(profile.Data.ProfileId, transferAuth.PIN).Result?.Data;

                if (authResponse == null)
                {
                    return(AirtimeValidationMessages.ErrorMessages.PinAuthenticationFailed);
                }

                if (!authResponse.Status)
                {
                    return(authResponse.Message);
                }

                if (authResponse.Status)
                {
                    return(AirtimeValidationMessages.ConstantMessages.AuthenticationSuccessful);
                }
            }
            else if (AuthenticationType.PinAndOtp == transferAuth.AuthenticationType)
            {
                return(AirtimeValidationMessages.ConstantMessages.AuthenticationSuccessful);
            }
            else if (AuthenticationType.PinAndBiometrics == transferAuth.AuthenticationType)
            {
                return(AirtimeValidationMessages.ConstantMessages.AuthenticationSuccessful);
            }
            return(AirtimeValidationMessages.ErrorMessages.AuthenticationFailed);
        }
Esempio n. 2
0
        public async Task <IActionResult> GetMomoFees([FromBody] FeesRequestDto payload)
        {
            if (payload == null)
            {
                ModelState.AddModelError("fees", "The fees request cannot be blank");
                return(BadRequest(Responses.ErrorResponse <FeesResponseDto>(ModelState.ToErrors(), StatusMessage.ValidationErrors, ResponseCodes.VALIDATION_ERRORS)));
            }

            var feesValidator = new FeesRequestValidator();

            feesValidator.Validate(payload).AddToModelState(ModelState, null);
            if (!ModelState.IsValid)
            {
                return(BadRequest(Responses.ErrorResponse <FeesResponseDto>(ModelState.ToErrors(), StatusMessage.ValidationErrors, ResponseCodes.VALIDATION_ERRORS)));
            }

            var phone = payload.MomoPhoneNumber.AsPhoneNumber();

            if (phone == null)
            {
                ModelState.AddModelError("phone", "The phone number is not valid");
                return(BadRequest(Responses.ErrorResponse <FeesResponseDto>(ModelState.ToErrors(), StatusMessage.ValidationErrors, ResponseCodes.VALIDATION_ERRORS)));
            }

            var accountId = UserHelper.GetAccountId(User);

            var customer = await _customerProfileService.GetCustomerProfile(phone).ConfigureAwait(false);

            if (customer.Channel == null)
            {
                return(NotFound(Responses.ErrorResponse(null, new FeesResponseDto(), "The phone number network code was not found", ResponseCodes.NOT_FOUND)));
            }

            var fees = await _merchantAccountService.GetMomoFeesAsync(payload.Amount, customer.Channel,
                                                                      payload.ChargeCustomer.Value, accountId).ConfigureAwait(false);

            if (fees == null)
            {
                return(NotFound(Responses.ErrorResponse(null, new FeesResponseDto(), "Error getting fees", ResponseCodes.EXTERNAL_ERROR)));
            }

            var feeResponse = new FeesResponseDto
            {
                Amount          = payload.Amount,
                ChargeCustomer  = payload.ChargeCustomer.Value,
                MomoPhoneNumber = payload.MomoPhoneNumber,
                CustomerProfile = customer,
                MomoFee         = fees.Data
            };

            return(Ok(Responses.SuccessResponse(StatusMessage.Found, feeResponse, ResponseCodes.SUCCESS)));
        }