/// <summary> /// 确认退款 /// </summary> /// <param name="refundParam"></param> /// <param name="certPath"></param> /// <param name="certPwd"></param> /// <param name="paykey"></param> /// <param name="return_msg"></param> /// <returns></returns> public StateCode WeChatConfirmRefund(RefundPay refundParam, long order_id, string certPath, string certPwd, string paykey, out string return_msg) { using (ISession s = SessionFactory.Instance.CreateSession()) { return_msg = string.Empty; try { //回调 RefundMessage rmessage = WeChatPayHelper.CallRefund(refundParam, certPath, certPwd, paykey); if (rmessage.return_code.Equals("FAIL", StringComparison.OrdinalIgnoreCase)) { return_msg = rmessage.return_msg; return(StateCode.State_500); } else if (rmessage.result_code.Equals("FAIL", StringComparison.OrdinalIgnoreCase)) { return_msg = rmessage.err_code + " " + rmessage.err_code_des; return(StateCode.State_500); } //开启事务 s.StartTransaction(); //更新订单状态 s.ExcuteUpdate("update tb_odr_order set refund_status = @0,status = @1 where id = @2 ", OrderRefundStatus.Pass, OrderStatus.Close, order_id); //更新退款单状态 s.ExcuteUpdate("update tb_odr_refund set status = @0 where order_serial_no = @1 ", OrderRefundStatus.Pass, refundParam.out_trade_no); //提交事务 s.Commit(); return(StateCode.State_200); } catch (Exception ex) { return_msg = ex.ToString(); s.RollBack(); return(StateCode.State_500); } } }
/// <summary> /// 退支付信息 /// </summary> /// <returns>退支付结果</returns> public Lazy <RefundPay> CreateRefundPay() { Lazy <RefundPay> result = new Lazy <RefundPay>(() => { //拆分退采购数据 RefundPay refundPay = new RefundPay(); var strArray = resultDetails.Split('#')[0].Split('$'); var strItem = strArray[0].Split('^'); refundPay.BatchNo = strItem[0]; refundPay.TradeNo = strItem[1]; refundPay.RefundAmount = Convert.ToDecimal(strItem[2]); refundPay.ResultCode = strItem[3]; if (strArray.Length >= 2) { var poundageItem = strArray[1].Split('^'); refundPay.PoundageAmount = Convert.ToDecimal(poundageItem[2]); } return(refundPay); }); return(result); }
public ServiceRequestResult RefundPay(RefundPay request, out RefundPayResult result) { return(ServiceRequest(EventNames.Pay_Refund, request, out result)); }
public JsonResult SubmitRefundOrder(string no, decimal refund_amount, IHostingEnvironment host) { try { //退款状态码 StateCode state = StateCode.State_500; #region 订单基本状态判断 //退款单 OrderRefund orderRefund = ServiceIoc.Get <OrderRefundService>().Get(no); //订单 ProductOrder order = ServiceIoc.Get <ProductOrderService>().GetById(orderRefund.order_id); //是否存在订单 if (order == null) { return(Json(GetResult(StateCode.State_551))); } //订单是否未支付 if (!order.is_pay) { return(Json(GetResult(StateCode.State_552))); } //退款金额是否大于实际支付金额 if (refund_amount > order.actual_amount) { return(Json(GetResult(StateCode.State_554))); } //订单状态和退款单状态是可以退款的情况 if (order.refund_status != 1 || orderRefund.status != 1) { return(Json(GetResult(StateCode.State_553))); } #endregion //返回信息 string msg = string.Empty; bool PayStatus = ConfigManage.AppSettings <bool>("AppSettings:WXPayStatus"); //支付宝支付 if (PayMethod.AliPay == order.pay_method) { //商户号ID string app_id = ConfigManage.AppSettings <string>("AppSettings:ALIPAY_APP_ID"); //AliRefundPayBizContent bizContent = new AliRefundPayBizContent(); //bizContent.out_trade_no = orderRefund.order_serial_no; //bizContent.refund_amount = PayStatus ? refund_amount : decimal.Parse("0.01"); ////string webRootPath = host.WebRootPath; //string privateKeyPem = host.ContentRootPath + "Config\\alipay_cret\\rsa_private_key.pem"; //string publicKeyPem = host.ContentRootPath + "Config\\alipay_cret\\rsa_public_key.pem"; //IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", app_id, privateKeyPem, "json", "1.0", "RSA2", publicKeyPem, "utf-8", true); //AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); //request.BizContent = JsonConvert.SerializeObject(bizContent); //AlipayTradeRefundResponse response = client.Execute(request); //if (!response.IsError) //{ // state = ServiceIoc.Get<OrderRefundService>().AliPayConfirmRefund(orderRefund.order_serial_no, order.id); //} //else { } }//微信app支付 else if (PayMethod.WeChat_App == order.pay_method) { RefundPay refundParam = new RefundPay(); //证书路径 DirectoryInfo Dir = Directory.GetParent(ConfigManage.AppSettings <string>("AppSettings:WeChat_App_CertPath")); string certPath = Dir.Parent.Parent.FullName; //证书密钥 //string certPwd = Settings.AppSettings("CertPwd"); //商户信息 WeChatMerchant merchant = ServiceIoc.Get <WeChatMerchantService>().Get(); refundParam.appid = merchant.app_id; //商户号 refundParam.mch_id = merchant.mch_id; //随机数 refundParam.nonce_str = StringHelper.CreateNoncestr(16); //商户侧传给微信的订单号 refundParam.out_trade_no = orderRefund.order_serial_no; //商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 refundParam.out_refund_no = orderRefund.refund_serial_no; //订单总金额,单位为分 refundParam.total_fee = PayStatus ? (int)(refund_amount * 100) : 1; //订单总金额,单位为分 refundParam.refund_fee = PayStatus ? (int)(refund_amount * 100) : 1; //操作员帐号, 默认为商户号 refundParam.op_user_id = merchant.mch_id; //退款 state = ServiceIoc.Get <OrderRefundService>().WeChatConfirmRefund(refundParam, order.id, certPath, merchant.mch_id, merchant.pay_key, out msg); }//微信公众号支付 else if (PayMethod.WeChat_JsApi == order.pay_method || PayMethod.WeChat_Native == order.pay_method) { RefundPay refundParam = new RefundPay(); //证书路径 DirectoryInfo Dir = Directory.GetParent(ConfigManage.AppSettings <string>("AppSettings:WeChat_App_CertPath")); string certPath = Dir.Parent.Parent.FullName; //证书密钥 //string certPwd = Settings.AppSettings("CertPwd"); //开放平台授权公众号信息 WeChatAccount weChatAccount = ServiceIoc.Get <WeChatAccountService>().Get(); refundParam.appid = weChatAccount.appid; //商户号 refundParam.mch_id = weChatAccount.mch_id; //随机数 refundParam.nonce_str = StringHelper.CreateNoncestr(16); //商户侧传给微信的订单号 refundParam.out_trade_no = orderRefund.order_serial_no; //商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔 refundParam.out_refund_no = orderRefund.refund_serial_no; //订单总金额,单位为分 refundParam.total_fee = PayStatus ? (int)(refund_amount * 100) : 1; //订单总金额,单位为分 refundParam.refund_fee = PayStatus ? (int)(refund_amount * 100) : 1; //操作员帐号, 默认为商户号 refundParam.op_user_id = weChatAccount.mch_id; //退款 state = ServiceIoc.Get <OrderRefundService>().WeChatConfirmRefund(refundParam, order.id, certPath, weChatAccount.mch_id, weChatAccount.pay_key, out msg); } return(Json(GetResult(state, msg))); } catch (Exception ex) { ServiceIoc.Get <APILogsService>().Save("提交退款SubmitRefundOrder==>" + ex.ToString()); return(Json(GetResult(StateCode.State_500))); } }