Example #1
0
 public AlipayRefundRequestContent(IGateWay gateWay, IRefundOrder order)
     : base(gateWay)
 {
     if (string.IsNullOrEmpty(order.OrderNo) && string.IsNullOrEmpty(order.PlatformTradeNo))
     {
         throw new PaymentArgumentException(gateWay.Name, "out_trade_no,trade_no", "参数错误out_trade_no和trade_no不能同时为空");
     }
     if (order.RefundAmount <= 0)
     {
         throw new PaymentArgumentException(gateWay.Name, "refund_amount", "参数错误refund_amount");
     }
     if (!string.IsNullOrEmpty(order.OrderNo))
     {
         this["out_trade_no"] = order.OrderNo;
     }
     if (!string.IsNullOrEmpty(order.PlatformTradeNo))
     {
         this["trade_no"] = order.PlatformTradeNo;
     }
     this["refund_amount"] = order.RefundAmount.ToString(CultureInfo.InvariantCulture);
 }
Example #2
0
        public void Refund()
        {
            IRefundOrder order = GetRefundOrder();

            if (order != null)
            {
                PayProvider pay = LoadProvider(order.PayProvider);
                if (pay != null)
                {
                    if (pay.IsOnlinePay)
                    {
                        OnSubmit(pay.Refund(this, pay.PackData(order.TradeNo, order), SubmitText));
                    }
                    else
                    {
                        RefundResult result = new RefundResult(new RefundInfo()
                        {
                            PayTradeNo = order.PayTradeNo,
                            TotalFee   = order.TotalFee,
                            Status     = true
                        });
                        OnCallback(pay, true, result);
                        OnRedirect(this, pay, result, true);
                        //try { Response.Redirect(ReturnUrl, true); }
                        //catch (Exception) { }
                    }
                }
                else
                {
                    OnError(string.Concat("第三方支付\"", order.PayProvider, "\"不被支持或已禁用!"));
                }
            }
            else
            {
                OnError(string.Concat("获取订单信息错误!"));
            }
        }
Example #3
0
        /// <summary>
        /// 微信交易退款。
        /// </summary>
        /// <param name="refundInfo">退款信息。</param>
        /// <returns></returns>
        public virtual async Task <IRefundResult> RefundPayment(IRefundOrder refundInfo)
        {
            if (refundInfo == null)
            {
                throw new ArgumentNullException("refundInfo");
            }
            if (!IsCertificateEnabled)
            {
                throw new NotSupportedException("不支持没有证书的操作。");
            }
            var payData = new Dictionary <string, string>();

            payData.Add("appid", AppId);
            payData.Add("mch_id", ShopId);
            payData.Add("nonce_str", Guid.NewGuid().ToString().Replace("-", ""));//随机字符串
            if (refundInfo.TransactionId != null)
            {
                payData.Add("transaction_id", refundInfo.TransactionId);
            }
            else
            {
                payData.Add("out_trade_no", refundInfo.TradeNo);
            }
            payData.Add("total_fee", refundInfo.RefundNo);
            payData.Add("refund_fee", refundInfo.TradeNo);
            if (refundInfo.RefundCurrency != null)
            {
                payData.Add("refund_fee_type", refundInfo.TradeNo);
            }
            payData.Add("op_user_id", refundInfo.Operator ?? ShopId);
            payData.Add("sign", GetSignature(payData, ShopKey));


            string backData = await HttpHelper.PostHttp(new Uri(RefundPayUrl), Encoding.UTF8.GetBytes(GetXml(payData)), "text/xml", Encoding.UTF8, 5000, Certificate);

            XElement root = XDocument.Parse(backData).Element("xml");

            if (root.Element("return_code").Value == "FAIL")
            {
                string errMsg = root.Element("return_msg").Value;
                throw new WechatException(errMsg);
            }
            if (root.Element("result_code").Value == "FAIL")
            {
                string errMsg = root.Element("err_code").Value;
                throw new WechatException(errMsg);
            }

            RefundResult result = new RefundResult();

            result.RefundId      = root.Element("refund_id").Value;
            result.RefundChannel = root.Element("refund_channel").Value;
            result.RefundFee     = int.Parse(root.Element("refund_fee").Value);
            result.RefundNo      = root.Element("out_refund_no").Value;
            result.Status        = RefundStatus.PROCESSING;
            if (root.Element("cash_refund_fee") != null)
            {
                result.RefundCash = int.Parse(root.Element("cash_fee").Value);
            }
            if (root.Element("coupon_refund_fee") != null)
            {
                result.Coupon = int.Parse(root.Element("coupon_refund_fee").Value);
            }
            return(result);
        }
Example #4
0
 private static string Format(IRefundOrder order)
 {
     return(string.Concat(order.PayTradeNo, '^', order.TotalFee.ToString("F2"), '^', Format(order.Subject)));
 }