Exemplo n.º 1
0
        public BarcodePayResponse BarcodePay(PayRequest payRequest)
        {
            _gateway = _gateways.GetByStoreId <AlipayGateway>(payRequest.GetStoreId());
            var queryModel = Newtonsoft.Json.JsonConvert.DeserializeAnonymousType(payRequest.BizContent, new { body = "", total_amount = 0, out_trade_no = "", auth_code = "", subject = "" });

            // 记录支付日志
            var content    = JsonConvert.SerializeObject(payRequest);
            var payHistory = new PaymentHistory();

            payHistory.LogAlipayBarcodeRequestPay(queryModel.out_trade_no, queryModel.total_amount.ToString(), "saleorder", content);
            _db.Insert(payHistory);
            _db.SaveChange();

            var request = new BarcodePayRequest();

            request.AddGatewayData(new BarcodePayModel()
            {
                Body        = queryModel.body,
                TotalAmount = queryModel.total_amount,
                Subject     = queryModel.subject,
                OutTradeNo  = queryModel.out_trade_no,
                AuthCode    = queryModel.auth_code
            });
            request.PaySucceed += BarcodePay_PaySucceed;
            request.PayFailed  += BarcodePay_PayFaild;

            var response = _gateway.Execute(request);

            return(response);
        }