public async Task <ActionResult> Donate(decimal Units) { if (unitsService.Get(Units) != null) { //get the subscriber var account = await _userManager.FindByNameAsync(User.Identity.Name); if (account != null) { //log the transaction CashDonationAttempt attempt = new CashDonationAttempt() { Email = account.Email, PhoneNumber = account.PhoneNumber, Amount = Units, CreatedBy = User.Identity.Name, DateCreated = DateTime.Now, Reference = Guid.NewGuid().ToString() }; Session.Add("trxref", attempt.Reference); //Save the transaction attempt = cashDonationAttemptService.Insert(attempt); //create transaction var transaction = new TransactionInitialize() { Amount = Units, Email = account.Email, Reference = attempt.Reference, CallBackUrl = String.Format("{0}/{1}/{2}", Request.Url.GetLeftPart(UriPartial.Authority), "Donate", "Verify") }; //decrypt secret var paymentConfiguration = payStackConfiguration.GetDefault(); var secret = paymentConfiguration.Secret;//StringEncrypterDecrypter.StringCipher.Decrypt(paymentConfiguration.Secret, String.Format("{0}{1}{2}{3}{4}{5}{6}", User.Identity.Name, paymentConfiguration.DateCreated.Year, paymentConfiguration.DateCreated.Month, paymentConfiguration.DateCreated.Day, paymentConfiguration.DateCreated.Hour, paymentConfiguration.DateCreated.Minute, paymentConfiguration.DateCreated.Second, paymentConfiguration.DateCreated.Millisecond)); //request charge authorization var canCharge = await paystackService.Initialize(secret, transaction); if (canCharge == null) { return(RedirectToAction("Donate")); } if (canCharge.Successful) { //redirect the user to the charge page return(Redirect(canCharge.Data.AuthorizationUrl)); } } else { ViewBag.Message = "Only Registered users are allowed to top up"; return(View("AccessDenied")); } } return(View()); }
public CashDonationAttempt Insert(CashDonationAttempt CashDonationAttempt) { if (CashDonationAttempt.Amount < 200) { throw new Exception("Transaction amount must not be less than 200"); } return(repository.Add(CashDonationAttempt)); }
public void Delete(CashDonationAttempt CashDonationAttempt) { repository.Delete(CashDonationAttempt); }
public bool Update(CashDonationAttempt CashDonationAttempt) { repository.Update(CashDonationAttempt); return(true); }