public async Task <PaymentCallbackResponse> GetPaymentResultAsync(PaymentQueryRequest request) { SettleObject inputObj = new SortedDictionary <string, object>(); InitAlipayData(inputObj); inputObj.SetValue("method", "alipay.trade.query"); var bzContent = new { out_trade_no = request.OrderId }; inputObj.SetValue("biz_content", JsonConvert.SerializeObject(bzContent)); inputObj.SetValue("sign", MakeSign(inputObj)); var result = await GetAsStringAsync($"{_options.Alipay.Gateway}?{inputObj.ToUrl()}"); var json = JObject.Parse(result); var data = json.SelectToken("alipay_trade_query_response").ToObject <IDictionary <string, object> >(); var sign = json.SelectToken("sign").ToObject <string>(); if (!CheckSign(JsonConvert.SerializeObject(data), sign)) { throw new SettleException("支付宝获取支付状态验签失败"); } try { var success = data["trade_status"]?.ToString(); return(new PaymentCallbackResponse { OrderId = request.OrderId, ProviderId = data.ContainsKey("trade_no") ? data["trade_no"]?.ToString() : string.Empty, Success = success == "TRADE_SUCCESS" || success == "TRADE_FINISHED" }); } catch { throw new SettleException(result); } }
public async Task <PaymentCallbackResponse> GetPaymentResultAsync(PaymentQueryRequest request) { SettleObject inputObj = new SortedDictionary <string, object>(); inputObj.SetValue("appid", _options.WeChat.AppId); inputObj.SetValue("mch_id", _options.WeChat.MchId); inputObj.SetValue("out_trade_no", request.OrderId); inputObj.SetValue("nonce_str", GenerateNonceStr()); inputObj.SetValue("sign", MakeSign(inputObj)); var xml = ToXml(inputObj); var url = $"{_options.WeChat.Gateway}/pay/orderquery"; var response = await PostAsStringAsync(url, xml); var result = FromXml(response); if (!CheckSign(result)) { throw new SettleException("签名错误"); } return(new PaymentCallbackResponse { OrderId = request.OrderId, ProviderId = result.GetValue <string>("transaction_id"), Success = result.GetValue <string>("trade_state") == "SUCCESS" }); }
/// <summary> /// İşlem Sorgulama /// </summary> /// <param name="payment">PaymentToken veya TransactionId alanlarından birinin gönderilmesi yeterlidir. İkisinin aynı anda gönderim zorunluluğu yoktur.</param> /// <returns></returns> public PaymentQueryResponse Query(PaymentQueryRequest payment) { #region Pos Configuration string strHostAddress = payment.ServiceUrl; #endregion var postData = new StringBuilder(); postData.AppendFormat("{0}={1}&", "Password", payment.Password); postData.AppendFormat("{0}={1}&", "TransactionId", payment.TransactionId); postData.AppendFormat("{0}={1}&", "PaymentToken", payment.PaymentToken); byte[] postByteArray = Encoding.UTF8.GetBytes(postData.ToString()); WebRequest webRequest = WebRequest.Create(strHostAddress); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = postByteArray.Length; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | (SecurityProtocolType)768 | (SecurityProtocolType)3072 | SecurityProtocolType.Tls; Stream dataStream = webRequest.GetRequestStream(); dataStream.Write(postByteArray, 0, postByteArray.Length); dataStream.Close(); WebResponse webResponse = webRequest.GetResponse(); dataStream = webResponse.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); var queryResponse = new PaymentQueryResponse(); //bankResponse.Response = reader.ReadToEnd(); //bankResponse.IsSuccessful = true; reader.Close(); dataStream.Close(); webResponse.Close(); return(queryResponse); }
public ActionResult Detail(Guid paymentId) { var request = new PaymentQueryRequest(paymentId); var response = _paymentQueryService.GetPaymentDetailById(request); return(View("Detail", response)); }
public Task <PaymentCallbackResponse> GetPaymentResultAsync(PaymentQueryRequest request) { var p = ChannelConvertor.ToProvider(request.Channel); var c = _channels[p]; return(c.GetPaymentResultAsync(request)); }
public PaymentViewResponse QueryPayments(PaymentQueryRequest request) { var result = _paymentRepository.QueryPayments(request.PayChannels, request.PayStatuses, request.OrderNO, request.PayTime, request.PageIndex, request.PageSize); var total = result.total; var payments = _mapper.Map <IList <PaymentDto> >(result.payments); PaymentViewResponse response = new PaymentViewResponse() { PageIndex = request.PageIndex, PageSize = request.PageSize, Payments = payments, Total = total }; return(response); }
public Task <PaymentCallbackResponse> GetPaymentResultAsync(PaymentQueryRequest request) { throw new NotImplementedException(); }
public IActionResult Post([FromBody] PaymentQueryRequest paymentQuery) { var response = _paymentService.QueryPayments(paymentQuery); return(Ok(response)); }