Esempio n. 1
0
        public static bool DoTopUp(TopUpDetails topUpDetails, out string error)
        {
            error = "";
            TopUp topUp = topUpDetails.GeneraTopUp();

            ExRMoneySvc.ExRMoneySoapClient exMoneyClient = new ExRMoneySvc.ExRMoneySoapClient();
            if (!CustomerHistoryHelper.CheckCustomerBalance(topUp.IdCustomer, Int32.Parse(topUp.Amount)))
            {
                error = "INSUFFISANT BANLANCE";
                return(false);
            }
            var result = exMoneyClient.SendAirTime(topUpDetails.SelectedPartner, topUpDetails.Amount, topUpDetails.Number);

            error = result.Error;
            if (result.Succes)
            {
                KoloAndroidEntities Context = new KoloAndroidEntities();
                Tuple <List <KoloNotification>, List <CustomerBalanceHistory> > tuple = OperationHelper.MakeOperation <TopUp>(topUp, Context, out error);
                Context.KoloNotifications.AddRange(tuple.Item1);
                Context.CustomerBalanceHistories.AddRange(tuple.Item2);
                Context.TopUps.Add(topUp);
                topUp.OpDate = DateTime.Now;
                try
                {
                    Context.SaveChanges();
                }
                catch (Exception ex)
                {
                    error = ExceptionHelper.GetExceptionMessage(ex);
                }
                Context.Dispose();
            }
            return(result.Succes);
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,MobileAccountId,TopUpChannelId,TopUpAmount")] TopUp topUp)
        {
            if (id != topUp.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(topUp);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TopUpExists(topUp.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MobileAccountId"] = new SelectList(_context.MobileAccount, "Id", "Id", topUp.MobileAccountId);
            ViewData["TopUpChannelId"]  = new SelectList(_context.Set <TopUpChannel>(), "Id", "Id", topUp.TopUpChannelId);
            return(View(topUp));
        }
        public ActionResult TopUpAccount(int id, [FromBody] TopUp topUp)
        {
            if (topUp.Amount == 0)
            {
                return(BadRequest());
            }
            User updatedUser = _paymentRepo.UpdateUserTopUp(id, topUp.Amount);

            return(Ok(_mapper.Map <User>(updatedUser)));
        }
Esempio n. 4
0
        public TopUp GeneraTopUp()
        {
            TopUp topUp = new TopUp();

            topUp.IdCustomer   = this.CustomerId;
            topUp.Amount       = this.Amount.ToString();
            topUp.PhoneNumber  = this.Number;
            topUp.OperatorCode = this.SelectedPartner;

            return(topUp);
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("Id,MobileAccountId,TopUpChannelId,TopUpAmount")] TopUp topUp)
        {
            if (ModelState.IsValid)
            {
                _context.Add(topUp);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MobileAccountId"] = new SelectList(_context.MobileAccount, "Id", "Id", topUp.MobileAccountId);
            ViewData["TopUpChannelId"]  = new SelectList(_context.Set <TopUpChannel>(), "Id", "Id", topUp.TopUpChannelId);
            return(View(topUp));
        }
        public ActionResult <Vehicle> TopUpVehicle([FromBody] TopUp topUp)
        {
            Vehicle vehicle = Vehicle.GetVehicleById(topUp.Id);

            if (vehicle == null)
            {
                return(NotFound("Vehicle with this id did not found"));
            }
            if (topUp.Sum <= 0)
            {
                return(BadRequest("The sum can not be less than zero or equals zero"));
            }
            Service.TopUpVehicle(topUp.Id, topUp.Sum);
            return(Ok(vehicle));
        }
        public async Task <ActionResult> Verify(string trxref)
        {
            if (string.IsNullOrEmpty(trxref) == true)
            {
                if (Session["trxref"] != null)
                {
                    trxref = Session["trxref"].ToString();
                }
            }
            //verify that we have the reference
            var attempt = topUpAttemptService.GetByReference(trxref);

            var user = subscriberService.FindByUserName(User.Identity.Name);

            if (attempt != null)
            {
                //oh great! We got the money, ok now lets confirm
                var verifyResponse = await paystackService.VerifyCharge(payStackConfiguration.GetDefault().Secret, attempt.Reference);

                if (verifyResponse.Successful)
                {
                    //excellent, confirmed so

                    //1. Update the attempt
                    attempt.IsSuccessful      = true;
                    attempt.CardType          = verifyResponse.Data.Authorization.CardType;
                    attempt.AuthorizationCode = verifyResponse.Data.Authorization.AuthorizationCode;
                    attempt.Bank        = verifyResponse.Data.Authorization.Bank;
                    attempt.Last4Digits = verifyResponse.Data.Authorization.Last4Digits;
                    attempt.Amount      = verifyResponse.Data.Amount / 100; //api returns amount in kobo, we divide by 100 to get the naira equivalent
                    attempt.DateUpdated = DateTime.Now;
                    attempt.UpdatedBy   = User.Identity.Name;

                    //save changes
                    topUpAttemptService.Update(attempt);

                    //2. Credit the subscriber
                    TopUp topUp = new TopUp {
                        Amount = attempt.Amount, CreatedBy = attempt.CreatedBy, Date = DateTime.Now, DateCreated = DateTime.Now, SubscriberId = attempt.SubscriberId, TopUpAttemptId = attempt.Id
                    };
                    topUpService.Insert(topUp);

                    return(View("Status", true));//RedirectToAction("Index", "Dashboard");
                }
            }

            return(View("Status", false));
        }
Esempio n. 8
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TopUp = await _context.TopUp
                    .Include(t => t.MobileAccount)
                    .Include(t => t.TopUpChannel).FirstOrDefaultAsync(m => m.Id == id);

            if (TopUp == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TopUp = await _context.TopUp.FindAsync(id);

            if (TopUp != null)
            {
                _context.TopUp.Remove(TopUp);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 10
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TopUp = await _context.TopUp
                    .Include(t => t.MobileAccount)
                    .Include(t => t.TopUpChannel).FirstOrDefaultAsync(m => m.Id == id);

            if (TopUp == null)
            {
                return(NotFound());
            }
            ViewData["MobileAccountId"] = new SelectList(_context.MobileAccount, "Id", "Number");
            ViewData["TopUpChannelId"]  = new SelectList(_context.TopUpChannel, "Id", "Name");
            return(Page());
        }
Esempio n. 11
0
        public bool AddBankTopupRequest(int userId, List <string> topUpReceiptUrls, AddBankTopUpBindingModel model)
        {
            try
            {
                TopUp topUp = new TopUp {
                    User_Id = userId, Amount = model.Amount, Account_Id = model.Account_Id, Status = TopUpStatus.Pending
                };
                _dbContext.BankTopUps.Add(topUp);

                foreach (var img in topUpReceiptUrls)
                {
                    TopUpMedia topUpMedia = new TopUpMedia {
                        MediaUrl = img, TopUp_Id = topUp.Id
                    };
                    _dbContext.TopUpMedias.Add(topUpMedia);
                }
                _dbContext.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 12
0
        public async Task <object> ConfirmPaypalPayment(PaymentConfirmationBindingModel model, int id)
        {
            try
            {
                if (_dbContext.PaymentHistories.Any(x => x.TransactionId.Equals(model.TransactionId)))
                {
                    return(HttpStatusCode.Conflict);
                }

                var    client         = new HttpClient();
                string result         = String.Empty;
                var    keyValues      = new List <KeyValuePair <string, string> >();
                string svcCredentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(AppSettingsProvider.PaypalUsername + ":" + AppSettingsProvider.PaypalPassword));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", svcCredentials);
                var request = new HttpRequestMessage(HttpMethod.Post, AppSettingsProvider.PaypalAPIGetTokenUrl);
                keyValues.Add(new KeyValuePair <string, string>("grant_type", "client_credentials"));

                request.Content = new FormUrlEncodedContent(keyValues);
                request.Headers.Authorization       = new AuthenticationHeaderValue("Basic", svcCredentials);
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
                HttpResponseMessage response = await client.SendAsync(request);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    result = await response.Content.ReadAsStringAsync();

                    PaypalAccessTokenModel tokenModel = JsonConvert.DeserializeObject <PaypalAccessTokenModel>(result);
                    if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(HttpStatusCode.NotFound);
                    }
                    else if (response.StatusCode == HttpStatusCode.OK)
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenModel.access_token);
                        response = await client.GetAsync(AppSettingsProvider.PaypalAPIVerificationUrl + model.TransactionId);

                        result = await response.Content.ReadAsStringAsync();

                        PaypalVerificationModel paymentModel = JsonConvert.DeserializeObject <PaypalVerificationModel>(result);


                        if (model.SubscriptionPackage_Id > 0)
                        {
                            var package = _dbContext.SubscriptionPackages.FirstOrDefault(x => x.Id == model.SubscriptionPackage_Id);
                            var driver  = _dbContext.Drivers.Include(x => x.CashSubscriptions).FirstOrDefault(x => x.Id == id);
                            CashSubscription cashSubscription = new CashSubscription {
                                RemainingRides = package.NumOfRides, Driver_Id = id, Amount = model.Amount, SubscriptionPackage_Id = model.SubscriptionPackage_Id.Value, Status = TopUpStatus.Accepted, isActive = true, PaymentType = PaymentMethods.CreditCard
                            };
                            if (driver.CashSubscriptions.Count > 0)
                            {
                                var pkg = driver.CashSubscriptions.Last();
                                if (pkg.isActive)
                                {
                                    cashSubscription.RemainingRides      += pkg.RemainingRides;
                                    cashSubscription.PreviousPackageRides = pkg.RemainingRides;
                                }
                                pkg.isActive = false;
                            }
                            #region Expiry
                            switch (package.DurationType)
                            {
                            case DurationType.Days:
                                cashSubscription.ExpiryDate = DateTime.UtcNow.AddDays(package.Duration);
                                break;

                            case DurationType.Months:
                                cashSubscription.ExpiryDate = DateTime.UtcNow.AddMonths(package.Duration);
                                break;

                            case DurationType.Years:
                                cashSubscription.ExpiryDate = DateTime.UtcNow.AddYears(package.Duration);
                                break;

                            default:
                                cashSubscription.ExpiryDate = DateTime.UtcNow.AddMonths(package.Duration);
                                break;
                            }
                            ;
                            #endregion
                            driver.CashSubscriptions.Add(cashSubscription);
                            PaymentHistory paymentHistory = new PaymentHistory {
                                TransactionId = model.TransactionId, CreatedDate = Convert.ToDateTime(paymentModel.Create_time), ModifiedDate = Convert.ToDateTime(paymentModel.Create_time), Driver_Id = id, Package_Id = model.SubscriptionPackage_Id
                            };
                            driver.PaymentHistories.Add(paymentHistory);
                            _dbContext.SaveChanges();
                            return(HttpStatusCode.OK);
                        }
                        else
                        {
                            var    user            = _dbContext.Users.Include(x => x.BankTopUps).FirstOrDefault(x => x.Id == id);
                            var    settings        = _dbContext.Settings.FirstOrDefault();
                            var    paypalAmount    = paymentModel.Transactions.First().Amount;
                            double convertedAmount = 0;
                            if (paypalAmount != null)
                            {
                                TopUp topUp = new TopUp {
                                    Amount = convertedAmount, PaymentType = PaymentMethods.CreditCard, Status = TopUpStatus.Accepted
                                };
                                user.BankTopUps.Add(topUp);
                                convertedAmount = paypalAmount.Total / settings.CurrencyToUSDRatio;
                                PaymentHistory paymentHistory = new PaymentHistory {
                                    TransactionId = model.TransactionId, CreatedDate = Convert.ToDateTime(paymentModel.Create_time), ModifiedDate = Convert.ToDateTime(paymentModel.Create_time), USDAmount = paypalAmount.Total, LocalCurrencyAmount = convertedAmount
                                };
                                user.PaymentHistories.Add(paymentHistory);
                                user.Wallet += convertedAmount;
                            }
                            _dbContext.SaveChanges();
                            return(HttpStatusCode.OK);
                        }
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }