public async Task <AccountHolderModel> GetAccountHolderDetailInformation(string id, string prgId)
        {
            var usrBitePayBalance       = new List <UserAvailableBalanceDto>();
            var jposusrbalance          = new JPOSBiteBalanceApiModel();
            AccountHolderModel usrModel = new AccountHolderModel();

            if (!string.IsNullOrEmpty(id))
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.SetBearerToken(Request.HttpContext.User.Claims.FirstOrDefault(x => x.Type.ToLower().Trim() == "AccessToken".ToLower().Trim()).Value);
                    var result = client.GetAsync(_configuration["ServiceAPIURL"] + ApiConstants.GetAccountHolderDetail + "?userEncId=" + id + "&programEncId=" + prgId).Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var response = await result.Content.ReadAsAsync <ApiResponse>();

                        dynamic response1 = JsonConvert.DeserializeObject(response.Result.ToString());
                        usrModel = response1.ToObject <AccountHolderModel>();
                        usrModel.ProgramCustomJsonFields = response.CustomResult;
                        usrModel.UserEncId               = id;
                        usrModel.Jpos_EncUserID          = !string.IsNullOrEmpty(usrModel.Jpos_AccountHolderId) ? Cryptography.EncryptPlainToCipher(usrModel.Jpos_AccountHolderId) : "";
                        usrModel.ProgramUniqueColumnName = response.CustomResult1;
                    }
                    //balances
                    ViewBag.uid = Convert.ToInt32(Cryptography.DecryptCipherToPlain(id));
                    var result1 = client.GetAsync(_configuration["ServiceAPIURL"] + ApiConstants.GetJPOSBiteUserBalance + "?userId=" + Convert.ToInt32(Cryptography.DecryptCipherToPlain(id))).Result;
                    if (result1.IsSuccessStatusCode)
                    {
                        var response = await result1.Content.ReadAsAsync <ApiResponse>();

                        dynamic response1 = JsonConvert.DeserializeObject(response.Result.ToString());
                        jposusrbalance = response1.ToObject <JPOSBiteBalanceApiModel>();
                        if (jposusrbalance.success != false)
                        {
                            IEnumerable <double> objbitepay = from s in jposusrbalance.accounts.Where(x => x.name == "bite pay")
                                                              select s.balance;
                            ViewBag.usrBitePayBalance = objbitepay.FirstOrDefault();
                        }
                        else
                        {
                            ViewBag.usrBitePayBalance = 0;
                        }
                        if (jposusrbalance.success != false)
                        {
                            IEnumerable <double> objrewards = from s in jposusrbalance.accounts.Where(x => x.name == "bite rewards")
                                                              select s.balance;
                            ViewBag.usrBiteRewardsBalance = objrewards.FirstOrDefault();
                        }
                        else
                        {
                            ViewBag.usrBiteRewardsBalance = 0;
                        }
                    }
                    var result2 = client.GetAsync(_configuration["ServiceAPIURL"] + ApiConstants.GetBiteUserLoyaltyTrackingBalance + "?userId=" + Convert.ToInt32(Cryptography.DecryptCipherToPlain(id))).Result;
                    if (result2.IsSuccessStatusCode)
                    {
                        var response = await result2.Content.ReadAsAsync <ApiResponse>();

                        ViewBag.usrLoyaltyTrackingBalance = response.Result;
                    }

                    var benefactorsDetails = client.GetAsync(_configuration["ServiceAPIURL"] + ApiConstants.BenefactorDetails + "?benefactorId=" + Convert.ToInt32(Cryptography.DecryptCipherToPlain(id))).Result;
                    if (benefactorsDetails.IsSuccessStatusCode)
                    {
                        var responseTransaction = await benefactorsDetails.Content.ReadAsAsync <ApiResponse>();

                        if (responseTransaction.Result != null)
                        {
                            //  transactions = JsonConvert.DeserializeObject<List<response.TranlogViewModel>>(responseTransaction.Result.ToString());
                            dynamic responseDesACH            = JsonConvert.DeserializeObject(responseTransaction.Result.ToString());
                            List <LinkedUsersDto> benefactors = responseDesACH.ToObject <List <LinkedUsersDto> >();
                            if (benefactors != null)
                            {
                                ViewBag.BenefectorsCounts = benefactors.Count();
                            }
                            else
                            {
                                ViewBag.BenefectorsCounts = 0;
                            }
                        }
                    }
                }
            }
            return(usrModel);
        }
Пример #2
0
        public async Task <IActionResult> GetJPOSBiteUserBalance(int UserId)
        {
            try
            {
                var userdetail = await _userRepository.GetUserInfoById(UserId);

                using (var client = new HttpClient())
                {
                    var jposSettingsForUserBalance = (await _setting.GetGeneratSettingValueByKeyGroup(Constants.GeneralSettingsKeyGroup.JPOS_Staging)).ToList();
                    if (jposSettingsForUserBalance.Count > 0)
                    {
                        foreach (var itemForJPOS in jposSettingsForUserBalance)
                        {
                            switch (itemForJPOS.KeyName)
                            {
                            case Constants.JPOSConstants.JPOS_Version:
                                version = itemForJPOS.Value;
                                break;

                            case Constants.JPOSConstants.JPOS_ConsumerId:
                                consumerId = itemForJPOS.Value;
                                break;

                            case Constants.JPOSConstants.JPOS_HostURL:
                                url = itemForJPOS.Value;
                                break;

                            case Constants.JPOSConstants.JPOS_N:
                                n = itemForJPOS.Value;
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    var usrBitePayBalance = new JPOSBiteBalanceApiModel();

                    if (!string.IsNullOrEmpty(consumerId) && !string.IsNullOrEmpty(url))
                    {
                        client.DefaultRequestHeaders.Add("version", version);
                        client.DefaultRequestHeaders.Add("consumer-id", consumerId);
                        client.DefaultRequestHeaders.Add("nonce", n);

                        var hostURLForUserBalance = new Uri($"" + url + "wallets/" + userdetail?.PartnerUserId + "/balance");
                        var response = await client.GetAsync(hostURLForUserBalance);

                        string jsonForUserBalance;
                        using (var content = response.Content)
                        {
                            jsonForUserBalance = await content.ReadAsStringAsync();

                            dynamic response1 = JsonConvert.DeserializeObject(jsonForUserBalance.ToString());
                            usrBitePayBalance = response1.ToObject <JPOSBiteBalanceApiModel>();
                            return(Ok(new ApiResponse(StatusCodes.Status200OK, true, MessagesConstants.JPOSBalanceReturnedSuccessfully, response1)));
                        }
                    }
                    return(Ok(new ApiResponse(StatusCodes.Status200OK, false, MessagesConstants.JPOSBalanceUnsuccessfuleturn, null)));
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(new Exception(string.Concat("API := (JPOS := JPOSUserBalance)", ex.Message, " Stack Trace : ", ex.StackTrace, " Inner Exception : ", ex.InnerException)));
                return(Ok(new ApiResponse(Microsoft.AspNetCore.Http.StatusCodes.Status200OK, false, MessagesConstants.SomeIssueInProcessing)));
            }
        }