public IHttpActionResult PayNow(UserPlanBindingModel plan) { try { plan.UserId = User.Identity.GetUserId(); plan.Email = User.Identity.GetUserName(); plan.MerchantIdentifier = Utility.Constants.MERCHANT_IDENTIFIER; plan.AccessCode = Utility.Constants.ACCESS_CODE; plan.Command = Utility.Constants.COMMAND; //Guid id = Guid.NewGuid(); Random r = new Random(); int randNum = r.Next(1000000); string sixDigitNumber = randNum.ToString("D20"); plan.Amount = plan.TotalValue; plan.MerchantReference = sixDigitNumber; plan.URFXPaymentType = Data.Enums.URFXPaymentType.PlanPayment; TransactionHistoryModel historyModel = new TransactionHistoryModel(); AutoMapper.Mapper.Map(plan, historyModel); historyModel.CreatedDate = DateTime.UtcNow; historyModel = transactionHistoryService.InsertTransactionHistory(historyModel); AutoMapper.Mapper.Map(historyModel, plan); plan.TotalValue = plan.TotalValue * 100; byte[] secretkey = new Byte[64]; SHA256Managed mysha256 = new SHA256Managed(); byte[] bytedText = System.Text.UTF8Encoding.UTF8.GetBytes("" + Utility.Constants.PHRASE + "access_code=" + plan.AccessCode + "amount=" + plan.TotalValue + "command=" + plan.Command + "currency=" + plan.Currency + "customer_email=" + plan.Email + "language=" + plan.Language + "merchant_identifier=" + plan.MerchantIdentifier + "merchant_reference=" + plan.MerchantReference + Utility.Constants.PHRASE); byte[] hashValue = mysha256.ComputeHash(bytedText); byte[] hash = HashHMAC(bytedText); plan.SecretKey = HashEncode(hash); return Ok(plan); } catch (Exception ex) { return BadRequest(ex.Message); } }
public IHttpActionResult ClientPayment(UserPlanBindingModel plan) { try { ApplicationUser user = UserManager.FindById(plan.UserId); if (user != null) { plan.Email = user.Email;// User.Identity.GetUserName(); plan.MerchantIdentifier = Utility.Constants.MERCHANT_IDENTIFIER; plan.AccessCode = Utility.Constants.ACCESS_CODE; plan.Command = Utility.Constants.COMMAND;//"AUTHORIZATION"; // //Guid id = Guid.NewGuid(); Random r = new Random(); int randNum = r.Next(1000000); string sixDigitNumber = randNum.ToString("D20"); plan.Amount = plan.TotalValue; plan.MerchantReference = sixDigitNumber; if(plan.PaymentType == URFXPaymentType.JobPayment.ToString()) { plan.URFXPaymentType = Data.Enums.URFXPaymentType.JobPayment; } else { plan.URFXPaymentType = Data.Enums.URFXPaymentType.JobAdditionalPayment; } TransactionHistoryModel historyModel = new TransactionHistoryModel(); AutoMapper.Mapper.Map(plan, historyModel); historyModel.CreatedDate = DateTime.UtcNow; historyModel = transactionHistoryService.InsertTransactionHistory(historyModel); AutoMapper.Mapper.Map(historyModel, plan); plan.TotalValue = plan.TotalValue * 100; byte[] secretkey = new Byte[64]; SHA256Managed mysha256 = new SHA256Managed(); byte[] bytedText = System.Text.UTF8Encoding.UTF8.GetBytes("" + Utility.Constants.PHRASE + "access_code=" + plan.AccessCode + "amount=" + plan.TotalValue + "command=" + plan.Command + "currency=" + plan.Currency + "customer_email=" + plan.Email + "language=" + plan.Language + "merchant_identifier=" + plan.MerchantIdentifier + "merchant_reference=" + plan.MerchantReference + Utility.Constants.PHRASE); byte[] hashValue = mysha256.ComputeHash(bytedText); byte[] hash = HashHMAC(bytedText); plan.SecretKey = HashEncode(hash); plan.Url = Utility.Constants.PAYMENT_URL; return Json(plan); } else { return BadRequest("User not found"); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return BadRequest(ex.Message); } }