コード例 #1
0
        private string GetValidOTP(string userId)
        {
            var otpService = new OTPService(new HmacBasedOTPAlgorithm(),
                                            new ExpiryBasedMovingFactorAlgorithm(new OTPConfiguration()), new ErrorFactory(), new OTPConfiguration());
            var generateOtpRequest = new GenerateOTPRequest {
                UserId = userId
            };
            GenerateOTPResponse generateOTPResponse = otpService.GenerateOtp(generateOtpRequest);

            return(generateOTPResponse.OTP);
        }
コード例 #2
0
        public static string DoOTPGenerationWithoutCustomerRegistration(string requestStr)
        {
            Serializer          ser           = new Serializer();
            string              xmlOutputData = string.Empty;
            string              responseCode  = string.Empty;
            DateTime            requestTime   = DateTime.Now;
            GenerateOTPResponse objResp       = new GenerateOTPResponse();

            try
            {
                GenerateOTPRequestEx obj = ser.Deserialize <GenerateOTPRequestEx>(requestStr);
                if (obj != null)
                {
                    var mandate = MandateRepo.GetMandateByCode(obj.MandateCode);
                    if (mandate != null)
                    {
                        CentralPayOtp otp = new CentralPayOtp()
                        {
                            DateGenerated   = DateTime.Now,
                            IsUsed          = false,
                            MandateCodeId   = mandate.Id,
                            otp             = Utils.GenerateNewOtp(),
                            Amount          = Convert.ToDecimal(obj.Amount),
                            ReferenceNumber = Guid.NewGuid().ToString()
                        };

                        bool isSaved = MandateRepo.SaveCentralPayOtp(otp);

                        responseCode = isSaved ? ResponseCodeMap.Successful : ResponseCodeMap.UnknownError;

                        objResp = new GenerateOTPResponse
                        {
                            BankCode      = obj.BankCode,
                            BillerID      = obj.BillerID,
                            BillerName    = obj.BillerName,
                            BillerTransId = obj.BillerTransId,
                            MandateCode   = obj.MandateCode,
                            TransType     = obj.TransType,
                            ResponseCode  = responseCode
                        };
                    }
                    else
                    {
                        objResp = new GenerateOTPResponse {
                            ResponseCode = ResponseCodeMap.USerNotSetUp
                        };
                    }
                }
                else
                {
                    objResp = new GenerateOTPResponse {
                        ResponseCode = ResponseCodeMap.InvalidXml
                    };
                }

                xmlOutputData = ser.Serialize <GenerateOTPResponse>(objResp);
            }
            catch (Exception e) { ExceptionLogRepo.SaveExceptionLog(e);
                                  xmlOutputData = ser.Serialize <GenerateOTPResponse>(new GenerateOTPResponse {
                    ResponseCode = ResponseCodeMap.InvalidXml
                }); }
            DateTime responseTime = DateTime.Now;

            RequestResponseRepository.SaveRequestResponse("ASMX", requestStr, requestTime, "", xmlOutputData, responseTime);
            return(xmlOutputData);
        }