public ActionResult ProceedTDC(PaymentViewModel model) { //Setear variables del conector PaymentApplication paymentApp = _paymentService.GetPaymentApplicationByKey(model.AppKey); paymentProviderService.MerchantId = paymentApp.MerchantId; paymentProviderService.PublicKey = paymentApp.PublicKey; paymentProviderService.PrivateKey = paymentApp.PrivateKey; //Crear modelo PaymentModel payment = new PaymentModel() { ClientId = paymentApp.ClientId, OrderId = model.OrderId, Amount = model.Amount, Description = model.Description, TokenId = model.TokenId, DeviceSessionId = model.DeviceSessionId, RedirectUrl = SecureVerificationURL, //Use3DSecure = true }; //Primero en BD Payment paymentBO = new Payment(); paymentBO.CreationDate = DateUtil.GetDateTimeNow(); paymentBO.User = paymentApp.User; paymentBO.Amount = model.Amount; paymentBO.OrderId = model.OrderId; paymentBO.ConfirmationEmail = model.ConfirmationEmail; paymentBO.Status = PaymentStatus.IN_PROGRESS; paymentBO.Method = PaymentMethod.CARD; paymentBO.TransactionType = PaymentType.CHARGE; paymentBO.ConfirmationDate = null; _paymentService.Create(paymentBO); //Luego cobrar model.PaymentMethod = PaymentMethod.CARD; payment = paymentProviderService.CreateTDCPayment(payment); //Si hubiera reintento, probar Antifraude if (UseSelective3DSecure && !payment.ChargeSuccess & payment.ResultCode == PaymentError.ANTI_FRAUD) { payment.Use3DSecure = true; payment = paymentProviderService.CreateTDCPayment(payment); } model.ChargeSuccess = payment.ChargeSuccess; if (payment.ChargeSuccess) { //Luego actualizar paymentBO.ProviderId = payment.Id; paymentBO.Status = payment.Status; paymentBO.DueDate = payment.DueDate; paymentBO.LogData = payment.ResultData; _paymentService.Update(paymentBO); model.Id = payment.Id; model.Description = payment.Description; model.JsonData = payment.ResultData; model.DueDate = payment.DueDate; model.PaymentCardURL = payment.PaymentCardURL; } else { paymentBO.Status = PaymentStatus.ERROR; paymentBO.LogData = payment.ResultData; _paymentService.Update(paymentBO); model.Description = payment.ResultData; } // Session.Add("Payments.PaymentModel", model); //if (payment.PaymentMethod != null && !string.IsNullOrEmpty(payment.PaymentMethod.RedirectUrl)) //{ // return Redirect(payment.PaymentMethod.RedirectUrl); //} if (paymentApp.ReturnURL != null && !string.IsNullOrEmpty(paymentApp.ReturnURL)) { FormCollection formCollection = new FormCollection { { "payment_id", paymentBO.ProviderId }, { "status", paymentBO.Status } }; //SendPostRequest(paymentApp.ReturnURL, formCollection); return(Content("<form action='" + paymentApp.ReturnURL + "' id='frmReturnURL' method='POST'>" + "<input type='hidden' name='Id' value='" + paymentBO.Id + "' />" + "<input type='hidden' name='ProviderId' value='" + paymentBO.ProviderId + "' />" + "<input type='hidden' name='CreationDate' value='" + paymentBO.CreationDate + "' />" + "<input type='hidden' name='Status' value='" + paymentBO.Status + "' />" + "<input type='hidden' name='Amount' value='" + paymentBO.Amount + "' />" + "<input type='hidden' name='OrderId' value='" + paymentBO.OrderId + "' />" + "<input type='hidden' name='Method' value='" + paymentBO.Method + "' />" + "<input type='hidden' name='TransactionType' value='" + paymentBO.TransactionType + "' />" + "</form>" + "<script>document.getElementById('frmReturnURL').submit();</script>")); } return(View("Test")); }
public ActionResult CreateTDC(PaymentViewModel model) { //Setear variables del conector PaymentApplication paymentApp = _paymentService.GetPaymentApplicationByKey(AppKey); paymentProviderService.MerchantId = paymentApp.MerchantId; paymentProviderService.PublicKey = paymentApp.PublicKey; paymentProviderService.PrivateKey = paymentApp.PrivateKey; paymentProviderService.DashboardURL = paymentApp.DashboardURL; PaymentModel payment = new PaymentModel() { ClientId = paymentApp.ClientId, OrderId = model.OrderId, Amount = model.Amount, TokenId = model.TokenId, DeviceSessionId = model.DeviceSessionId, Description = String.Format("Pago de orden {0}", model.OrderId), RedirectUrl = SecureVerificationURL, //Use3DSecure = true }; //Primero en BD Payment paymentBO = new Payment(); paymentBO.CreationDate = DateUtil.GetDateTimeNow(); paymentBO.User = new User() { Id = Authenticator.AuthenticatedUser.Id }; paymentBO.Amount = model.Amount; paymentBO.OrderId = model.OrderId; paymentBO.ConfirmationEmail = model.ConfirmationEmail; paymentBO.Status = PaymentStatus.IN_PROGRESS; paymentBO.Method = PaymentMethod.CARD; paymentBO.TransactionType = PaymentType.CHARGE; paymentBO.ConfirmationDate = null; _paymentService.Create(paymentBO); //Luego cobrar model.PaymentMethod = PaymentMethod.CARD; payment = paymentProviderService.CreateTDCPayment(payment); //Si hubiera reintento, probar Antifraude if (UseSelective3DSecure && !payment.ChargeSuccess & payment.ResultCode == PaymentError.ANTI_FRAUD) { payment.Use3DSecure = true; payment = paymentProviderService.CreateTDCPayment(payment); } model.ChargeSuccess = payment.ChargeSuccess; if (payment.ChargeSuccess) { //Luego actualizar paymentBO.ProviderId = payment.Id; paymentBO.Status = payment.Status; paymentBO.DueDate = payment.DueDate; paymentBO.LogData = payment.ResultData; _paymentService.Update(paymentBO); model.Id = payment.Id; model.Description = payment.Description; model.JsonData = payment.ResultData; model.DueDate = payment.DueDate; model.PaymentCardURL = payment.PaymentCardURL; } else { paymentBO.Status = PaymentStatus.ERROR; paymentBO.LogData = payment.ResultData; _paymentService.Update(paymentBO); model.Description = payment.ResultData; } // Session.Add("Payments.PaymentModel", model); if (payment.PaymentMethod != null && !string.IsNullOrEmpty(payment.PaymentMethod.RedirectUrl)) { return(Redirect(payment.PaymentMethod.RedirectUrl)); } //return View("CreateTDC", model); return(View("CheckoutSuccess", model)); }