Ejemplo n.º 1
0
 public async Task ExecuteAsync(HttpContext context)
 {
     try
     {
         var body = (await context.Request.ReadFormAsync()).AsNameValueCollection();
         if (body?.Count == 0)
         {
             throw new ArgumentNullException(nameof(body));
         }
         var request = new ScanPayRequest();
         request.AddParameters(new ScanPayModel()
         {
             Body       = body.Get("Body"),
             OutTradeNo = body.Get("Out_Trade_No"),
             TotalFee   = int.Parse(body.Get("Total_Amount"))
         });
         await context.Response.WriteAsync((await _client.ExecuteAsync(request)).ToJson());
     }
     catch (Exception ex)
     {
         context.Response.StatusCode = StatusCodes.Status500InternalServerError;
         await context.Response.WriteAsync(ex.Message);
     }
     context.Response.ContentType = "application/json; charset=UTF-8";
     await context.Response.Body.FlushAsync();
 }
Ejemplo n.º 2
0
        public async Task <OkObjectResult> ScanPay(string Body, string Out_Trade_No, int Total_Amount)
        {
            var request = new ScanPayRequest();

            request.AddParameters(new ScanPayModel()
            {
                Body       = Body,
                OutTradeNo = Out_Trade_No,
                TotalFee   = Total_Amount
            });
            return(Ok(await _client.ExecuteAsync(request)));
        }
Ejemplo n.º 3
0
        public IActionResult ScanPay(string order_id, int total_amount)
        {
            var request = new ScanPayRequest();

            request.AddGatewayData(new ScanPayModel()
            {
                TotalAmount = total_amount,
                OrderId     = order_id
            });

            var response = _gateway.Execute(request);

            return(Json(response));
        }
Ejemplo n.º 4
0
        public async Task ScanPayTest()
        {
            var gateway = GetService <IGateway>();
            var request = new ScanPayRequest(new ScanPayModel
            {
                OutTradeNo  = "abc001",
                TotalAmount = 0.01,
                Subject     = "spear_pay",
                Body        = "test"
            });
            var resp = await gateway.Execute(request);

            Print(resp);
        }
Ejemplo n.º 5
0
        public IHttpActionResult Pay([FromBody] ScanPayModel payModel)
        {
            var request = new ScanPayRequest();

            if (payModel.TotalAmount == 0)
            {
                payModel.TotalAmount = 500;
            }

            request.AddGatewayData(payModel);
            var response = _gateway.Execute(request);

            return(Json(response));
        }
Ejemplo n.º 6
0
        public ActionResult ScanPay(string out_trade_no, string body, int total_amount)
        {
            var request = new ScanPayRequest();

            request.AddGatewayData(new ScanPayModel()
            {
                Body        = body,
                TotalAmount = total_amount,
                OutTradeNo  = out_trade_no
            });

            var response = _gateway.Execute(request);

            return(Json(response));
        }
Ejemplo n.º 7
0
        public void TestScanPay()
        {
            var request = new ScanPayRequest();

            request.AddGatewayData(new ScanPayModel()
            {
                TotalAmount = 1,
                Subject     = "支付宝扫码支付测试",
                OutTradeNo  = _outTradeNo
            });

            var response = _alipayGateway.Execute(request);

            _output.WriteLine(response.QrCode);
            Assert.NotNull(response.QrCode);
        }
Ejemplo n.º 8
0
        public IHttpActionResult ScanPay(string out_trade_no, string subject, double total_amount, string body)
        {
            var request = new ScanPayRequest();

            request.AddGatewayData(new ScanPayModel()
            {
                Body        = body,
                TotalAmount = total_amount,
                Subject     = subject,
                OutTradeNo  = out_trade_no
            });

            if (_gateway != null)
            {
                var response = _gateway.Execute(request);

                return(Json(response));
            }

            return(Json(new string[] { "parameter _gateway is null" }));
        }