Exemplo n.º 1
0
        public IViewComponentResult ParatikaPaymentInfo(PaymentInfoModel model)
        {
            Dictionary <String, String> requestParameters = new Dictionary <String, String>();

            requestParameters.Add("ACTION", "SESSIONTOKEN");

            var processGuid = Guid.NewGuid().ToString();

            _session.Set <string>("MERCHANTPAYMENTID_" + _workContext.CurrentCustomer.Id, processGuid);

            var cart = _workContext.CurrentCustomer.ShoppingCartItems
                       .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
                       .LimitPerStore(_storeContext.CurrentStore.Id)
                       .ToList();

            if (!cart.Any())
            {
                model.Error = _localizationService.GetResource("Plugins.Payments.Paratika.Fields.Error");
                return(View("~/Plugins/Payments.Paratika/Views/PaymentInfo.cshtml", model));
            }

            if (_paratikaOrderPaymentSettings.PaymentHPMethod)
            {
                //used main url set value only with hp method
                model.PaymentHPMethodURL = _paratikaOrderPaymentSettings.PaymentHPMethodURL;
            }

            HelperParatikaService.ParatikaParameter(requestParameters, cart, _workContext, _httpContextAccessor, _webHelper, _paratikaOrderPaymentSettings, _orderTotalCalculationService);
            var     requestData      = HelperParatikaService.convertToRequestData(requestParameters);
            var     response         = HelperParatikaService.getConnection(_paratikaOrderPaymentSettings.URL, requestData);
            JObject paratikaResponse = JObject.Parse(response);

            if (
                response != null &&
                "00".Equals(paratikaResponse.GetValue("responseCode").ToString(), StringComparison.InvariantCultureIgnoreCase) &&
                "Approved".Equals(paratikaResponse.GetValue("responseMsg").ToString(), StringComparison.InvariantCultureIgnoreCase)
                )
            {
                model.SessionToken = paratikaResponse["sessionToken"].ToString();
                _session.Set <string>("SESSIONTOKEN_" + _workContext.CurrentCustomer.Id, paratikaResponse["sessionToken"].ToString());
                return(View("~/Plugins/Payments.Paratika/Views/PaymentInfo.cshtml", model));
            }
            else
            {
                model.Error  = paratikaResponse.GetValue("errorCode").ToString() + "-" + paratikaResponse.GetValue("errorMsg").ToString();
                model.Error += _localizationService.GetResource("Plugins.Payments.Paratika.Fields.Error");
                return(View("~/Plugins/Payments.Paratika/Views/PaymentInfo.cshtml", model));
            }
        }
        public IActionResult ParatikaPaymentInfo3D(PaymentInfoModel model)
        {
            Dictionary <String, String> requestParameters = new Dictionary <String, String>();

            requestParameters.Add("NAMEONCARD", model.CardholderName);
            requestParameters.Add("CARDPAN", model.CardNumber);
            requestParameters.Add("CARDEXPIRY", model.ExpireCardMounth + "." + model.ExpireCardYear.ToString());
            requestParameters.Add("CARDCVV", model.CardCode);
            requestParameters.Add("ACTION", "SALE");
            requestParameters.Add("INSTALLMENTS", model.Installment.ToString());
            requestParameters.Add("cardOwner", model.CardholderName);
            requestParameters.Add("pan", model.CardNumber);
            requestParameters.Add("expiryMonth", model.ExpireCardMounth);
            requestParameters.Add("expiryYear", model.ExpireCardYear);
            requestParameters.Add("cvv", model.CardCode);
            requestParameters.Add("installmentCount", model.Installment.ToString());

            if (_orderSettings.CheckoutDisabled)
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            var cart = _workContext.CurrentCustomer.ShoppingCartItems
                       .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
                       .LimitPerStore(_storeContext.CurrentStore.Id)
                       .ToList();

            if (!cart.Any())
            {
                return(RedirectToRoute("ShoppingCart"));
            }

            if (_orderSettings.OnePageCheckoutEnabled)
            {
                return(RedirectToRoute("CheckoutOnePage"));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_orderSettings.AnonymousCheckoutAllowed)
            {
                return(Challenge());
            }

            //Check whether payment workflow is required
            var isPaymentWorkflowRequired = _orderProcessingService.IsPaymentWorkflowRequired(cart);

            if (!isPaymentWorkflowRequired)
            {
                return(RedirectToRoute("CheckoutConfirm"));
            }

            //load payment method
            var paymentMethodSystemName = _genericAttributeService.GetAttribute <string>(_workContext.CurrentCustomer,
                                                                                         NopCustomerDefaults.SelectedPaymentMethodAttribute, _storeContext.CurrentStore.Id);
            var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(paymentMethodSystemName);

            if (paymentMethod == null)
            {
                return(RedirectToRoute("CheckoutPaymentMethod"));
            }

            HelperParatikaService.ParatikaParameter(requestParameters, cart, _workContext, _httpContextAccessor, _webHelper, _paratikaOrderPaymentSettings, _orderTotalCalculationService);
            var getSessionToken = _session.Get <string>("SESSIONTOKEN_" + _workContext.CurrentCustomer.Id);

            requestParameters.Add("SESSIONTOKEN", getSessionToken.ToString());
            var requestData = HelperParatikaService.convertToRequestData(requestParameters);

            //var response = HelperParatikaService.getConnection(_paratikaOrderPaymentSettings.URL + "post/sale3d/" + getSessionToken.ToString(), requestData);

            //redirect url - 3D Security
            return(Json(new { url = _paratikaOrderPaymentSettings.URL + "post/sale3d/" + getSessionToken.ToString(), data = requestData }));
        }