//ToDo method public ActionResult CancelOrder(IpnModel model) { var form = model.Form; const string orderIdKey = "order_id"; var orderId = GetValue(orderIdKey, form); Order order = null; if (Guid.TryParse(orderId, out Guid orderGuid)) { order = _orderService.GetOrderByGuid(orderGuid); } if (order == null) { return(RedirectToAction("Index", "Home", new { area = string.Empty })); } //update payment status if need if (order.PaymentStatus != PaymentStatus.Voided) { var status = GetPaymentProcessor().GetPaymentStatus(orderId); if (status[0].ToLower() == "ok") { UpdateOrderStatus(order, status[1]); } } return(RedirectToRoute("OrderDetails", new { orderId = order.Id })); }
public IActionResult IPNHandler(IpnModel model) { var form = model.Form; var processor = GetPaymentProcessor(); if (processor.VerifyIpn(form, out TransactionStatus txnStatus)) { var val = GetValue(Constants.OK_INVOICE_KEY, form); if (!string.IsNullOrEmpty(val) && int.TryParse(val, out int orderId)) { var order = _orderService.GetOrderById(orderId); if (_orderProcessingService.CanMarkOrderAsPaid(order) && txnStatus == TransactionStatus.Completed) { _orderProcessingService.MarkOrderAsPaid(order); } else if ((order.PaymentStatus == PaymentStatus.Paid || order.PaymentStatus == PaymentStatus.Authorized) && _orderProcessingService.CanCancelOrder(order) && txnStatus != TransactionStatus.Completed) { _orderProcessingService.CancelOrder(order, true); } var sb = new StringBuilder(); sb.AppendLine("OkPay IPN:"); sb.Append(PreparationOrderNote(form)); sb.AppendLine("New transaction status: " + txnStatus); order.OrderNotes.Add(new OrderNote { Note = sb.ToString(), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); } else { var sb = new StringBuilder(); sb.AppendLine("OkPay error: failed order identifier"); sb.AppendLine("Transaction status: " + txnStatus); sb.Append(PreparationOrderNote(form)); _logger.Error("OkPay IPN failed.", new NopException(sb.ToString())); } } else { var sb = new StringBuilder(); sb.AppendLine("Transaction status: " + txnStatus); sb.Append(PreparationOrderNote(form)); _logger.Error("OkPay IPN failed.", new NopException(sb.ToString())); } return(Content("")); }
public IActionResult SuccessCallbackHandler(IpnModel model) { var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Moneris") as MonerisPaymentProcessor; if (processor == null || !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed) { throw new NopException("Moneris module cannot be loaded"); } var parameters = model.Form; if (string.IsNullOrEmpty(GetValue("transactionKey", parameters)) || string.IsNullOrEmpty(GetValue("rvar_order_id", parameters))) { return(RedirectToAction("Index", "Home", new { area = "" })); } var transactionKey = GetValue("transactionKey", parameters); if (!processor.TransactionVerification(transactionKey, out Dictionary <string, string> values)) { return(RedirectToAction("Index", "Home", new { area = "" })); } var orderIdValue = GetValue("rvar_order_id", parameters); if (!int.TryParse(orderIdValue, out int orderId)) { return(RedirectToAction("Index", "Home", new { area = "" })); } var order = _orderService.GetOrderById(orderId); if (order == null || !_orderProcessingService.CanMarkOrderAsPaid(order)) { return(RedirectToAction("Index", "Home", new { area = "" })); } if (values.ContainsKey("txn_num")) { order.AuthorizationTransactionId = values["txn_num"]; _orderService.UpdateOrder(order); } _orderProcessingService.MarkOrderAsPaid(order); return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id })); }
public IActionResult PayFastResultHandler(IpnModel model) { var form = model.Form; //validation if (!ValidateITN(form, out Order order)) { return(new StatusCodeResult((int)HttpStatusCode.OK)); } //paid order if (_orderProcessingService.CanMarkOrderAsPaid(order)) { order.AuthorizationTransactionId = form["pf_payment_id"]; _orderService.UpdateOrder(order); _orderProcessingService.MarkOrderAsPaid(order); } return(new StatusCodeResult((int)HttpStatusCode.OK)); }
public IActionResult IPNHandler(IpnModel model, IFormCollection form) { if (!(_paymentPluginManager.LoadPluginBySystemName("Payments.AuthorizeNet") is AuthorizeNetPaymentProcessor processor) || !_paymentPluginManager.IsPluginActive(processor) || !processor.PluginDescriptor.Installed) { throw new NopException("AuthorizeNet module cannot be loaded"); } var responseCode = form.Keys.Contains("x_response_code") ? form["x_response_code"].ToString() : string.Empty; if (responseCode == "1") { var transactionId = form.Keys.Contains("x_trans_id") ? form["x_trans_id"].ToString() : string.Empty; processor.ProcessRecurringPayment(transactionId); } //nothing should be rendered to visitor return(Content(string.Empty)); }
public IActionResult Fail(IpnModel model) { var form = model.Form; var storeScope = _storeContext.ActiveStoreScopeConfiguration; var okPayPaymentSettings = _settingService.LoadSetting <OkPayPaymentSettings>(storeScope); if (!okPayPaymentSettings.ReturnFromOkPayWithoutPaymentRedirectsToOrderDetailsPage) { return(RedirectToRoute("HomePage")); } var val = GetValue(Constants.OK_INVOICE_KEY, form); if (string.IsNullOrEmpty(val) || !int.TryParse(val, out int orderId)) { return(RedirectToRoute("HomePage")); } var order = _orderService.GetOrderById(orderId); return(order != null?RedirectToRoute("OrderDetails", new { orderId = order.Id }) : RedirectToRoute("HomePage")); }
public IActionResult IPNHandler(IpnModel model) { var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.AuthorizeNet") as AuthorizeNetPaymentProcessor; if (processor == null || !_paymentService.IsPaymentMethodActive(processor) || !processor.PluginDescriptor.Installed) { throw new NopException("AuthorizeNet module cannot be loaded"); } var form = model.Form; var responseCode = form.Keys.Contains("x_response_code") ? form["x_response_code"].ToString() : string.Empty; if (responseCode == "1") { var transactionId = form.Keys.Contains("x_trans_id") ? form["x_trans_id"].ToString() : string.Empty; processor.ProcessRecurringPayment(transactionId); } //nothing should be rendered to visitor return(Content(string.Empty)); }
public ActionResult Return(IpnModel model) { var processor = _paymentPluginManager.LoadPluginBySystemName("Payments.CCAvenue") as CCAvenuePaymentProcessor; if (processor == null || !_paymentPluginManager.IsPluginActive(processor) || !processor.PluginDescriptor.Installed) { throw new NopException("CCAvenue module cannot be loaded"); } //assign following values to send it to verifychecksum function. if (string.IsNullOrWhiteSpace(_ccAvenuePaymentSettings.Key)) { throw new NopException("CCAvenue key is not set"); } var workingKey = _ccAvenuePaymentSettings.Key; var ccaCrypto = new CCACrypto(); var encResponse = ccaCrypto.Decrypt(model.Form["encResp"], workingKey); var paramList = new NameValueCollection(); var segments = encResponse.Split('&'); foreach (var seg in segments) { var parts = seg.Split('='); if (parts.Length <= 0) { continue; } paramList.Add(parts[0].Trim(), parts[1].Trim()); } var sb = new StringBuilder(); sb.AppendLine("CCAvenue:"); for (var i = 0; i < paramList.Count; i++) { sb.AppendLine(paramList.Keys[i] + " = " + paramList[i]); } var orderId = paramList["Order_Id"]; var authDesc = paramList["order_status"]; var order = _orderService.GetOrderById(Convert.ToInt32(orderId)); if (order == null) { return(RedirectToAction("Index", "Home", new { area = string.Empty })); } order.OrderNotes.Add(new OrderNote { Note = sb.ToString(), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); //var merchantId = Params["Merchant_Id"]; //var Amount = Params["Amount"]; //var myUtility = new CCAvenueHelper(); //var checksum = myUtility.verifychecksum(merchantId, orderId, Amount, AuthDesc, _ccAvenuePaymentSettings.Key, checksum); if (!authDesc.Equals("Success", StringComparison.InvariantCultureIgnoreCase)) { return(RedirectToRoute("OrderDetails", new { orderId = order.Id })); } //here you need to put in the routines for a successful transaction such as sending an email to customer, //setting database status, informing logistics etc etc if (_orderProcessingService.CanMarkOrderAsPaid(order)) { _orderProcessingService.MarkOrderAsPaid(order); } //thank you for shopping with us. Your credit card has been charged and your transaction is successful return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id })); }
/* * * [NonAction] * public override IList<string> ValidatePaymentForm(FormCollection form) * { * var warnings = new List<string>(); * return warnings; * } * * [NonAction] * public override ProcessPaymentRequest GetPaymentInfo(FormCollection form) * { * var paymentInfo = new ProcessPaymentRequest(); * return paymentInfo; * } */ //[ValidateInput(false)] public IActionResult Return(IpnModel model) { /* * var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.Payu") as PayuPaymentProcessor; * if (processor == null || * !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed) * throw new NopException("Payu module cannot be loaded"); * */ var myUtility = new PayuHelper(); string orderId, merchantId, Amount, productinfo, firstname, email, hash, status, checksum; //Assign following values to send it to verifychecksum function. if (String.IsNullOrWhiteSpace(_payuPaymentSettings.Key)) { throw new NopException("Payu key is not set"); } merchantId = _payuPaymentSettings.MerchantId.ToString(); orderId = model.Form["txnid"]; Amount = model.Form["amount"]; productinfo = model.Form["productinfo"]; firstname = model.Form["firstname"]; email = model.Form["email"]; hash = model.Form["hash"]; status = model.Form["status"]; checksum = myUtility.verifychecksum(merchantId, orderId, Amount, productinfo, firstname, email, status, _payuPaymentSettings.Key); if (checksum == hash) { if (status == "success") { /* * Here you need to put in the routines for a successful * transaction such as sending an email to customer, * setting database status, informing logistics etc etc */ var order = _orderService.GetOrderById(Convert.ToInt32(orderId)); if (_orderProcessingService.CanMarkOrderAsPaid(order)) { _orderProcessingService.MarkOrderAsPaid(order); var sb = new StringBuilder(); sb.AppendLine("PayU IPN:"); foreach (var v in model.Form) { sb.AppendLine(v.Key + ": " + v.Value); } //order note order.OrderNotes.Add(new OrderNote { Note = sb.ToString(), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); } //Thank you for shopping with us. Your credit card has been charged and your transaction is successful return(RedirectToRoute("CheckoutCompleted", new { orderId = order.Id })); } else { /* * Here you need to put in the routines for a failed * transaction such as sending an email to customer * setting database status etc etc */ return(RedirectToAction("Index", "Home", new { area = "" })); } } else { /* * Here you need to simply ignore this and dont need * to perform any operation in this condition */ return(Content("Security Error. Illegal access detected")); } }
public ActionResult Notify(IpnModel model) { var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.AliPay") as AliPayPaymentProcessor; if (processor == null || !_paymentService.IsPaymentMethodActive(processor) || !processor.PluginDescriptor.Installed) { throw new NopException("AliPay module cannot be loaded"); } var partner = _aliPayPaymentSettings.Partner; if (string.IsNullOrEmpty(partner)) { throw new Exception("Partner is not set"); } var key = _aliPayPaymentSettings.Key; if (string.IsNullOrEmpty(key)) { throw new Exception("Partner is not set"); } var alipayNotifyUrl = $"https://www.alipay.com/cooperate/gateway.do?service=notify_verify&partner={partner}¬ify_id={model.Form["notify_id"]}"; var responseTxt = string.Empty; try { var myReq = (HttpWebRequest)WebRequest.Create(alipayNotifyUrl); myReq.Timeout = 120000; var httpWResp = (HttpWebResponse)myReq.GetResponse(); var myStream = httpWResp.GetResponseStream(); if (myStream != null) { using (var sr = new StreamReader(myStream, Encoding.Default)) { var strBuilder = new StringBuilder(); while (-1 != sr.Peek()) { strBuilder.Append(sr.ReadLine()); } responseTxt = strBuilder.ToString(); } } } catch (Exception exc) { responseTxt = $"Error: {exc.Message}"; } int i; var coll = model.Form; var sortedStr = coll.Keys.ToArray(); Array.Sort(sortedStr, StringComparer.InvariantCulture); var prestr = new StringBuilder(); for (i = 0; i < sortedStr.Length; i++) { if (coll[sortedStr[i]] == "" || sortedStr[i] == "sign" || sortedStr[i] == "sign_type") { continue; } prestr.AppendFormat("{0}={1}", sortedStr[i], coll[sortedStr[i]]); if (i < sortedStr.Length - 1) { prestr.Append("&"); } } prestr.Append(key); var mySign = processor.GetMD5(prestr.ToString()); var sign = coll["sign"]; byte[] data = null; if (mySign == sign && responseTxt == "true") { if (coll["trade_status"] == "TRADE_FINISHED" || coll["trade_status"] == "TRADE_SUCCESS") { var strOrderNo = model.Form["out_trade_no"]; int orderId; if (int.TryParse(strOrderNo, out orderId)) { var order = _orderService.GetOrderById(orderId); if (order != null && _orderProcessingService.CanMarkOrderAsPaid(order)) { _orderProcessingService.MarkOrderAsPaid(order); } } } data = Encoding.UTF8.GetBytes("success"); } else { data = Encoding.UTF8.GetBytes("fail"); var logStr = $"MD5:mysign={mySign},sign={sign},responseTxt={responseTxt}"; _logger.Error(logStr); } Response.Body.Write(data, 0, data.Length); return(Content("")); }
public ActionResult ConfirmPay(IpnModel model) { var form = model.Form; var processor = GetPaymentProcessor(); const string orderIdKey = "order_id"; const string signatureKey = "signature"; const string orderStatus = "order_status"; var orderId = GetValue(orderIdKey, form); var signature = GetValue(signatureKey, form); var result = GetValue(orderStatus, form); Order order = null; if (Guid.TryParse(orderId, out Guid orderGuid)) { order = _orderService.GetOrderByGuid(orderGuid); } if (order == null) { return(GetResponse("Order cannot be loaded", processor)); } var sb = new StringBuilder(); sb.AppendLine("Fondy:"); foreach (var key in form.Keys) { sb.AppendLine(key + ": " + form[key]); } //order note order.OrderNotes.Add(new OrderNote { Note = sb.ToString(), DisplayToCustomer = false, CreatedOnUtc = DateTime.UtcNow }); _orderService.UpdateOrder(order); var postData = new NameValueCollection(); foreach (var keyValuePair in form.Where(pair => !pair.Key.Equals(signatureKey, StringComparison.InvariantCultureIgnoreCase))) { if (keyValuePair.Value == "") { continue; } postData.Add(keyValuePair.Key, keyValuePair.Value); } var checkDataString = processor.GetSignature(postData); if (checkDataString != signature) { return(GetResponse("Invalid order data", processor)); } if (result == "declined" || result == "expired") { return(GetResponse("The payment has been canceled", processor, true)); } //mark order as paid if (_orderProcessingService.CanMarkOrderAsPaid(order) && result == "approved") { _orderProcessingService.MarkOrderAsPaid(order); } return(GetResponse("The order has been paid", processor, true)); }