예제 #1
0
        protected async void btnValidateOtp_Click(object sender, EventArgs e)
        {
            string EndpointUrl    = $"{BaseUrl}/api/otp?otp={txtOtp.Text}";
            var    GetOtpResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(null, ApiRequest.Verbs.GET, null);

            if (GetOtpResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string responseString = await GetOtpResponse.Content.ReadAsStringAsync();

                DefaultApiReponse <OtpResponse> response = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <OtpResponse> >(responseString);

                if (response == null)
                {
                    Response.Write("<script language='javascript'>alert('Invalid Otp');</script>");
                    return;
                }

                else if (response.Object.IsUsed == 1)
                {
                    Response.Write("<script language='javascript'>alert('Otp has been used already');</script>");
                    return;
                }
                else
                {
                    EndpointUrl = $"{BaseUrl}/api/otp";
                    var ValidateOtpResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(txtOtp.Text, ApiRequest.Verbs.POST, null);

                    if (ValidateOtpResponse.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        string ValidateOTPResponseString = await ValidateOtpResponse.Content.ReadAsStringAsync();

                        DefaultApiReponse <int> ValidationResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <int> >(responseString);
                        if (ValidationResponse.Object == 1)
                        {
                            //trigger thumbprint reader
                            //Save to DB
                            CustomerRepository customerRepository = new CustomerRepository();
                            BvnSearchResp      custObj            = (BvnSearchResp)Session["BvnSearchResp"];
                            customerRepository.CreateCustomer(new CustomerCreation
                            {
                                BVN            = custObj.BVN,
                                EmailAddress   = custObj.Email,
                                FirstName      = custObj.FirstName,
                                LastName       = custObj.LastName,
                                PhoneNumber    = custObj.PhoneNumber1,
                                CardToken      = null,
                                CardType       = null,
                                EnrollmentType = "Account",
                                PanicFinger    = "",
                                MaxAmount      = 100000000000
                            });
                        }
                    }
                }
            }
        }
예제 #2
0
        async Task <List <TransactionDto> > GetTransactions(DateTime fromDate, DateTime toDate)
        {
            string EndpointUrl = $"{BaseUrl}/api/Transactions/merchants?merchantid=1&fromDate={fromDate}&toDate={toDate}";

            var headers        = new Dictionary <string, string>();
            var r              = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(null, ApiRequest.Verbs.GET, headers);
            var responseString = await r.Content.ReadAsStringAsync();

            DefaultApiReponse <List <TransactionDto> > response = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <List <TransactionDto> > >(responseString);

            return(response.Object);
        }
예제 #3
0
        protected async Task <IApiResponse <T> > HandleApiOperationAsync <T>(Func <Task <DefaultApiReponse <T> > > action, [CallerLineNumber] int lineNo = 0, [CallerMemberName] string method = "")
        {
            var apiResponse = new DefaultApiReponse <T> {
                Code = $"{(int)HttpStatusCode.OK}", ShortDescription = "SUCCESS"
            };

            var userId = "";//CurrentUserId;

            log.Info($" / {method} by {userId} BEGINS.");
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new GenericException("There are some errors in your input, please correct them.", $"{(int)HttpStatusCode.BadRequest}");
                }

                var methodResponse = await action.Invoke();

                apiResponse.Object           = methodResponse.Object;
                apiResponse.ShortDescription = string.IsNullOrEmpty(methodResponse.ShortDescription)
                    ? apiResponse.ShortDescription
                    : methodResponse.ShortDescription;
                apiResponse.Code = string.IsNullOrEmpty(methodResponse.Code) ? apiResponse.Code : methodResponse.Code;
            }
            catch (GenericException igex)
            {
                log.Warn($"/ {method} L{lineNo} by {userId} - {igex.ErrorCode}: {igex.Message}");
                apiResponse.ShortDescription = igex.Message;
                apiResponse.Code             = igex.ErrorCode;

                if (!ModelState.IsValid)
                {
                    apiResponse.ValidationErrors = ModelState.ToDictionary(
                        m =>
                    {
                        var tokens = m.Key.Split('.');
                        return(tokens.Length > 0 ? tokens[tokens.Length - 1] : tokens[0]);
                    },
                        m => m.Value.Errors.Select(e => e.Exception?.Message ?? e.ErrorMessage)
                        );
                }
            }
            catch (Exception ex)
            {
                log.Error($"/ {method} L{lineNo} by {userId} \n\n{ex}\n");
                apiResponse.ShortDescription = ex.Message;
                apiResponse.Code             = $"{(int)HttpStatusCode.InternalServerError}";
            }

            log.Info($" / {method} by {userId} ENDS.");

            return(apiResponse);
        }
예제 #4
0
        protected async void btnVerifyBVN_Click(object sender, EventArgs e)
        {
            Random rnd            = new Random();
            string EndpointUrl    = $"{BaseUrl}/api/nibss/searchbvn?bvn={txtBVN.Text}";
            string responseString = "";
            // NibssRepository nibssRepository = new NibssRepository();
            //var resp= nibssRepository.BvnSearch(txtBVN.Text);

            var bvnSearchResponse = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(null, ApiRequest.Verbs.GET, null);

            if (bvnSearchResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                responseString = await bvnSearchResponse.Content.ReadAsStringAsync();

                DefaultApiReponse <BvnSearchResp> response = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultApiReponse <BvnSearchResp> >(responseString);
                Session["BvnSearchResp"] = response.Object;
                string Otp     = rnd.Next(0, 9999).ToString("D4");
                string phoneNo = response.Object.PhoneNumber1;

                //Save Otp
                EndpointUrl = $"{BaseUrl}/api/otp";

                OtpRequest otpRequest = new OtpRequest
                {
                    Bvn = txtBVN.Text,
                    Otp = Otp
                };

                var headers = new Dictionary <string, string>();
                var r       = await new ApiRequest(EndpointUrl).MakeHttpClientRequest(otpRequest, ApiRequest.Verbs.POST, headers);

                if (r.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    responseString = await r.Content.ReadAsStringAsync();

                    string mailbody = "Dear Customer,<br/><br/> Your One Time OTP is " + Otp;

                    mailer.SendMailAlerts(response.Object.Email, mailbody, "Team Daze - One Time Password");
                }
                formoneaccount.Visible = false;
                formtwoaccount.Visible = true;
            }
        }