public async Task <IActionResult> SendToBankFromInvoice(int orderId, bool isOnlinePay = true) { if (!isOnlinePay) { var createPaymentFactor = await _shopOrderPaymentRepository.CreateOfflinePayment(orderId); return(RedirectToAction("OrderDetail", "Profile", new { id = orderId })); } var countPaymentFactor = await _shopOrderPaymentRepository.CreatePayment(orderId); if (orderId != 0 && countPaymentFactor > 1) { return(RedirectToAction("OrderDetail", "Profile", new { id = orderId })); } else if (orderId != 0 && countPaymentFactor == 1) { var paymentId = await _shopOrderPaymentRepository.GetByConditionAsync(a => a.ShopOrderId == orderId && !a.IsSuccess); return(await RequestByOrderPayment(paymentId.Id)); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Result(string orderId, int shopOrderId) { var shopOrderPayment = await _shopOrderPaymentRepository .GetByConditionAsync(a => a.ShopOrderId == shopOrderId && a.OrderId == orderId); var userInfo = await _userRepository.GetByConditionAsync(a => a.Id == UserId); //var model = await _shopOrderRepository.GetByConditionAsync(a => a.OrderId == orderId && a.UserId == UserId); ViewBag.Order = await _shopProductRepository.GetListAsync(a => a.ShopOrderId == shopOrderId && a.UserId == UserId, null, "Product,ProductPackage"); ViewBag.PhoneNumber = userInfo.PhoneNumber; ViewBag.FullName = userInfo.FirstName + " " + userInfo.LastName; ViewBag.UserAddress = await _userAddressRepository.GetByConditionAsync(a => a.UserId == UserId); return(View(shopOrderPayment)); }
public async Task <IActionResult> VerifyPaymentRequest(BankVerifyViewModel vm) { try { _logRepository.Add(new Log() { Text = $"*Start => " }); // گرفتن اطلاعات فاکتور بر اساس شناسه خرید و شناسه گاربری var model = _usersPaymentRepository.GetByCondition(a => a.OrderId == vm.OrderId && a.Token == vm.Token); var result = await _shopOrderPaymentRepository.GetByConditionAsync(a => a.OrderId == vm.OrderId); if (result == null) { TempData.AddResult(SweetAlertExtenstion.Error("متاسفانه اطلاعاتی با این شناسه خرید یافت نشد اگر هزینه ای از شما کسر شد طی 72 ساعت آینده به حسابتان واریز می شود")); return(Redirect("/")); } await _usersPaymentRepository.ResultOrderCallBack(result.ShopOrderId, result.OrderId, UserId); // رمز گذاری توکن var dataBytes = Encoding.UTF8.GetBytes(vm.Token); var symmetric = SymmetricAlgorithm.Create("TripleDes"); symmetric.Mode = CipherMode.ECB; symmetric.Padding = PaddingMode.PKCS7; var encryptor = symmetric.CreateEncryptor(Convert.FromBase64String(_bankConfig.MerchantKey), new byte[8]); var signedData = Convert.ToBase64String(encryptor.TransformFinalBlock(dataBytes, 0, dataBytes.Length)); var data = new { token = vm.Token, SignData = signedData }; var ipgUri = string.Format("{0}/api/v0/Advice/Verify", _bankConfig.PurchasePage); var res = CallApi <BankCallBackResultViewModel>(ipgUri, data); _logRepository.Add(new Log() { Text = $"*1 => " + ((res != null && res.Result != null) ? "" : "") }); if (res != null && res.Result != null) { await _usersPaymentRepository.ResultOrder(result.ShopOrderId, result.OrderId, UserId, res.Result.Succeed, res.Result.ResCode); _logRepository.Add(new Log() { Text = $"*2 => " + res.Result.ResCode.ToString() }); if (res.Result.ResCode == "0") { vm.VerifyResultData = res.Result; res.Result.Succeed = true; ViewBag.Success = res.Result.Description; await _shopOrderPaymentRepository.UpdateStatus(result.Id); // ثبت کردن اطلاعات در وضعیت await _shopOrderStatusRepository.InsertAsync(new ShopOrderStatusInsertViewModel() { Date = DateTime.Now, ShopOrderId = result.ShopOrderId, Status = ShopOrderStatusSSOT.Ordered }); if (await _shopOrderPaymentRepository.AllIsPay(result.ShopOrderId)) { // تغییر وضعیت فاکتور از پیش خرید به خرید شده await _shopOrderRepository.SuccessedOrder(result.ShopOrderId, model.UserId); // تغییر وضعیت سبد خرید await _shopProductRepository.SuccessedOrder(result.ShopOrderId, model.UserId); } _logRepository.Add(new Log() { Text = $"*3 => " + "Start send message" }); // ارسال اس ام اس به کاربر جهت ثبت سفارش var text = $"{result.ShopOrderId};{DateTime.Now.ToPersianDay()}"; var phoneNumber = _userRepository.GetByCondition(a => a.Id == model.UserId).PhoneNumber; var smsResult = _smsRestClient.SendByBaseNumber(text, phoneNumber, (int)SmsBaseCodeSSOT.SetOrder); // ارسال اس ام اس به مدیریت var ResultTest = $"{DateTime.Now.ToPersianDay()};{result.ShopOrderId}"; var sms1Result = _smsRestClient.SendByBaseNumber(ResultTest, "09122013443", (int)SmsBaseCodeSSOT.Result); var sms2Result = _smsRestClient.SendByBaseNumber(ResultTest, "09351631398", (int)SmsBaseCodeSSOT.Result); var sms3Result = _smsRestClient.SendByBaseNumber(ResultTest, "09104996615", (int)SmsBaseCodeSSOT.Result); _logRepository.Add(new Log() { Text = $"*sms -> FirstUser>{sms1Result.RetStatus}-{sms1Result.Value}-{sms1Result.StrRetStatus}" }); _logRepository.Add(new Log() { Text = $"*sms -> SecondUser>{sms2Result.RetStatus}-{sms2Result.Value}-{sms2Result.StrRetStatus}" }); _logRepository.Add(new Log() { Text = $"*sms -> ThirtUser>{sms3Result.RetStatus}-{sms3Result.Value}-{sms3Result.StrRetStatus}" }); _logRepository.Add(new Log() { Text = $"*3 => " + "End send message" }); await _treeRepository.CalculateRateTreeFromAmountAndInsert(result.PaymentAmount, model.UserId); return(RedirectToAction("Result", "UserOrder", new { orderId = res.Result.OrderId, shopOrderId = result.ShopOrderId })); } ViewBag.Message = res.Result.Description; return(RedirectToAction("Result", "UserOrder", new { orderId = result.OrderId, shopOrderId = result.ShopOrderId })); } } catch (Exception ex) { ViewBag.Message = ex.ToString(); _logRepository.Add(new Log() { Text = $"*Error => {ex.ToString()}" }); } return(Redirect("/")); }