private XDocument MakeXml(string responseType, YandexResponceModel model) { XDocument xml = new XDocument(); XElement rootX = new XElement(responseType); XAttribute performedDatetimeX = new XAttribute("performedDatetime", DateTime.Now.ToString("O")); XAttribute codeX = new XAttribute("code", model.code); XAttribute invoiceIdX = new XAttribute("invoiceId", model.invoiceId); XAttribute shopIdX = new XAttribute("shopId", model.shopId); XAttribute orderSumAmountX = new XAttribute("orderSumAmount", model.orderSumAmount); if (!string.IsNullOrEmpty(model.message)) { XAttribute messageX = new XAttribute("message", model.message); rootX.Add(messageX); } if (!string.IsNullOrEmpty(model.techMessage)) { XAttribute techMessageX = new XAttribute("techMessage", model.techMessage); rootX.Add(techMessageX); } rootX.Add(performedDatetimeX); rootX.Add(codeX); rootX.Add(invoiceIdX); rootX.Add(shopIdX); rootX.Add(orderSumAmountX); xml.Add(rootX); return(xml); }
private YandexResponceModel _CheckRequest(YandexRequestModel model, string action) { YandexResponceModel responce = new YandexResponceModel() { code = 200, performedDatetime = DateTime.Now.ToString("O"), shopId = model.shopId, invoiceId = model.invoiceId }; try { responce.orderSumAmount = decimal.Parse(model.orderSumAmount, CultureInfo.InvariantCulture); Order order = _orderService.GetOrderById(Convert.ToInt32(model.orderNumber)); if (order == null) { responce.code = 100; responce.message = "Ордер не найден"; } else if (order.PaymentStatus == PaymentStatus.Pending) { var storeScope = this.GetActiveStoreScopeConfiguration(_storeService, _workContext); var yandexKassaPaymentSettings = _settingService.LoadSetting <YandexKassaPaymentSettings>(storeScope); if (!_VerifyMd5(action, model, order, yandexKassaPaymentSettings)) { responce.code = 1; } else { if (yandexKassaPaymentSettings.ShopId != model.shopId) { throw new Exception(); } if (Math.Abs(_currencyService.ConvertFromPrimaryStoreCurrency(order.OrderTotal, _workContext.WorkingCurrency) - responce.orderSumAmount) > 0.01M) { throw new Exception(); } responce.code = 0; } } } catch { responce.code = 200; } return(responce); }
public ActionResult CallBack(YandexRequestModel model) { YandexResponceModel responce = _CheckRequest(model, model.action); string responseType = ""; switch (this.Request.Form["action"]) { case "checkOrder": responseType = "checkOrderResponse"; break; case "paymentAviso": responseType = "paymentAvisoResponse"; if (responce.code == 0) { try { Order order = _orderService.GetOrderById(Convert.ToInt32(model.orderNumber)); if (order != null && _orderProcessingService.CanMarkOrderAsPaid(order)) { order.AuthorizationTransactionId = model.invoiceId.ToString(); _orderService.UpdateOrder(order); _orderProcessingService.MarkOrderAsPaid(order); responce.code = 0; } else { responce.code = 200; } } catch { responce.code = 200; } } break; } return(new XmlActionResult(MakeXml(responseType, responce))); }