コード例 #1
0
ファイル: PaymentService.cs プロジェクト: pppp7973666/Wechat
        /// <summary>
        /// 微信内置JsAPI支付。
        /// </summary>
        /// <param name="order">订单信息。</param>
        /// <param name="openId">用户OpenId。</param>
        /// <param name="notifyUrl">回调通知地址。</param>
        /// <returns></returns>
        public virtual async Task <IJsPayment> CreatePayment(IPaymentOrder order, IOpenId openId, string notifyUrl)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (openId == null)
            {
                throw new ArgumentNullException("openId");
            }
            if (notifyUrl == null)
            {
                throw new ArgumentNullException("notifyUrl");
            }
            ValidateOrderInfo(order);
            var payData = OrderInfoToDictionary(order);

            payData.Add("trade_type", "JSAPI");
            payData.Add("openid", openId.OpenId);
            payData.Add("appid", AppId);                                          //公众账号ID
            payData.Add("mch_id", ShopId);                                        //商户号
            payData.Add("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串
            payData.Add("notify_url", notifyUrl);
            payData.Add("sign", GetSignature(payData, ShopKey));

            string backData = await HttpHelper.PostHttp(new Uri(CreatePayUrl), Encoding.UTF8.GetBytes(GetXml(payData)), "application/x-www-form-urlencoded", Encoding.UTF8);

            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);
            }
            JsPayment payment = new JsPayment();

            payment.PrepayId  = root.Element("prepay_id").Value;
            payment.Nonce     = Guid.NewGuid().ToString().Replace("-", "");
            payment.TradeType = root.Element("trade_type").Value;
            payment.TimeStamp = GetTimestamp();
            payment.Signature = GetSignature(new
            {
                appId     = AppId,
                timeStamp = payment.TimeStamp,
                nonceStr  = payment.Nonce,
                package   = "prepay_id=" + payment.PrepayId,
                signType  = "MD5"
            }, ShopKey);

            return(payment);
        }
コード例 #2
0
        public async Task <string> GetPaymentStatus(IPaymentOrder paymentOrder)
        {
            int idPagoElectronico = Convert.ToInt32(paymentOrder.UID);

            var SITPayment = await _apiClient.ValidatePayment(idPagoElectronico);

            var payment = Mapper.MapSITPaymentToPayment(SITPayment);

            return(payment.Status);
        }
コード例 #3
0
ファイル: PaymentService.cs プロジェクト: pppp7973666/Wechat
 /// <summary>
 /// 验证交易信息正确性。
 /// </summary>
 public virtual void ValidateOrderInfo(IPaymentOrder orderInfo)
 {
     if (string.IsNullOrEmpty(orderInfo.Title))
     {
         throw new Exception("Title不能为空。");
     }
     if (orderInfo.Title.Length > 32)
     {
         throw new Exception("Title长度不能大于32。");
     }
     if (orderInfo.Detail != null && orderInfo.Detail.Length > 8192)
     {
         throw new Exception("Detail长度不能大于8192。");
     }
     if (orderInfo.Comment != null && orderInfo.Comment.Length > 127)
     {
         throw new Exception("Comment长度不能大于8192。");
     }
     if (string.IsNullOrEmpty(orderInfo.TradeNo))
     {
         throw new Exception("TradeNo不能为空。");
     }
     if (orderInfo.TradeNo.Length > 32)
     {
         throw new Exception("TradeNo长度不能大于32。");
     }
     if (orderInfo.Currency != null && orderInfo.Currency.Length > 16)
     {
         throw new Exception("Currency长度不能大于16。");
     }
     if (orderInfo.Fee < 1)
     {
         throw new Exception("Fee不能小于1。");
     }
     if (string.IsNullOrEmpty(orderInfo.UserIp))
     {
         throw new Exception("UserIp不能为空。");
     }
     if (orderInfo.UserIp.Length > 32)
     {
         throw new Exception("UserIp长度不能大于16。");
     }
     if (orderInfo.Tag != null && orderInfo.Tag.Length > 32)
     {
         throw new Exception("Tag长度不能大于32。");
     }
     if (orderInfo.Device != null && orderInfo.Device.Length > 32)
     {
         throw new Exception("Device长度不能大于32。");
     }
 }
コード例 #4
0
ファイル: PaymentService.cs プロジェクト: pppp7973666/Wechat
        /// <summary>
        /// 微信二维码扫码支付。
        /// </summary>
        /// <param name="order">订单信息。</param>
        /// <param name="productId">商品Id。</param>
        /// <param name="notifyUrl">回调通知地址。</param>
        /// <returns></returns>
        public virtual async Task <IQrPayment> CreatePayment(IPaymentOrder order, string productId, string notifyUrl)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }
            if (productId == null)
            {
                throw new ArgumentNullException("productId");
            }
            if (productId.Length > 32)
            {
                throw new ArgumentOutOfRangeException("productId长度不能大于32。");
            }
            ValidateOrderInfo(order);
            var payData = OrderInfoToDictionary(order);

            payData.Add("trade_type", "NATIVE");
            payData.Add("product_id", productId);
            payData.Add("appid", AppId);                                          //公众账号ID
            payData.Add("mch_id", ShopId);                                        //商户号
            payData.Add("nonce_str", Guid.NewGuid().ToString().Replace("-", "")); //随机字符串
            payData.Add("notify_url", notifyUrl);
            payData.Add("sign", GetSignature(payData, ShopKey));

            string backData = await HttpHelper.PostHttp(new Uri(CreatePayUrl), Encoding.UTF8.GetBytes(GetXml(payData)), "application/x-www-form-urlencoded", Encoding.UTF8);

            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);
            }
            QrPayment payment = new QrPayment();

            payment.PrepayId  = root.Element("prepay_id").Value;
            payment.TradeType = root.Element("trade_type").Value;
            payment.QrUrl     = root.Element("code_url").Value;
            return(payment);
        }
コード例 #5
0
ファイル: PaymentService.cs プロジェクト: pppp7973666/Wechat
        private IDictionary <string, string> OrderInfoToDictionary(IPaymentOrder orderInfo)
        {
            Dictionary <string, string> payData = new Dictionary <string, string>();

            payData.Add("body", orderInfo.Title);
            payData.Add("out_trade_no", orderInfo.TradeNo);
            payData.Add("total_fee", orderInfo.Fee.ToString());
            payData.Add("spbill_create_ip", orderInfo.UserIp);
            if (orderInfo.Detail != null)
            {
                payData.Add("detail", orderInfo.Detail);
            }
            if (orderInfo.Comment != null)
            {
                payData.Add("attach", orderInfo.Comment);
            }
            if (orderInfo.Currency != null)
            {
                payData.Add("fee_type", orderInfo.Currency);
            }
            if (orderInfo.StartDate != null)
            {
                payData.Add("time_start", orderInfo.StartDate.Value.ToString("yyyyMMddHHmmss"));
            }
            if (orderInfo.ExpiredDate != null)
            {
                payData.Add("time_expire", orderInfo.ExpiredDate.Value.ToString("yyyyMMddHHmmss"));
            }
            if (orderInfo.Tag != null)
            {
                payData.Add("goods_tag", orderInfo.Tag);
            }
            if (orderInfo.Device != null)
            {
                payData.Add("device_info", orderInfo.Device);
            }
            return(payData);
        }
コード例 #6
0
 public UnitTest1()
 {
     _service    = new FakePaymentOrder();
     _controller = new PaymentController(_service);
 }
コード例 #7
0
 public PaymentOrderController(IPaymentOrder process, ICustomer processCustomer, ISaleOrderItem processItems)
 {
     _process = process;
 }
コード例 #8
0
 public PaymentController(IPaymentOrder paymentOrder)
 {
     _paymentOrder = paymentOrder;
 }