Esempio n. 1
0
        /// <summary>
        /// Returns a value indicating whether payment method should be hidden during checkout
        /// </summary>
        /// <param name="cart">Shoping cart</param>
        /// <returns>true - hide; false - display.</returns>
        public bool HidePaymentMethod(IList <ShoppingCartItem> cart)
        {
            bool hide = false;
            var  ZarinPalPaymentSettings = _settingService.LoadSetting <ZarinpalPaymentSettings>(_storeContext.ActiveStoreScopeConfiguration);

            hide = string.IsNullOrWhiteSpace(_ZarinPalPaymentSettings.MerchantID);
            if (_ZarinPalPaymentSettings.BlockOverseas)
            {
                hide = hide || ZarinpalHelper.isOverseaseIp(_httpContextAccessor.HttpContext.Connection.RemoteIpAddress);
            }
            return(hide);
        }
Esempio n. 2
0
        /// <summary>
        /// Post process payment (used by payment gateways that require redirecting to a third-party URL)
        /// </summary>
        /// <param name="postProcessPaymentRequest">Payment info required for an order processing</param>
        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            var total = Convert.ToInt32(Math.Round(postProcessPaymentRequest.Order.OrderTotal, 2));

            if (_ZarinPalPaymentSettings.RialToToman)
            {
                total = total / 10;
            }
            string   urlToRedirect = "";
            Customer cm            = _customerService.GetCustomerById(postProcessPaymentRequest.Order.CustomerId);

            if (_ZarinPalPaymentSettings.UseSandbox)
            {
                using (ServiceReferenceZarinpalSandBox.PaymentGatewayImplementationServicePortTypeClient ZpalSr = new ServiceReferenceZarinpalSandBox.PaymentGatewayImplementationServicePortTypeClient())
                {
                    ServiceReferenceZarinpalSandBox.PaymentRequestResponse resp = ZpalSr.PaymentRequestAsync(
                        _ZarinPalPaymentSettings.MerchantID,
                        total,
                        string.Concat(_storeService.GetStoreById(postProcessPaymentRequest.Order.StoreId).Name, " - ", cm.Email),
                        cm.Email,
                        _workContext.CurrentCustomer.Addresses.FirstOrDefault().PhoneNumber ?? "",
                        string.Concat(_webHelper.GetStoreLocation(), "Plugins/PaymentZarinpal/ResultHandler", "?OGUId=" + postProcessPaymentRequest.Order.OrderGuid)
                        ).Result;
                    urlToRedirect = (resp.Body.Status == 100) ? string.Concat("https://sandbox.zarinpal.com/pg/StartPay/", resp.Body.Authority) : string.Concat(_webHelper.GetStoreLocation(), "Plugins/PaymentZarinpal/ErrorHandler", "?Error=", resp.Body.Status);
                    _httpContextAccessor.HttpContext.Response.Redirect(urlToRedirect);
                }
            }
            else
            {
                using (ServiceReferenceZarinpal.PaymentGatewayImplementationServicePortTypeClient ZpalSr = new ServiceReferenceZarinpal.PaymentGatewayImplementationServicePortTypeClient())
                {
                    ServiceReferenceZarinpal.PaymentRequestResponse resp = ZpalSr.PaymentRequestAsync(
                        _ZarinPalPaymentSettings.MerchantID,
                        total,
                        string.Concat(_storeService.GetStoreById(postProcessPaymentRequest.Order.StoreId).Name, " - ", cm.Email),
                        cm.Email,
                        _workContext.CurrentCustomer.Addresses.FirstOrDefault().PhoneNumber ?? "",
                        string.Concat(_webHelper.GetStoreLocation(), "Plugins/PaymentZarinpal/ResultHandler", "?OGUId=" + postProcessPaymentRequest.Order.OrderGuid)
                        ).Result;
                    urlToRedirect = (resp.Body.Status == 100) ? string.Concat("https://zarinpal.com/pg/StartPay/", resp.Body.Authority) : string.Concat(_webHelper.GetStoreLocation(), "Plugins/PaymentZarinpal/ErrorHandler", "?Error=", "Error : ", ZarinpalHelper.StatusToMessage(resp.Body.Status));
                    _httpContextAccessor.HttpContext.Response.Redirect(urlToRedirect);
                }
            }
        }