Exemplo n.º 1
0
        /// <summary>
        /// 统一收单交易支付接口
        /// </summary>
        /// <param name="request">提交给统一下单API的参数</param>
        /// <param name="config"></param>
        /// <param name="timeOut">超时时间</param>
        /// <returns>成功时返回,其他抛异常</returns>
        public static async Task <AlipayTradePayResponse> CreateOrder(AlipayTradePayModel request, AlipayConfig config, int timeOut = 6)
        {
            IAopClient client      = new AopClient(AlipayConstants.GATEWAYURL, config.AppId, config.PrivateKey, config.Format, config.Version, config.SignType, config.AliPublicKey, config.Charset, config.KeyFromFile);
            var        requestData = new AlipayTradePayRequest();

            requestData.SetNotifyUrl(config.NotifyUrl);
            requestData.SetReturnUrl(config.QuitUrl);
            requestData.SetBizModel(request);

            return(await client.ExecuteAsync(requestData));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 条码支付
        /// </summary>
        /// <param name="pay">条码支付实体</param>
        /// <param name="payBack">条码支付实体返回</param>
        /// <param name="message">错误信息</param>
        /// <returns></returns>
        internal bool Pay(Pay pay, out PayBack payBack, out string message)
        {
            _log.Info("条码支付 Pay 开始");
            var payRequst = new AlipayTradePayRequest();

            payRequst.SetNotifyUrl(AlipayConfig.NotifyUrl);
            payRequst.BizContent = JsonConvert.SerializeObject(pay, new Newtonsoft.Json.JsonSerializerSettings()
            {
                DefaultValueHandling = DefaultValueHandling.Ignore
            }).ToLower();
            var payResponse = client.Execute(payRequst);

            if (payResponse.Code == "10000")
            {
                _log.Info("条码支付成功!");
                payBack = new PayBack()
                {
                    Code                  = payResponse.Code,
                    Msg                   = payResponse.Msg,
                    Out_Trade_No          = payResponse.OutTradeNo,
                    Sub_Code              = payResponse.SubCode,
                    Sub_Msg               = payResponse.SubMsg,
                    Buyer_Logon_Id        = payResponse.BuyerLogonId,
                    Buyer_Pay_Amount      = Convert.ToDecimal(payResponse.BuyerPayAmount),
                    Buyer_User_Id         = payResponse.BuyerUserId,
                    Card_Balance          = Convert.ToDecimal(payResponse.CardBalance),
                    Discount_Goods_Detail = payResponse.DiscountGoodsDetail,
                    Fund_Bill_List        = GetTradeFundBills(payResponse.FundBillList),
                    Gmt_Payment           = Convert.ToDateTime(payResponse.GmtPayment),
                    Invoice_Amount        = Convert.ToDecimal(payResponse.InvoiceAmount),
                    Point_Amount          = Convert.ToDecimal(payResponse.PointAmount),
                    Receipt_Amount        = Convert.ToDecimal(payResponse.ReceiptAmount),
                    Store_Name            = payResponse.StoreName,
                    Total_Amount          = payResponse.TotalAmount,
                    Trade_No              = payResponse.TradeNo,
                    Voucher_Detail_List   = GetVoucherDetails(payResponse.VoucherDetailList)
                };
                message = "";
                return(true);
            }
            else
            {
                payBack = null;
                message = $"{ payResponse.Msg},{payResponse.SubMsg}";
                _log.Error($"条码支付失败:{message}");
                return(false);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Pay(string out_trade_no, string scene, string auth_code, string subject, string total_amount, string body, string notify_url)
        {
            var model = new AlipayTradePayModel()
            {
                Scene       = scene,
                AuthCode    = auth_code,
                Body        = body,
                Subject     = subject,
                TotalAmount = total_amount,
                OutTradeNo  = out_trade_no,
            };
            var req = new AlipayTradePayRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(notify_url);

            var response = await _client.ExecuteAsync(req);

            return(Ok(response.Body));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Pay(AlipayTradePayViewModel viewModel)
        {
            var model = new AlipayTradePayModel()
            {
                OutTradeNo  = viewModel.OutTradeNo,
                Subject     = viewModel.Subject,
                Scene       = viewModel.Scene,
                AuthCode    = viewModel.AuthCode,
                TotalAmount = viewModel.TotalAmount,
                Body        = viewModel.Body,
            };
            var req = new AlipayTradePayRequest();

            req.SetBizModel(model);
            req.SetNotifyUrl(viewModel.NotifyUrl);

            var response = await _client.ExecuteAsync(req);

            ViewData["response"] = response.Body;
            return(View());
        }
Exemplo n.º 5
0
        public AlipayF2FPayResult tradePay(AlipayTradePayContentBuilder builder, string notifyUrl)
        {
            AlipayF2FPayResult payResult = new AlipayF2FPayResult();

            try
            {
                AlipayTradePayRequest payRequest = new AlipayTradePayRequest();
                payRequest.BizContent = builder.BuildJson();
                payRequest.SetNotifyUrl(notifyUrl);
                AlipayTradePayResponse payResponse = client.Execute(payRequest);

                if (payResponse != null)
                {
                    switch (payResponse.Code)
                    {
                    case ResultCode.SUCCESS:
                        break;

                    //返回支付处理中,需要进行轮询
                    case ResultCode.INRROCESS:

                        AlipayTradeQueryResponse queryResponse = LoopQuery(builder.out_trade_no, 10, 3000);       //用订单号trade_no进行轮询也是可以的。
                        //轮询结束后还是支付处理中,需要调撤销接口
                        if (queryResponse != null)
                        {
                            if (queryResponse.TradeStatus == "WAIT_BUYER_PAY")
                            {
                                CancelAndRetry(builder.out_trade_no);
                                payResponse.Code = ResultCode.FAIL;
                            }
                            payResponse = toTradePayResponse(queryResponse);
                        }
                        break;

                    //明确返回业务失败
                    case ResultCode.FAIL:
                        break;

                    //返回系统异常,需要调用一次查询接口,没有返回支付成功的话调用撤销接口撤销交易
                    case ResultCode.ERROR:

                        AlipayTradeQueryResponse queryResponse2 = sendTradeQuery(builder.out_trade_no);

                        if (queryResponse2 != null)
                        {
                            if (queryResponse2.TradeStatus == TradeStatus.WAIT_BUYER_PAY)
                            {
                                AlipayTradeCancelResponse cancelResponse = CancelAndRetry(builder.out_trade_no);
                                payResponse.Code = ResultCode.FAIL;
                            }

                            payResponse = toTradePayResponse(queryResponse2);
                        }
                        break;

                    default:
                        payResult.response = payResponse;
                        break;
                    }
                    payResult.response = payResponse;
                    return(payResult);
                }
                else
                {
                    AlipayTradeQueryResponse queryResponse3 = sendTradeQuery(builder.out_trade_no);
                    if (queryResponse3 != null)
                    {
                        if (queryResponse3.TradeStatus == TradeStatus.WAIT_BUYER_PAY)
                        {
                            AlipayTradeCancelResponse cancelResponse = CancelAndRetry(builder.out_trade_no);
                            payResponse.Code = ResultCode.FAIL;
                        }
                        payResponse = toTradePayResponse(queryResponse3);
                    }
                    payResult.response = payResponse;
                    return(payResult);
                }
                return(payResult);
            }
            catch (Exception e)
            {
                AlipayTradePayResponse payResponse = new AlipayTradePayResponse();
                payResponse.Code   = ResultCode.FAIL;
                payResponse.Body   = e.Message;
                payResult.response = payResponse;
                return(payResult);
            }
        }