Пример #1
0
 internal static string ToPostDataString(this WxPayPaymentLimit value)
 {
     if (value == WxPayPaymentLimit.NoCreditCard)
     {
         return("no_credit");
     }
     else
     {
         return(null);
     }
 }
Пример #2
0
        public async Task <OrderReceipt> PlaceOrder(string appID, string mechantID, string deviceInfo, string description, IEnumerable <GoodsDetails> details, string attachNote, string orderID, string currency, int totalAmount, string clientIP, DateTime?validFrom, DateTime?expireAt, string couponTag, string callbackUrl, WxPayApiType apiType, string productID, WxPayPaymentLimit paymentLimit, string userOpenID)
        {
            dynamic postData = new WxPayData(_configuration.APIKey);

            postData.appid            = appID;
            postData.mch_id           = mechantID;
            postData.device_info      = deviceInfo;
            postData.body             = description;
            postData.detail           = SerializeGoodsDetails(details);
            postData.attach           = attachNote;
            postData.out_trade_no     = orderID;
            postData.fee_type         = currency;
            postData.total_fee        = totalAmount;
            postData.spbill_create_ip = clientIP;
            postData.time_start       = ConvertToEast8TimeString(validFrom);
            postData.time_expire      = ConvertToEast8TimeString(expireAt);
            postData.goods_tag        = couponTag;
            postData.notify_url       = callbackUrl;
            postData.trade_type       = apiType.ToPostDataString();
            postData.product_id       = productID;
            postData.limit_pay        = paymentLimit.ToPostDataString();
            postData.openid           = userOpenID;

            postData.Sign();

            HttpContent postContent = new ByteArrayContent(postData.ToByteArray());
            var         response    = await _httpClient.PostAsync("unifiedorder", postContent);

            if (!response.IsSuccessStatusCode)
            {
                throw new WxPayResponseInvalidException();
            }

            var resContent = await response.Content.ReadAsStringAsync();

            var resData = WxPayData.FromXml(resContent, _configuration.APIKey);

            if (resData.IsReturnedValid)
            {
                if (resData.VerifySignature())
                {
                    return(OrderReceipt.FromWxPayData(resData));
                }
                else
                {
                    throw new WxPaySignatureInvalidException("PlaceOrder return error");
                }
            }
            else
            {
                throw new WxPayResponseInvalidException(resData.ReturnedError);
            }
        }
Пример #3
0
 public async Task <OrderReceipt> PlaceNativeOrder(string description, IEnumerable <GoodsDetails> details, string attachNote, string orderID, string currency, int totalAmount, string clientIP, DateTime?expireAt, string couponTag, string productID, WxPayPaymentLimit paymentLimit, string callbackUrl)
 {
     return(await PlaceOrder(_configuration.AppID, _configuration.MechantID, _configuration.DeviceInfo,
                             description, details, attachNote, orderID, currency, totalAmount, clientIP, DateTime.Now, expireAt, couponTag,
                             callbackUrl, WxPayApiType.Native, productID, paymentLimit, null));
 }