예제 #1
0
 public ParatikaViewComponent(IWorkContext workContext,
                              IHttpContextAccessor httpContextAccessor,
                              IStoreContext storeContext,
                              ILocalizationService localizationService,
                              ParatikaOrderPaymentSettings ParatikaOrderPaymentSettings,
                              IWebHelper webHelper,
                              IOrderTotalCalculationService orderTotalCalculationService
                              )
 {
     this._httpContextAccessor          = httpContextAccessor;
     this._workContext                  = workContext;
     this._storeContext                 = storeContext;
     this._webHelper                    = webHelper;
     this._localizationService          = localizationService;
     this._paratikaOrderPaymentSettings = ParatikaOrderPaymentSettings;
     this._orderTotalCalculationService = orderTotalCalculationService;
 }
 public ParatikaController(IWorkContext workContext,
                           IHttpContextAccessor httpContextAccessor,
                           IStoreService storeService,
                           ISettingService settingService,
                           IStoreContext storeContext,
                           ILocalizationService localizationService,
                           ILanguageService languageService,
                           IOrderProcessingService orderProcessingService,
                           IGenericAttributeService genericAttributeService,
                           ParatikaOrderPaymentSettings ParatikaOrderPaymentSettings,
                           ICurrencyService currencyService,
                           IPermissionService permissionService,
                           ICustomerService customerService,
                           CurrencySettings currencySettings,
                           IOrderService orderService,
                           IWebHelper webHelper,
                           IOrderTotalCalculationService orderTotalCalculationService,
                           ILogger logger,
                           IPaymentService paymentService,
                           OrderSettings orderSettings,
                           IPriceFormatter priceFormatter)
 {
     this._httpContextAccessor          = httpContextAccessor;
     this._orderService                 = orderService;
     this._workContext                  = workContext;
     this._storeService                 = storeService;
     this._settingService               = settingService;
     this._storeContext                 = storeContext;
     this._localizationService          = localizationService;
     this._languageService              = languageService;
     this._permissionService            = permissionService;
     this._webHelper                    = webHelper;
     this._orderProcessingService       = orderProcessingService;
     this._genericAttributeService      = genericAttributeService;
     this._paratikaOrderPaymentSettings = ParatikaOrderPaymentSettings;
     this._currencyService              = currencyService;
     this._customerService              = customerService;
     this._currencySettings             = currencySettings;
     this._orderTotalCalculationService = orderTotalCalculationService;
     this._logger         = logger;
     this._paymentService = paymentService;
     this._orderSettings  = orderSettings;
     this._priceFormatter = priceFormatter;
 }
        public static void ParatikaParameter(Dictionary <string, string> requestParameters, List <ShoppingCartItem> cart, IWorkContext _workContext, IHttpContextAccessor _httpContextAccessor, IWebHelper _webHelper, ParatikaOrderPaymentSettings _paratikaOrderPaymentSettings, IOrderTotalCalculationService _orderTotalCalculationService)
        {
            var storeLocation  = _webHelper.GetStoreLocation();
            var getPaymentGuid = _httpContextAccessor.HttpContext.Session.Get <string>("MERCHANTPAYMENTID_" + _workContext.CurrentCustomer.Id);

            requestParameters.Add("MERCHANT", _paratikaOrderPaymentSettings.Code);
            requestParameters.Add("MERCHANTUSER", _paratikaOrderPaymentSettings.Username);
            requestParameters.Add("MERCHANTPASSWORD", _paratikaOrderPaymentSettings.Password);

            requestParameters.Add("MERCHANTPAYMENTID", getPaymentGuid);
            var orderTotal = _orderTotalCalculationService.GetShoppingCartTotal(cart, out var orderDiscountAmount, out var orderAppliedDiscounts, out var appliedGiftCards, out var redeemedRewardPoints, out var redeemedRewardPointsAmount);

            requestParameters.Add("AMOUNT", orderTotal.ToString());
            requestParameters.Add("CURRENCY", "TRY");
            requestParameters.Add("SESSIONTYPE", "PAYMENTSESSION");
            requestParameters.Add("RETURNURL", $"{storeLocation}Paratika/PaymentInfoCallBack");

            JArray oItems = new JArray();

            foreach (var card in cart)
            {
                JObject item = new JObject();
                item.Add("code", card.Product.Sku);
                item.Add("name", card.Product.Name);
                item.Add("quantity", card.Quantity);
                item.Add("description", card.Product.Name);
                item.Add("amount", card.Product.Price);
                oItems.Add(item);
            }

            decimal productSum = 0;

            foreach (var item in oItems)
            {
                productSum += Convert.ToDecimal(item["amount"]) * Convert.ToInt32(item["quantity"]);
            }
            if (orderTotal != productSum)
            {
                if (orderTotal > productSum)
                {
                    var     diffrerent = orderTotal - productSum;
                    JObject item       = new JObject();
                    item.Add("code", "different");
                    item.Add("name", "different");
                    item.Add("quantity", "1");
                    item.Add("description", "different");
                    item.Add("amount", diffrerent.ToString());
                    oItems.Add(item);
                }
                else
                {
                    var     diffrerent = productSum - orderTotal;
                    JObject item       = new JObject();
                    item.Add("code", "discount");
                    item.Add("name", "discount");
                    item.Add("quantity", "1");
                    item.Add("description", "discount");
                    item.Add("amount", diffrerent.ToString());
                    oItems.Add(item);
                }
            }
            requestParameters.Add("ORDERITEMS", encodeParameter(oItems.ToString()));

            JObject extra = new JObject();

            extra.Add("IntegrationModel", "API");
            //extra.Add("AlwaysSaveCard", "true");
            requestParameters.Add("EXTRA", encodeParameter(extra.ToString()));

            requestParameters.Add("CUSTOMER", _workContext.CurrentCustomer.CustomerGuid.ToString());
            requestParameters.Add("CUSTOMERNAME", _workContext.CurrentCustomer.ShippingAddress.FirstName + " " + _workContext.CurrentCustomer.ShippingAddress.LastName);
            requestParameters.Add("CUSTOMEREMAIL", _workContext.CurrentCustomer.Email);
            requestParameters.Add("CUSTOMERIP", _workContext.CurrentCustomer.LastIpAddress);
            requestParameters.Add("CUSTOMERPHONE", _workContext.CurrentCustomer.ShippingAddress.PhoneNumber);
            //requestParameters.Add("CUSTOMERBIRTHDAY", _workContext.CurrentCustomer.ShippingAddress.);
            requestParameters.Add("CUSTOMERUSERAGENT", _httpContextAccessor.HttpContext.Request.Headers["User-Agent"].ToString());

            requestParameters.Add("BILLTOADDRESSLINE", _workContext.CurrentCustomer.BillingAddress.Address1);
            requestParameters.Add("BILLTOCITY", _workContext.CurrentCustomer.BillingAddress.City);
            requestParameters.Add("BILLTOCOUNTRY", _workContext.CurrentCustomer.BillingAddress.Country.Name);
            requestParameters.Add("BILLTOPOSTALCODE", _workContext.CurrentCustomer.BillingAddress.ZipPostalCode);
            requestParameters.Add("BILLTOPHONE", _workContext.CurrentCustomer.BillingAddress.PhoneNumber);
            requestParameters.Add("SHIPTOADDRESSLINE", _workContext.CurrentCustomer.ShippingAddress.Address1);
            requestParameters.Add("SHIPTOCITY", _workContext.CurrentCustomer.ShippingAddress.City);
            requestParameters.Add("SHIPTOCOUNTRY", _workContext.CurrentCustomer.ShippingAddress.Country.Name);
            requestParameters.Add("SHIPTOPOSTALCODE", _workContext.CurrentCustomer.ShippingAddress.ZipPostalCode);
            requestParameters.Add("SHIPTOPHONE", _workContext.CurrentCustomer.ShippingAddress.PhoneNumber);
        }