Ejemplo n.º 1
0
        /// <summary>
        /// 发起订单退款
        /// </summary>
        /// <param name="refundRequest">退款申请参数</param>
        /// <returns></returns>
        public override ApiResultModel <string> RefundPay(RefundBaseRequest refundRequest)
        {
            var res = new ApiResultModel <string>()
            {
                Code = ApiResultCode.Fail, Message = "fail"
            };

            string total_fee  = refundRequest.OrderMoney.ToString("#0.00");
            string refund_fee = refundRequest.RefundMoney.ToString("#0.00");
            //退款请求
            IAopClient client = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.AppId, AliPayConfig.privatekey, "json", "1.0", AliPayConfig.sign_type, AliPayConfig.alipublickey, AliPayConfig.charset, false);
            AlipayTradeRefundRequest request     = new AlipayTradeRefundRequest();
            AlipayTradeRefundModel   alipayModel = new AlipayTradeRefundModel()
            {
                OutTradeNo   = refundRequest.OrderCode,
                TradeNo      = refundRequest.TradeNo,
                RefundAmount = refund_fee,
                RefundReason = "用户申请退款",
            };

            request.SetBizModel(alipayModel);
            AlipayTradeRefundResponse response = client.Execute(request);

            //2.2、记录请求日志
            //记录支付宝退款调用的日志
            //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderRefund.OrderCode, ThirdPlatformType.Alipay, AliPayConfig.gatewayUrl, request.BizContent, DateTime.Now, response.Body, DateTime.Now, true);
            if (response.Code != "10000")
            {
                res.Message = response.Msg;
                return(res);
            }
            res.Code    = ApiResultCode.Success;
            res.Message = "ok";
            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发起订单退款
        /// </summary>
        /// <param name="refundRequest">退款申请参数</param>
        /// <returns></returns>
        public override ApiResultModel <string> RefundPay(RefundBaseRequest refundRequest)
        {
            ApiResultModel <string> res = new ApiResultModel <string> {
                Code = ApiResultCode.Fail
            };

            //处理退款金额,不能超过支付金额
            var orderRefund     = refundRequest.OrderMoney;
            var orderRefundCode = refundRequest.RefundRemark;


            //2、实际退款请求
            string total_fee = (refundRequest.OrderMoney * 100).ToString("f0");

            int.TryParse(total_fee, out int _total_fee);

            string refund_fee = (refundRequest.RefundMoney * 100).ToString("f0");

            int.TryParse(refund_fee, out int _refund_fee);

            WxPayData data = new WxPayData();

            data.SetValue("transaction_id", refundRequest.TradeNo);
            data.SetValue("out_trade_no", refundRequest.OrderCode);
            data.SetValue("total_fee", _total_fee);
            data.SetValue("refund_fee", _refund_fee);
            data.SetValue("refund_desc", "用户申请退款");
            data.SetValue("out_refund_no", orderRefundCode);
            data.SetValue("appid", AppId);
            data.SetValue("mch_id", MchId);

            //2.1、实际退款请求
            var result = WxPayApi.Refund(data, key: Key);

            //2.2、记录请求日志
            //记录微信退款调用的日志
            //string url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
            //WritePostThirdApi(ThirdPlatformBusinessType.Payment, orderRefund.OrderCode, ThirdPlatformType.WechatPay, url, data.ToXml(), DateTime.Now, result.ToXml(), DateTime.Now, true);

            //3、退款结果验证
            if (result.GetValue("return_code").ToString() != "SUCCESS")
            {
                res.Message = string.Format("{0}({1})", result.GetValue("return_msg").ToString(), result.GetValue("return_code").ToString());
                return(res);
            }
            if (result.GetValue("result_code").ToString() != "SUCCESS")
            {
                res.Message = string.Format("{0}({1})", result.GetValue("err_code_des").ToString(), result.GetValue("result_code").ToString());
                return(res);
            }

            res.Code = ApiResultCode.Success;
            return(res);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 发起订单退款
 /// </summary>
 /// <param name="refundRequest">退款申请参数</param>
 /// <returns></returns>
 public abstract ApiResultModel <string> RefundPay(RefundBaseRequest refundRequest);