/// <summary>
        /// Ödeme Talebi İadesi
        /// </summary>
        /// <param name="refundPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
        {
            var refundResult = new RefundPaymentResult();

            if (!refundPaymentRequest.IsPartialRefund)
            {
                CreateCancelRequest request = new CreateCancelRequest();
                request.ConversationId = refundPaymentRequest.Order.CustomOrderNumber;
                request.Locale         = Locale.TR.ToString();
                request.PaymentId      = refundPaymentRequest.Order.AuthorizationTransactionId;
                request.Ip             = refundPaymentRequest.Order.CustomerIp;
                Cancel cancel = Cancel.Create(request, HelperApiOptions.GetApiContext(_iyzicoPayPaymentSettings));
                if (cancel.Status == "success")
                {
                    refundResult.NewPaymentStatus = PaymentStatus.Refunded;
                }
                else
                {
                    refundResult.AddError(cancel.ErrorGroup);
                }
            }
            else
            {
                string[]            list    = refundPaymentRequest.Order.AuthorizationTransactionResult.Split('-');
                CreateRefundRequest request = new CreateRefundRequest();
                request.ConversationId       = refundPaymentRequest.Order.CustomOrderNumber;
                request.Locale               = Locale.TR.ToString();
                request.PaymentTransactionId = list[0];
                request.Price    = refundPaymentRequest.AmountToRefund.ToString("##.###").Replace(',', '.');
                request.Ip       = refundPaymentRequest.Order.CustomerIp;
                request.Currency = Currency.TRY.ToString();
                Iyzico.Models.Refund refund = Iyzico.Models.Refund.Create(request, HelperApiOptions.GetApiContext(_iyzicoPayPaymentSettings));
                if (refund.Status == "success")
                {
                    refundResult.NewPaymentStatus = PaymentStatus.PartiallyRefunded;
                }
            }

            return(refundResult);
        }
        private ProcessPaymentResult ProcessPayment(ProcessPaymentRequest paymentRequest, bool isRecurringPayment)
        {
            var result         = new ProcessPaymentResult();
            var iyzicoSettings = _settingService.LoadSetting <IyzicoPayPaymentSettings>();
            var customer       = _customerService.GetCustomerById(_workContext.CurrentCustomer.Id);

            var cart = _workContext.CurrentCustomer.ShoppingCartItems
                       .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
                       .LimitPerStore(_storeContext.CurrentStore.Id)
                       .ToList();
            var subTotalIncludingTax = _workContext.TaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal;

            _orderTotalCalculationService.GetShoppingCartSubTotal(cart, subTotalIncludingTax, out decimal orderSubTotalDiscountAmountBase, out List <DiscountForCaching> _, out decimal subTotalWithoutDiscountBase, out decimal _);

            var subtotalBase = subTotalWithoutDiscountBase;
            var subtotal     = _currencyService.ConvertFromPrimaryStoreCurrency(subtotalBase, _workContext.WorkingCurrency);

            CreatePaymentRequest request = new CreatePaymentRequest
            {
                Locale         = Locale.TR.ToString(),
                ConversationId = customer.CustomerGuid.ToString(),
                Price          = subtotal.ToString("##.###").Replace(',', '.')
            };
            var paidprice  = paymentRequest.CustomValues["Installments"].ToString();
            var instalment = paymentRequest.CustomValues["InstalmentCount"].ToString();
            var forceDs    = false;

            if (!string.IsNullOrEmpty(paymentRequest.CustomValues["force3ds"].ToString()))
            {
                forceDs = paymentRequest.CustomValues["force3ds"].ToString() == "1" ? true : false;
            }

            request.PaidPrice = paidprice;
            request.Currency  = _workContext.WorkingCurrency.CurrencyCode.ToString();
            if (!string.IsNullOrEmpty(instalment))
            {
                request.Installment = Convert.ToInt32(instalment);
            }

            request.BasketId       = customer.Id.ToString();
            request.PaymentChannel = PaymentChannel.WEB.ToString();
            request.PaymentGroup   = PaymentGroup.PRODUCT.ToString();

            PaymentCard paymentCard = new PaymentCard
            {
                CardHolderName = paymentRequest.CreditCardName,
                CardNumber     = paymentRequest.CreditCardNumber,
                ExpireMonth    = paymentRequest.CreditCardExpireMonth.ToString(),
                ExpireYear     = paymentRequest.CreditCardExpireYear.ToString(),
                Cvc            = paymentRequest.CreditCardCvv2,
                RegisterCard   = 0
            };

            request.PaymentCard = paymentCard;

            Buyer buyer = new Buyer
            {
                Id   = customer.Id.ToString(),
                Name =
                    _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.FirstNameAttribute) ??
                    customer.BillingAddress.FirstName,
                Surname =
                    _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.LastNameAttribute) ??
                    customer.BillingAddress.LastName,
                GsmNumber =
                    _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.PhoneAttribute) ??
                    customer.BillingAddress.PhoneNumber,
                Email          = customer.Email ?? customer.BillingAddress.Email,
                IdentityNumber = paymentRequest.CustomValues["IdentityNumber"].ToString() ??
                                 _genericAttributeService.GetAttribute <string>(customer,
                                                                                NopCustomerDefaults.VatNumberAttribute),
                LastLoginDate       = Convert.ToDateTime(customer.LastLoginDateUtc).ToString("yyyy-M-d hh:mm:ff"),
                RegistrationDate    = customer.CreatedOnUtc.ToString("yyyy-M-d  hh:mm:ff"),
                RegistrationAddress = customer.BillingAddress.Address1,
                Ip      = customer.LastIpAddress,
                City    = customer.BillingAddress.City,
                Country = customer.BillingAddress.Country.Name,
                ZipCode = ""
            };

            request.Buyer = buyer;

            Address shippingAddress = new Address
            {
                ContactName = customer.ShippingAddress.FirstName + " " + customer.ShippingAddress.LastName,
                City        = customer.ShippingAddress.City,
                Country     = customer.ShippingAddress.Country.Name,
                Description = customer.ShippingAddress.Address1,
                ZipCode     = ""
            };

            request.ShippingAddress = shippingAddress;

            Address billingAddress = new Address
            {
                ContactName = customer.BillingAddress.FirstName + " " + customer.BillingAddress.LastName,
                City        = customer.BillingAddress.City,
                Country     = customer.BillingAddress.Country.Name,
                Description = customer.BillingAddress.Address1,
                ZipCode     = ""
            };

            request.BillingAddress = billingAddress;

            List <BasketItem> basketItems = new List <BasketItem>();

            foreach (var cartItem in cart)
            {
                var categorys    = _categoryService.GetProductCategoriesByProductId(cartItem.ProductId);
                var categoryName = string.Empty;
                foreach (var category in categorys)
                {
                    if (_categoryService.FindProductCategory(categorys, cartItem.ProductId, category.CategoryId) != null)
                    {
                        categoryName = category.Category.Name;
                    }
                }

                var basketItem = new BasketItem
                {
                    Id        = cartItem.Id.ToString(),
                    Name      = cartItem.Product.Name,
                    Category1 = categoryName,
                    Category2 = "",
                    ItemType  = BasketItemType.PHYSICAL.ToString(),
                    Price     = (_currencyService.ConvertFromPrimaryStoreCurrency(
                                     (cartItem.Product.Price * cartItem.Quantity), _workContext.WorkingCurrency))
                                .ToString("##.###")
                                .Replace(',', '.')
                };
                basketItems.Add(basketItem);
            }
            request.BasketItems = basketItems;
            if (forceDs)
            {
                request.CallbackUrl = $"{_webHelper.GetStoreLocation()}PaymentIyzicoPay/Success";
                ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, HelperApiOptions.GetApiContext(iyzicoSettings));
                if (threedsInitialize.Status == "success")
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(threedsInitialize.HtmlContent);
                    this._httpContextAccessor.HttpContext.Response.Clear();
                    this._httpContextAccessor.HttpContext.Response.Body.Write(bytes, 0, bytes.Length);
                    this._httpContextAccessor.HttpContext.Response.Body.Close();
                    result.AllowStoringCreditCardNumber = true;
                }
                else
                {
                    result.Errors = new List <string> {
                        threedsInitialize.ErrorCode, threedsInitialize.ErrorGroup, threedsInitialize.ErrorMessage
                    };
                }
            }
            else
            {
                Payment payment = Payment.Create(request, HelperApiOptions.GetApiContext(iyzicoSettings));
                if (payment.Status == "success")
                {
                    result.NewPaymentStatus             = payment.FraudStatus == 1 ? PaymentStatus.Paid : PaymentStatus.Pending;
                    result.AuthorizationTransactionId   = payment.PaymentId;
                    result.AuthorizationTransactionCode = payment.AuthCode;
                    result.AllowStoringCreditCardNumber = true;
                    var trans = string.Empty;
                    foreach (var item in payment.PaymentItems)
                    {
                        trans += item.ItemId + "-" + item.PaymentTransactionId + "-";
                    }
                    result.AuthorizationTransactionResult = trans;
                }
                else
                {
                    result.NewPaymentStatus = PaymentStatus.Pending;
                    result.Errors           = new List <string> {
                        payment.ErrorCode, payment.ErrorGroup, payment.ErrorMessage
                    };
                }
            }

            return(result);
        }