public ActionResult SyncReturn(string paymentCode, Guid orderId) { return(Redirect(_publicService.GetReturnUrl(orderId))); //var paymentDispatcher = HostConstObject.Container.ResolveNamed<IPaymentDispatcher>(paymentCode.ToLower()); //var result = paymentDispatcher.SyncReturn(Request); //return Json(result,JsonRequestBehavior.AllowGet); }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult Pay(PayViewModel payModel) { //获取产品信息 if (payModel.OrderId.Equals(Guid.Empty)) { return(Content("订单Id不合法!")); } var order = _currencyService.GetSingleById <Order>(payModel.OrderId); if (order == null) { return(Content("订单数据不存在!")); } if (order.OrderStatus != OrderStatus.PendingPayment && order.PayStatus != PayStatus.Unpaid) { return(Content("订单状态不合理,无法支付!")); } var payment = _paymentService.LoadPayment(payModel.PaymentCode); if (payment == null || !payment.Enabled) { return(Content("支付方式不合法或已停用!")); } var paymentDispatcher = HostConstObject.Container.ResolveNamed <IPaymentDispatcher>(payment.Code.ToLower()); if (paymentDispatcher == null) { return(Content("支付方式不合法")); } var routeParas = new RouteValueDictionary { { "area", PaymentProcessModule.Area }, { "controller", "Receive" }, { "action", "AsyncReturn" }, { "paymentCode", payment.Code } }; var notifyUrl = HostConstObject.HostUrl + _urlHelper.RouteUrl(routeParas); var routeParas2 = new RouteValueDictionary { { "area", PaymentProcessModule.Area }, { "controller", "Receive" }, { "action", "SyncReturn" }, { "paymentCode", payment.Code } }; var returnUrl = HostConstObject.HostUrl + _urlHelper.RouteUrl(routeParas2); if (payModel.UseBalance == 1) { //使用余额付款 #region using (TransactionScope scope = new TransactionScope()) { var cashWallet = _walletService.GetWalletByMemberId(order.MemberId, Wallet.Models.WalletType.Cash); if (cashWallet != null && cashWallet.Available > 0) { if (cashWallet.Available >= order.PayFee) { string error; if (_walletService.Draw(order.MemberId, Wallet.Models.WalletType.Cash, order.PayFee, "支付订单" + order.OrderNo, out error)) { order.BalancePay = order.PayFee; order.OrderStatus = OrderStatus.WaitingForDelivery; order.PayStatus = PayStatus.Paid; order.PayTime = DateTime.Now; var balancePayment = _paymentService.LoadPayment(PaymentType.Balance.ToString()); order.PaymentId = balancePayment.Id; order.PaymentName = balancePayment.Name; _orderService.ChangeOrderStatus(order.Id, order.OrderStatus, order.PayStatus); _currencyService.Update(order); scope.Complete(); } } else { string error; if (_walletService.Draw(order.MemberId, Wallet.Models.WalletType.Cash, cashWallet.Available, "支付订单" + order.OrderNo, out error)) { order.UnpayFee = order.PayFee - cashWallet.Available; order.BalancePay = cashWallet.Available; _currencyService.Update(order); scope.Complete(); } } } } #endregion } if (order.PayStatus == PayStatus.Paid) { return(Redirect(_publicService.GetReturnUrl(order.Id))); } var payLog = new PayLog { Id = KeyGenerator.GetGuidKey(), TransactionNo = $"{order.OrderNo}{KeyGenerator.GenerateRandom(1000, 1)}", OrderId = order.Id, OrderNo = order.OrderNo, OrderAmount = order.UnpayFee, PaymentId = payment.Id, PaymentName = payment.Name, CreateTime = DateTime.Now, LogStatus = LogStatus.Unpaid }; if (!_currencyService.Create(payLog)) { throw new WebApiInnerException("0007", "生成支付流水失败"); } var subject = $"支付订单{order.OrderNo}-{payLog.TransactionNo}"; var body = string.Join(";", _currencyService.GetList <OrderGoods>(x => x.OrderId == order.Id).Select(g => g.GoodsName)); ViewBag.Html = paymentDispatcher.H5Pay(subject, body, notifyUrl, returnUrl, payLog, payment); return(View()); }
/// <summary> /// 获取用户的OpenId /// </summary> /// <returns></returns> public ActionResult PayOAuth(Guid orderId, int useBalance) { //获取产品信息 if (orderId.Equals(Guid.Empty)) { return(Content("订单Id不合法!")); } var order = _currencyService.GetSingleById <Order>(orderId); if (order == null) { return(Content("订单数据不存在!")); } if (order.OrderStatus != OrderStatus.PendingPayment && order.PayStatus != PayStatus.Unpaid) { return(Content("订单状态不合理,无法支付!")); } var payment = _paymentService.LoadPayment("weixin"); if (payment == null || !payment.Enabled) { return(Content("支付方式不合法或已停用!")); } if (useBalance == 1) { //使用余额付款 #region using (TransactionScope scope = new TransactionScope()) { var cashWallet = _walletService.GetWalletByMemberId(order.MemberId, Wallet.Models.WalletType.Cash); if (cashWallet != null && cashWallet.Available > 0) { if (cashWallet.Available >= order.PayFee) { string error; if (_walletService.Draw(order.MemberId, Wallet.Models.WalletType.Cash, order.PayFee, "支付订单" + order.OrderNo, out error)) { order.BalancePay = order.PayFee; order.OrderStatus = OrderStatus.WaitingForDelivery; order.PayStatus = PayStatus.Paid; order.PayTime = DateTime.Now; var balancePayment = _paymentService.LoadPayment(PaymentType.Balance.ToString()); order.PaymentId = balancePayment.Id; order.PaymentName = balancePayment.Name; _orderService.ChangeOrderStatus(order.Id, order.OrderStatus, order.PayStatus); _currencyService.Update(order); scope.Complete(); } } else { string error; if (_walletService.Draw(order.MemberId, Wallet.Models.WalletType.Cash, cashWallet.Available, "支付订单" + order.OrderNo, out error)) { order.UnpayFee = order.PayFee - cashWallet.Available; order.BalancePay = cashWallet.Available; _currencyService.Update(order); scope.Complete(); } } } } #endregion } if (order.PayStatus == PayStatus.Paid) { return(Redirect(_publicService.GetReturnUrl(order.Id))); } var state = $"{orderId}"; var oathInfo = _currencyService.GetSingleByConditon <UserOAuth>(ua => ua.MemberId == order.MemberId && ua.OAuthType == OAuthType.WeiXin); if (oathInfo != null) { var result = JsApiPayProcess($"|{oathInfo.OAuthId}|", state); if (result != null) { return(result); } return(View("JsApi")); } //需要授权 var routeParas = new RouteValueDictionary { { "area", PaymentProcessModule.Area }, { "controller", "WeiXin" }, { "action", "JsApi" } }; var returnUrl = HostConstObject.HostUrl + _urlHelper.RouteUrl(routeParas); var url = OAuthApi.GetAuthorizeUrl(AppId, returnUrl, state, OAuthScope.snsapi_userinfo); return(Redirect(url)); }