public static bool Cancel(string refNo, string payType, decimal amount, out CancelResponseModel response) { bool result; try { string jsonString = new CancelService { refNo = refNo, payType = payType, transAmount = amount }.DefContent(); response = null; response = JsonHelper.JsonDeserialize <List <CancelResponseModel> >(jsonString)[0]; result = true; } catch { response = null; result = false; } return(result); }
/// <summary> /// 撤销订单 /// </summary> /// <param name="cancelModel">请求参数</param> /// <returns></returns> public void AlipayCancel(CancelModel cancelModel, Action <bool, CancelResponseModel> aliPayCancelCallBack) { CancelResponseModel response = ServiceUtil.AliPayClient.Cancel(cancelModel); ServiceUtil.AliPayClient.Close(); if (response.code == TradepayResultCode.TRADE_SUCCESS) { aliPayCancelCallBack(true, response); } else { if (response.retry_flag == "Y") { Thread.Sleep(3000); //间隔3s请求一次 AlipayCancel(cancelModel, aliPayCancelCallBack); } else { aliPayCancelCallBack(false, response); } } }
public async Task <CancelResponseModel> Cancel(CancelRequestModel request) { var securityUrl = request.Settings["SecurityUrl"]; var userName = request.Settings["UserName"]; var password = request.Settings["Password"]; var voidUrl = request.Settings["VoidUrl"]; var merchantId = request.Settings["MerchantId"]; var token = await this._visaNetSecurityTokenService.GetToken(securityUrl, userName, password); var requestMessage = new { order = new { purchaseNumber = request.OrderNumber, transactionDate = request.TransactionDate.ToString("yyyyMMdd") } }; var headers = new Dictionary <string, string>(); headers.Add("authorization", token); using (var proxy = new HttpClient()) { var httpRequest = new HttpRequestMessage(HttpMethod.Post, $"{voidUrl}/reverse/ecommerce/{merchantId}"); foreach (var h in headers) { httpRequest.Headers.TryAddWithoutValidation(h.Key, h.Value); } var json = Newtonsoft.Json.JsonConvert.SerializeObject(requestMessage); httpRequest.Content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await proxy.SendAsync(httpRequest); if (response.IsSuccessStatusCode) { var data = Newtonsoft.Json.JsonConvert.DeserializeObject <CancelResultModel>(await response.Content.ReadAsStringAsync()); var result = new CancelResponseModel { Success = true }; return(result); } var errorData = Newtonsoft.Json.JsonConvert.DeserializeObject <CancelFailedResultModel>(await response.Content.ReadAsStringAsync()); return(new CancelResponseModel { Success = false, Errors = new List <TransactionErrorResponseModel> { new TransactionErrorResponseModel { Code = errorData.ErrorCode, Message = errorData.ErrorMessage } } }); } }