/// <summary> /// Get installment /// </summary> /// <param name="processPaymentRequest">Process Payment Request</param> /// <param name="paymentCard">Payment Card</param> /// <param name="options">Iyzipay Options</param> /// <returns>installment</returns> private Installment GetInstallment(ProcessPaymentRequest processPaymentRequest, PaymentCard paymentCard, Armut.Iyzipay.Options options) { int.TryParse((string)processPaymentRequest.CustomValues.GetValueOrDefault(_localizationService.GetResource("Plugins.Payments.Iyzico.Installment")), out int formInstallment); var retrieveInstallmentInfoRequest = new RetrieveInstallmentInfoRequest() { BinNumber = paymentCard.CardNumber.ToString(), Locale = Locale.TR.ToString(), Price = _priceCalculationService.RoundPrice(processPaymentRequest.OrderTotal).ToString("f8", CultureInfo.InvariantCulture), ConversationId = string.Empty }; var installmentInfo = InstallmentInfo.Retrieve(retrieveInstallmentInfoRequest, options); var installment = new Installment() { InstallmentNumber = 1, TotalPrice = _priceCalculationService.RoundPrice(processPaymentRequest.OrderTotal).ToString("f8", CultureInfo.InvariantCulture) }; if (installmentInfo.Status == "success" && installmentInfo.InstallmentDetails.Count > 0) { var installmentDetail = installmentInfo.InstallmentDetails.FirstOrDefault().InstallmentPrices.FirstOrDefault(x => x.InstallmentNumber == formInstallment); installment.InstallmentNumber = installmentDetail.InstallmentNumber ?? 1; installment.TotalPrice = installmentDetail.TotalPrice.Replace(".", ","); } return(installment); }
public void Should_Retrieve_Installments() { RetrieveInstallmentInfoRequest request = new RetrieveInstallmentInfoRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; request.BinNumber = "554960"; request.Price = "100"; InstallmentInfo installmentInfo = InstallmentInfo.Retrieve(request, _options); PrintResponse(installmentInfo); Assert.AreEqual(Status.SUCCESS.ToString(), installmentInfo.Status); Assert.AreEqual(Locale.TR.ToString(), installmentInfo.Locale); Assert.AreEqual("123456789", installmentInfo.ConversationId); Assert.NotNull(installmentInfo.InstallmentDetails[0]); Assert.AreEqual("554960", installmentInfo.InstallmentDetails[0].BinNumber); Assert.AreEqual("100", installmentInfo.InstallmentDetails[0].Price); Assert.AreEqual("CREDIT_CARD", installmentInfo.InstallmentDetails[0].CardType); Assert.AreEqual("MASTER_CARD", installmentInfo.InstallmentDetails[0].CardAssociation); Assert.AreEqual("Bonus", installmentInfo.InstallmentDetails[0].CardFamilyName); Assert.NotNull(installmentInfo.InstallmentDetails[0].InstallmentPrices[0].InstallmentNumber); Assert.NotNull(installmentInfo.InstallmentDetails[0].InstallmentPrices[0].Price); Assert.NotNull(installmentInfo.InstallmentDetails[0].InstallmentPrices[0].TotalPrice); Assert.NotNull(installmentInfo.SystemTime); Assert.Null(installmentInfo.ErrorCode); Assert.Null(installmentInfo.ErrorMessage); Assert.Null(installmentInfo.ErrorGroup); Assert.NotNull(installmentInfo.InstallmentDetails); Assert.False(installmentInfo.InstallmentDetails.Count == 0); }
public IActionResult BinControl(string cardnumber) { var customer = _customerService.GetCustomerById(_workContext.CurrentCustomer.Id); var cart = _workContext.CurrentCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .LimitPerStore(_storeContext.CurrentStore.Id) .ToList(); RetrieveInstallmentInfoRequest request = new RetrieveInstallmentInfoRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = customer.CustomerGuid.ToString(); request.BinNumber = cardnumber; decimal price = 0; foreach (var shoppingCartItem in cart) { price += (shoppingCartItem.Product.Price * shoppingCartItem.Quantity); } request.Price = _currencyService.ConvertFromPrimaryStoreCurrency(price, _workContext.WorkingCurrency).ToString("##.###").Replace(',', '.'); InstallmentInfo installmentInfo = InstallmentInfo.Retrieve(request, HelperApiOptions.GetApiContext(_iyzicoPayPaymentSettings)); return(Json(installmentInfo)); }
public virtual IActionResult GetInstallment(string binNumber) { if (String.IsNullOrEmpty(binNumber)) { return(Json(String.Empty)); } var customer = _customerService.GetCustomerById(_workContext.CurrentCustomer.Id); var shoppingCart = _shoppingCartService.GetShoppingCart(customer, ShoppingCartType.ShoppingCart); var shoppingCartTotal = _orderTotalCalculationService.GetShoppingCartTotal(shoppingCart, out var orderDiscountAmount, out var orderAppliedDiscounts, out var appliedGiftCards, out var redeemedRewardPoints, out var redeemedRewardPointsAmount); var options = IyzicoHelper.GetIyzicoOptions(_iyzicoPaymentSettings); var retrieveInstallmentInfoRequest = new RetrieveInstallmentInfoRequest() { BinNumber = binNumber.ToString(), Locale = Locale.TR.ToString(), Price = _priceCalculationService.RoundPrice(shoppingCartTotal.Value).ToString("f8", CultureInfo.InvariantCulture), ConversationId = string.Empty }; var installmentInfo = InstallmentInfo.Retrieve(retrieveInstallmentInfoRequest, options); var subTotalIncludingTax = _workContext.TaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal; var subtotal = decimal.Zero; var list = new List <Installment>(); if (installmentInfo.Status == "success" && installmentInfo.InstallmentDetails.Count > 0) { foreach (var installmentDetail in installmentInfo.InstallmentDetails.FirstOrDefault().InstallmentPrices) { var installment = new Installment(); installment.DisplayName = _localizationService.GetResource("Plugins.Payments.Iyzico.Installment" + installmentDetail.InstallmentNumber); installment.InstallmentNumber = installmentDetail.InstallmentNumber ?? 0; decimal.TryParse(installmentDetail.Price.Replace(".", ","), out decimal price); installment.Price = _priceFormatter.FormatPrice(price, true, _workContext.WorkingCurrency, _workContext.WorkingLanguage.Id, subTotalIncludingTax); decimal.TryParse(installmentDetail.TotalPrice.Replace(".", ","), out decimal totalPrice); installment.TotalPrice = _priceFormatter.FormatPrice(totalPrice, true, _workContext.WorkingCurrency, _workContext.WorkingLanguage.Id, subTotalIncludingTax); list.Add(installment); } } else { subtotal = _currencyService.ConvertFromPrimaryStoreCurrency(shoppingCartTotal ?? 0, _workContext.WorkingCurrency); list.Add(new Installment() { DisplayName = _localizationService.GetResource("Plugins.Payments.Iyzico.Installment1"), InstallmentNumber = 1, Price = _priceFormatter.FormatPrice(subtotal, true, _workContext.WorkingCurrency, _workContext.WorkingLanguage.Id, subTotalIncludingTax), TotalPrice = _priceFormatter.FormatPrice(subtotal, true, _workContext.WorkingCurrency, _workContext.WorkingLanguage.Id, subTotalIncludingTax) }); } return(Json(list)); }
public void Should_Retrieve_Installment_Info() { RetrieveInstallmentInfoRequest request = new RetrieveInstallmentInfoRequest(); request.Locale = Locale.TR.GetName(); request.ConversationId = "123456789"; request.BinNumber = "554960"; request.Price = "1"; InstallmentInfo installmentInfo = InstallmentInfo.Retrieve(request, options); PrintResponse <InstallmentInfo>(installmentInfo); Assert.IsNotNull(installmentInfo.SystemTime); Assert.AreEqual(Status.SUCCESS.ToString(), installmentInfo.Status); Assert.AreEqual(Locale.TR.GetName(), installmentInfo.Locale); Assert.AreEqual("123456789", installmentInfo.ConversationId); }
/// <summary> /// Gets additional handling fee /// </summary> /// <param name="cart">Shoping cart</param> /// <returns>Additional handling fee</returns> public decimal GetAdditionalHandlingFee(IList <ShoppingCartItem> cart) { var processPaymentRequest = _httpContextAccessor.HttpContext?.Session?.Get <ProcessPaymentRequest>("OrderPaymentInfo"); if (processPaymentRequest != null) { var customer = _customerService.GetCustomerById(_workContext.CurrentCustomer.Id); var shoppingCart = _shoppingCartService.GetShoppingCart(customer, ShoppingCartType.ShoppingCart); var shoppingCartTotal = _orderTotalCalculationService.GetShoppingCartTotal(shoppingCart, out var orderDiscountAmount, out var orderAppliedDiscounts, out var appliedGiftCards, out var redeemedRewardPoints, out var redeemedRewardPointsAmount, usePaymentMethodAdditionalFee: false); var options = IyzicoHelper.GetIyzicoOptions(_iyzicoPaymentSettings); int.TryParse((string)processPaymentRequest.CustomValues.GetValueOrDefault(_localizationService.GetResource("Plugins.Payments.Iyzico.Installment")), out int formInstallment); var retrieveInstallmentInfoRequest = new RetrieveInstallmentInfoRequest() { BinNumber = processPaymentRequest.CreditCardNumber.Substring(0, 6), Locale = Locale.TR.ToString(), Price = _priceCalculationService.RoundPrice(shoppingCartTotal ?? 0).ToString("f8", CultureInfo.InvariantCulture), ConversationId = string.Empty }; var installmentInfo = InstallmentInfo.Retrieve(retrieveInstallmentInfoRequest, options); if (installmentInfo.Status == "success" && installmentInfo.InstallmentDetails.Count > 0) { decimal.TryParse(installmentInfo.InstallmentDetails.FirstOrDefault().InstallmentPrices.FirstOrDefault(x => x.InstallmentNumber == formInstallment).TotalPrice.Replace(".", ","), out decimal installmentTotalPrice); var fee = installmentTotalPrice - (shoppingCartTotal ?? 0); return(_paymentService.CalculateAdditionalFee(cart, fee, false)); } else { return(0); } } else { return(0); } }
public void Should_Retrieve_Installments() { RetrieveInstallmentInfoRequest request = new RetrieveInstallmentInfoRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; request.BinNumber = "554960"; request.Price = "100"; InstallmentInfo installmentInfo = InstallmentInfo.Retrieve(request, options); PrintResponse <InstallmentInfo>(installmentInfo); Assert.AreEqual(Status.SUCCESS.ToString(), installmentInfo.Status); Assert.AreEqual(Locale.TR.ToString(), installmentInfo.Locale); Assert.AreEqual("123456789", installmentInfo.ConversationId); Assert.IsNotNull(installmentInfo.SystemTime); Assert.IsNull(installmentInfo.ErrorCode); Assert.IsNull(installmentInfo.ErrorMessage); Assert.IsNull(installmentInfo.ErrorGroup); Assert.IsNotNull(installmentInfo.InstallmentDetails); Assert.IsNotEmpty(installmentInfo.InstallmentDetails); }