public string ServerUrl(string signature, string data) { try { if (signature == null || data == null) { throw new Exception("ERROR_EMPTY_DATA"); } byte[] dataVal = Convert.FromBase64String(data); string decodedString = Encoding.UTF8.GetString(dataVal); PaymentLiqpayResponse model = JsonConvert.DeserializeObject <PaymentLiqpayResponse>(decodedString); LiqPaySignatureGenerator liqpaySignature = new LiqPaySignatureGenerator(); if (!String.Equals(signature, liqpaySignature.GenerateSignature(data, _liqPayPaymentSettings.PrivateKey))) { throw new Exception("SENDER_ERROR"); } var order = _orderService.GetOrderById(int.Parse(model.order_id)); if (order == null) { throw new Exception("ORDER_NOT_FOUND"); } if (model.status == "success" || model.status == "sandbox") { order.PaymentStatus = PaymentStatus.Paid; } if (model.status == "failure") { order.PaymentStatus = PaymentStatus.Voided; } if (model.status == "processing") { order.PaymentStatus = PaymentStatus.Pending; } _orderService.UpdateOrder(order); return("OK"); } catch (Exception ex) { _logger.InsertLog(Core.Domain.Logging.LogLevel.Error, ex.Message, JsonConvert.SerializeObject(ex)); throw ex; } }
public IActionResult CreatePayment(int orderId) { PaymentLiqpayVM model = new PaymentLiqpayVM(); LiqPaySignatureGenerator liqpaysignature = new LiqPaySignatureGenerator(); var order = _orderService.GetOrderById(orderId); if (order == null) { return(Redirect(_baseUrl)); } if (order.PaymentStatus == PaymentStatus.Paid) { return(Redirect(string.Format("{0}ru/checkout/completed/{1}", _baseUrl, order.Id))); } model.pay_way = "card,liqpay,privat24"; model.amount = order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture); model.currency = "UAH"; model.action = "pay"; model.private_key = _liqPayPaymentSettings.PrivateKey; model.public_key = _liqPayPaymentSettings.PublicKey; model.recurringbytoken = "0"; model.result_url = string.Format("{0}ru/checkout/completed/{1}", _baseUrl, order.Id);; model.server_url = string.Format("{0}liqpay/callback", _baseUrl); model.version = "3"; if (_liqPayPaymentSettings.UseSandbox) { model.sandbox = "1"; } else { model.sandbox = "0"; } model.description = String.Format("Заказ #{0}. Имя: {1}, тел. {2}, email: {3}", order.Id, order.Customer.BillingAddress.FirstName, order.Customer.BillingAddress.PhoneNumber, order.Customer.Email); model.order_id = order.Id.ToString(); liqpaysignature.GenerateSignature(model); return(View("~/Plugins/Payments.LiqPay/Views/CreatePayment.cshtml", model)); }