/// <summary> /// 东方支付商品申报回调 /// </summary> /// <param name="collection"></param> /// <returns></returns> public string EasiPayDeclareProductBack(NameValueCollection collection) { try { #region 写系统Log ApplicationEventLog log = new ApplicationEventLog() { Source = "B2C site ProductDeclare", EventType = 8, HostName = "B2C", EventTitle = "ProductDeclare callback", EventMessage = Charges.BuildStringFromNameValueCollection(collection), LanguageCode = ConstValue.LanguageCode, CompanyCode = ConstValue.CompanyCode, StoreCompanyCode = ConstValue.StoreCompanyCode }; CommonDA.CreateApplicationEventLog(log); #endregion EasiPayProductDeclareBackInfo backResult = SerializationUtility.JsonDeserialize <EasiPayProductDeclareBackInfo>(collection["EData"]); var customsInfo = ShoppingOrderDA.LoadVendorCustomsInfoByProduct(backResult.cargoes.FirstOrDefault().cargoCode); #region 验证签名 if (!EasiPaySODeclareBackVerifySign(collection["EData"], customsInfo.CBTProductDeclareSecretKey, collection["SignMsg"])) { throw new Exception("商品申报回调,验证签名失败!" + Charges.BuildStringFromNameValueCollection(collection)); } #endregion bool bHandleResult = true; var client = new Common.RestClient.RestClient(ConstValue.ECCServiceBaseUrl, ConstValue.LanguageCode); RestServiceError error; object obj = new object(); string serviceUrl = "/SOService/SO/Job/DeclareProductCallBack"; client.Query(serviceUrl, backResult.cargoes.ToJsonString(), out obj, out error); if (error != null) { bHandleResult = false; StringBuilder sb = new StringBuilder(); error.Faults.ForEach(e => sb.AppendLine(e.ErrorDescription)); if (error.Faults.All(e => e.IsBusinessException)) { return(sb.ToString()); } ECommerce.Utility.Logger.WriteLog(sb.ToString(), "ProductDeclareCallback", "ProductDeclareCallbackUpdateFailure"); } return(BuildPaymentCallbackReturnResult(111, bHandleResult)); } catch (Exception ex) { //系统异常,写日志 ECommerce.Utility.Logger.WriteLog(string.Format("系统异常,异常信息:{0}!", ex.ToString()), "ProductDeclareCallback", "ProductDeclareBgCallbackFailure"); return(BuildPaymentCallbackReturnResult(111, false)); } }
/// <summary> /// 东方支付退款后台回调 /// </summary> /// <param name="collection"></param> /// <returns></returns> public string EasiPayRefundBack(NameValueCollection collection) { try { #region 写系统Log ApplicationEventLog log = new ApplicationEventLog() { Source = "B2C site refund", EventType = 8, HostName = "B2C", EventTitle = "Refund callback", EventMessage = Charges.BuildStringFromNameValueCollection(collection), LanguageCode = ConstValue.LanguageCode, CompanyCode = ConstValue.CompanyCode, StoreCompanyCode = ConstValue.StoreCompanyCode }; CommonDA.CreateApplicationEventLog(log); #endregion CallbackContext context = new CallbackContext(); context.PaymentModeId = 111; context.ResponseForm = collection; Charges charge = Charges.GetInstance(context); charge.UpdateCallbackPayment(context); if (charge.VerifySign(context)) { string trxContent = Charges.Base64Decode(context.ResponseForm["TRX_CONTENT"]); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(trxContent); string code = xmlDoc.SelectSingleNode("EasipayB2CResponse/ResData/RTN_CODE").InnerText; if (code.Equals("000000")) { string serno = xmlDoc.SelectSingleNode("EasipayB2CResponse/ResData/REFTRX_SERNO").InnerText; string refundStatus = xmlDoc.SelectSingleNode("EasipayB2CResponse/ResData/REFUND_STATE").InnerText; bool bRefundStatus = refundStatus.Equals("S") ? true : false; Refund(serno, bRefundStatus); } return(BuildPaymentCallbackReturnResult(111, true)); } ECommerce.Utility.Logger.WriteLog("返回退款回调失败", "RefundCallback", "CheckRefundResult"); return(BuildPaymentCallbackReturnResult(111, false)); } catch (Exception ex) { //系统异常,写日志 ECommerce.Utility.Logger.WriteLog(string.Format("系统异常,异常信息:{0}!", ex.ToString()), "RefundCallback", "RefundBgCallbackFailure"); return(BuildPaymentCallbackReturnResult(111, false)); } }
/// <summary> /// 财付通退款后台回调 /// </summary> /// <param name="collection"></param> /// <returns></returns> public string TenPayRefundBack(NameValueCollection collection) { try { #region 写系统Log ApplicationEventLog log = new ApplicationEventLog() { Source = "B2C site refund", EventType = 8, HostName = "B2C", EventTitle = "TenPay Refund callback", EventMessage = Charges.BuildStringFromNameValueCollection(collection), LanguageCode = ConstValue.LanguageCode, CompanyCode = ConstValue.CompanyCode, StoreCompanyCode = ConstValue.StoreCompanyCode }; CommonDA.CreateApplicationEventLog(log); #endregion CallbackContext context = new CallbackContext(); context.PaymentModeId = 114; context.ResponseForm = collection; Charges charge = Charges.GetInstance(context); charge.UpdateCallbackPayment(context); if (charge.VerifySign(context)) { bool bRefundStatus = false; string serno = context.ResponseForm["refund_id"]; string code = context.ResponseForm["refund_status"]; if (code.Equals("4") || code.Equals("10")) { bRefundStatus = true; } var status = bRefundStatus ? SOIncomeStatus.Confirmed : SOIncomeStatus.ProcessingFailed; ShoppingOrderDA.Refund(serno, status); return(BuildPaymentCallbackReturnResult(114, true)); } ECommerce.Utility.Logger.WriteLog("返回退款回调失败", "RefundCallback", "CheckRefundResult"); return(BuildPaymentCallbackReturnResult(114, false)); } catch (Exception ex) { //系统异常,写日志 ECommerce.Utility.Logger.WriteLog(string.Format("系统异常,异常信息:{0}!", ex.ToString()), "RefundCallback", "RefundBgCallbackFailure"); return(BuildPaymentCallbackReturnResult(111, false)); } }
/// <summary> /// 支付后台回调 /// </summary> /// <param name="payTypeSysNo">支付方式系统编号</param> /// <param name="collection">POST数据集合</param> /// <returns></returns> public string PaymentCallback(int payTypeSysNo, NameValueCollection collection, out CallbackContext context) { context = new CallbackContext(); try { #region [ 写系统Log ] ApplicationEventLog log = new ApplicationEventLog() { Source = "B2C site pay", EventType = 8, HostName = "B2C", EventTitle = "Pay callback", EventMessage = Charges.BuildStringFromNameValueCollection(collection), LanguageCode = ConstValue.LanguageCode, CompanyCode = ConstValue.CompanyCode, StoreCompanyCode = ConstValue.StoreCompanyCode }; CommonDA.CreateApplicationEventLog(log); #endregion context.PaymentModeId = payTypeSysNo; context.ResponseForm = collection; Charges charge = Charges.GetInstance(context); context.SOSysNo = charge.GetSOSysNo(context); context.SOInfo = ShoppingOrderDA.PayGetOrderInfoBySOSysNo(context.SOSysNo); charge.UpdateCallbackPayment(context); //如果为泰隆网关支付,写入积分消费记录 //if (payTypeSysNo == 201) //{ // CreateUserBankPointRecord(context); //} if (charge.VerifySign(context)) { #region [ 检查返回的订单实际支付金额与订单需要支付的金额是否相等,否则不予处理 ] if (context.SOInfo == null) { return(BuildPaymentCallbackReturnResult(payTypeSysNo, false)); } if (!charge.GetPayAmount(context).ToString("F2").Equals(context.SOInfo.RealPayAmt.ToString("F2"))) { ECommerce.Utility.Logger.WriteLog("订单实际支付金额与订单需要支付的金额不相等!", "PayCallback", "CheckPayAmount"); return(BuildPaymentCallbackReturnResult(payTypeSysNo, false)); } #endregion #region [ 检查NetPay是否存在并且状态为>=0,是则已支付过 ] NetpayInfo netPayInfo = ShoppingOrderDA.GetCenterDBNetpayBySOSysNo(context.SOSysNo); if (netPayInfo != null && netPayInfo.Status > (int)NetPayStatusType.Origin) { ECommerce.Utility.Logger.WriteLog("订单已经支付!", "PayCallback", "CheckNetPay"); return(BuildPaymentCallbackReturnResult(payTypeSysNo, true)); } #endregion if (charge.GetPayResult(context)) { //支付成功 using (ITransaction scope = TransactionManager.Create()) { #region 1.写Netpay netPayInfo = new NetpayInfo() { SOSysNo = context.SOSysNo, PayTypeSysNo = payTypeSysNo, PayAmount = context.SOInfo.RealPayAmt, Source = 0, Status = NetPayStatusType.Verified, CompanyCode = context.SOInfo.CompanyCode, LanguageCode = context.SOInfo.LanguageCode, CurrencySysNo = context.SOInfo.CurrencySysNo, StoreCompanyCode = context.SOInfo.StoreCompanyCode, OrderAmt = (context.SOInfo.SoAmt - Math.Abs((context.SOInfo.Amount.PointPay * 1.00m) / decimal.Parse(ConstValue.PointExhangeRate)) - Math.Abs(context.SOInfo.PromotionAmt) + Math.Abs(context.SOInfo.Amount.PayPrice) + Math.Abs(context.SOInfo.Amount.ShipPrice) + Math.Abs(context.SOInfo.Amount.PremiumAmt) - Math.Abs(context.SOInfo.Amount.DiscountAmt) + Math.Abs(context.SOInfo.TariffAmt) ), PrePayAmt = context.SOInfo.Amount.PrepayAmt, PointPayAmt = context.SOInfo.PointPay * 1.00m / decimal.Parse(ConstValue.PointExhangeRate), GiftCardPayAmt = context.SOInfo.Amount.GiftCardPay, SerialNumber = charge.GetSerialNumber(context), PayProcessTime = charge.GetPayProcessTime(context) }; bool isTrue = ShoppingOrderDA.CreateNetpay(netPayInfo); #endregion if (!isTrue) { //解决前后台多次并发处理重复数据 ECommerce.Utility.Logger.WriteLog("订单已经支付!", "PayCallback", "CreateNetPay"); return(BuildPaymentCallbackReturnResult(payTypeSysNo, false)); } if (ConstValue.PaymentInventory) { List <OrderItem> subOrderItemList = new List <OrderItem>(); context.SOInfo.SOItemList.ForEach(Item => { OrderProductItem opitem = new OrderProductItem(); opitem["Quantity"] = Item.Quantity; opitem.ProductSysNo = int.Parse(Item.ProductID); opitem.ProductName = Item.ProductName; opitem.WarehouseNumber = int.Parse(Item.WarehouseNumber); subOrderItemList.Add(opitem); }); subOrderItemList.ForEach(Item => { //限时促销 if (PipelineDA.CheckCountDownByProductSysNo(Item.ProductSysNo)) { //扣减订单商品库存 int inventoryType = PipelineDA.GetInventoryType(Item); var rowCount = PipelineDA.UpdateInventory(Item); if (rowCount != 1 && inventoryType != 1 && inventoryType != 3 && inventoryType != 5) { ECommerce.Utility.Logger.WriteLog("inventory: qty is not enough", "SOPipeline.CreateSOBasicPersister"); throw new BusinessException(string.Format("商品【{0}】库存不足", Item.ProductName)); } rowCount = PipelineDA.UpdateInventoryStock(Item); if (rowCount != 1 && inventoryType != 1 && inventoryType != 3 && inventoryType != 5) { ECommerce.Utility.Logger.WriteLog("inventory_stock: qty is not enough", "SOPipeline.CreateSOBasicPersister"); throw new BusinessException(string.Format("商品【{0}】库存不足", Item.ProductName)); } } }); } #region 2.发送支付成功邮件 //确认不需要发邮件 //CustomerInfo customer = CustomerDA.GetCustomerInfo(context.SOInfo.CustomerSysNo); //if (!string.IsNullOrWhiteSpace(customer.Email)) //{ // AsyncEmail email = new AsyncEmail(); // email.MailAddress = customer.Email; // email.CustomerID = customer.CustomerID; // email.Status = (int)EmailStatus.NotSend; // string token = Guid.NewGuid().ToString("N"); // email.ImgBaseUrl = ConfigurationManager.AppSettings["CDNWebDomain"].ToString(); // email.SetNewTokenUrl = "/EmailVerifySucceed?token=" + token + "&sysno=" + customer.SysNo.ToString() + "&email=" + System.Web.HttpUtility.HtmlEncode(customer.Email); // string subject = string.Empty; // email.MailBody = MailHelper.GetMailTemplateBody("SalesOrderPaySuccessful", out subject); // email.MailSubject = subject.Replace("[SOSysNo]", context.SOInfo.SoSysNo.ToString()); // //订单内容 // email.MailBody = email.MailBody.Replace("[CustomerName]", customer.CustomerName); // email.MailBody = email.MailBody.Replace("[SOSysNo]", context.SOInfo.SoSysNo.ToString()); // email.MailBody = email.MailBody.Replace("[PayAmount]", context.SOInfo.RealPayAmt.ToString("F2")); // email.MailBody = email.MailBody.Replace("[PayTypeName]", context.SOInfo.Payment.PayTypeName); // email.MailBody = email.MailBody.Replace("[OrderDate]", context.SOInfo.OrderDate.ToString()); // email.MailBody = email.MailBody.Replace("[ReceiveName]", context.SOInfo.ReceiveName); // email.MailBody = email.MailBody.Replace("[SOMemo]", context.SOInfo.Memo); // email.MailBody = email.MailBody.Replace("[NowDate]", DateTime.Now.ToShortDateString()); // EmailDA.SendEmail(email); //} #endregion scope.Complete(); } return(BuildPaymentCallbackReturnResult(payTypeSysNo, true)); } else { ECommerce.Utility.Logger.WriteLog("返回支付失败", "PayCallback", "CheckPayResult"); return(BuildPaymentCallbackReturnResult(payTypeSysNo, false)); } } else { //验签失败 return(BuildPaymentCallbackReturnResult(payTypeSysNo, false)); } } catch (Exception ex) { //系统异常,写日志 ECommerce.Utility.Logger.WriteLog(string.Format("系统异常,异常信息:{0}!", ex.ToString()), "PayCallback", "OnlinePayBgCallbackFailure"); return(BuildPaymentCallbackReturnResult(payTypeSysNo, false)); } }
public string EasiPaySODeclareBack(NameValueCollection collection) { try { #region 写系统Log ApplicationEventLog log = new ApplicationEventLog() { Source = "B2C site SODeclare", EventType = 8, HostName = "B2C", EventTitle = "SODeclare callback", EventMessage = Charges.BuildStringFromNameValueCollection(collection), LanguageCode = ConstValue.LanguageCode, CompanyCode = ConstValue.CompanyCode, StoreCompanyCode = ConstValue.StoreCompanyCode }; CommonDA.CreateApplicationEventLog(log); #endregion EasiPaySODeclareBackInfo backResult = SerializationUtility.JsonDeserialize <EasiPaySODeclareBackInfo>(collection["EData"]); int SOSysNo = int.Parse(backResult.merchantOrderId); int status = 0; var customsInfo = ShoppingOrderDA.LoadVendorCustomsInfo(SOSysNo); #region 验证签名 if (!EasiPaySODeclareBackVerifySign(collection["EData"], customsInfo.CBTSODeclareSecretKey, collection["SignMsg"])) { throw new Exception("订单申报回调,验证签名失败!" + Charges.BuildStringFromNameValueCollection(collection)); } #endregion bool bHandleResult = true; var client = new Common.RestClient.RestClient(ConstValue.ECCServiceBaseUrl, ConstValue.LanguageCode); ECommerce.Facade.Common.RestClient.RestServiceError error; string serviceUrl = ""; if (backResult.status.Equals("1")) { //成功 status = 10; serviceUrl = "/SOService/SO/UpdateSOStatusToReported"; client.Update(serviceUrl, backResult.merchantOrderId, out error); if (error != null) { bHandleResult = false; StringBuilder sb = new StringBuilder(); error.Faults.ForEach(e => sb.AppendLine(e.ErrorDescription)); if (error.Faults.All(e => e.IsBusinessException)) { return(sb.ToString()); } ECommerce.Utility.Logger.WriteLog(sb.ToString(), "SODeclareCallback", "SODeclareBgCallbackUpdateFailure"); } if (ShoppingOrderDA.GetOrderTradeType(int.Parse(backResult.merchantOrderId)) == TradeType.DirectMail) { //如果是直邮订单,直接完成通关操作 serviceUrl = "/SOService/SO/BatchOperationUpdateSOStatusToCustomsPass"; client.Update(serviceUrl, new List <int> { int.Parse(backResult.merchantOrderId) }, out error); if (error != null) { bHandleResult = false; StringBuilder sb = new StringBuilder(); error.Faults.ForEach(e => sb.AppendLine(e.ErrorDescription)); if (error.Faults.All(e => e.IsBusinessException)) { return(sb.ToString()); } ECommerce.Utility.Logger.WriteLog(sb.ToString(), "SODeclareCallback", "SODeclareBgCallbackUpdateFailure"); } } } else { //失败 status = -10; object obj = new object(); serviceUrl = "/SOService/SO/UpdateSOStatusToReject"; client.Update(serviceUrl, backResult.merchantOrderId, out obj, out error); if (error != null) { bHandleResult = false; StringBuilder sb = new StringBuilder(); error.Faults.ForEach(e => sb.AppendLine(e.ErrorDescription)); if (error.Faults.All(e => e.IsBusinessException)) { return(sb.ToString()); } ECommerce.Utility.Logger.WriteLog(sb.ToString(), "SODeclareCallback", "SODeclareBgCallbackUpdateFailure"); } } if (bHandleResult) { ShoppingOrderDA.UpdateDeclareRecordsStatus(SOSysNo, status); } return(BuildPaymentCallbackReturnResult(111, bHandleResult)); } catch (Exception ex) { //系统异常,写日志 ECommerce.Utility.Logger.WriteLog(string.Format("系统异常,异常信息:{0}!", ex.ToString()), "SODeclareCallback", "SODeclareBgCallbackFailure"); return(BuildPaymentCallbackReturnResult(111, false)); } }