public void Should_Create_Threeds_Payment_With_Physical_And_Virtual_Item_For_Marketplace_Merchant() { CreateSubMerchantRequest createSubMerchantRequest = CreateSubMerchantRequestBuilder.Create() .PersonalSubMerchantRequest() .Build(); SubMerchant subMerchant = SubMerchant.Create(createSubMerchantRequest, _options); CreatePaymentRequest createPaymentRequest = CreatePaymentRequestBuilder.Create() .MarketplacePayment(subMerchant.SubMerchantKey) .CallbackUrl("https://www.merchant.com/callback") .Build(); ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(createPaymentRequest, _options); PrintResponse(threedsInitialize); Assert.AreEqual(Locale.TR.ToString(), threedsInitialize.Locale); Assert.AreEqual(Status.SUCCESS.ToString(), threedsInitialize.Status); Assert.NotNull(threedsInitialize.SystemTime); Assert.NotNull(threedsInitialize.HtmlContent); Assert.Null(threedsInitialize.ErrorCode); Assert.Null(threedsInitialize.ErrorMessage); Assert.Null(threedsInitialize.ErrorGroup); }
public async Task <IActionResult> ThreeDPay(CreditCardInfoFormVm request) { var currentUser = await _workContext.GetCurrentUser(); var order = await _orderService.CreateOrder(currentUser, "Iyzico"); var cart = await _cartService.GetCart(currentUser.Id); var create3DPayment = Create3dPayment(request, order.Value, cart, currentUser); var options = GetIyzcioOptions(); var threedsInitialize = ThreedsInitialize.Create(create3DPayment, options); if (threedsInitialize.Status == Status.SUCCESS.ToString()) { return(View(threedsInitialize.HtmlContent)); } return(View("Shared/unsuccessful", threedsInitialize.ErrorMessage)); }
public void Should_Create_Payment_With_Physical_And_Virtual_Item_For_Standard_Merchant() { CreatePaymentRequest createPaymentRequest = CreatePaymentRequestBuilder.Create() .StandardListingPayment() .CallbackUrl("https://www.merchant.com/callback") .Build(); ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(createPaymentRequest, Options); PrintResponse(threedsInitialize); Assert.AreEqual(Locale.TR.ToString(), threedsInitialize.Locale); Assert.AreEqual(Status.SUCCESS.ToString(), threedsInitialize.Status); Assert.NotNull(threedsInitialize.SystemTime); Assert.NotNull(threedsInitialize.HtmlContent); Assert.Null(threedsInitialize.ErrorCode); Assert.Null(threedsInitialize.ErrorMessage); Assert.Null(threedsInitialize.ErrorGroup); }
public void Should_Initialize_Threeds() { CreatePaymentRequest request = new CreatePaymentRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = "123456789"; request.Price = "1"; request.PaidPrice = "1.2"; request.Currency = Currency.TRY.ToString(); request.Installment = 1; request.BasketId = "B67832"; request.PaymentChannel = PaymentChannel.WEB.ToString(); request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); request.CallbackUrl = "https://www.merchant.com/callback"; PaymentCard paymentCard = new PaymentCard(); paymentCard.CardHolderName = "John Doe"; paymentCard.CardNumber = "5528790000000008"; paymentCard.ExpireMonth = "12"; paymentCard.ExpireYear = "2030"; paymentCard.Cvc = "123"; paymentCard.RegisterCard = 0; request.PaymentCard = paymentCard; Buyer buyer = new Buyer(); buyer.Id = "BY789"; buyer.Name = "John"; buyer.Surname = "Doe"; buyer.GsmNumber = "+905350000000"; buyer.Email = "*****@*****.**"; buyer.IdentityNumber = "74300864791"; buyer.LastLoginDate = "2015-10-05 12:43:35"; buyer.RegistrationDate = "2013-04-21 15:12:09"; buyer.RegistrationAddress = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; buyer.Ip = "85.34.78.112"; buyer.City = "Istanbul"; buyer.Country = "Turkey"; buyer.ZipCode = "34732"; request.Buyer = buyer; Address shippingAddress = new Address(); shippingAddress.ContactName = "Jane Doe"; shippingAddress.City = "Istanbul"; shippingAddress.Country = "Turkey"; shippingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; shippingAddress.ZipCode = "34742"; request.ShippingAddress = shippingAddress; Address billingAddress = new Address(); billingAddress.ContactName = "Jane Doe"; billingAddress.City = "Istanbul"; billingAddress.Country = "Turkey"; billingAddress.Description = "Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1"; billingAddress.ZipCode = "34742"; request.BillingAddress = billingAddress; List <BasketItem> basketItems = new List <BasketItem>(); BasketItem firstBasketItem = new BasketItem(); firstBasketItem.Id = "BI101"; firstBasketItem.Name = "Binocular"; firstBasketItem.Category1 = "Collectibles"; firstBasketItem.Category2 = "Accessories"; firstBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); firstBasketItem.Price = "0.3"; basketItems.Add(firstBasketItem); BasketItem secondBasketItem = new BasketItem(); secondBasketItem.Id = "BI102"; secondBasketItem.Name = "Game code"; secondBasketItem.Category1 = "Game"; secondBasketItem.Category2 = "Online Game Items"; secondBasketItem.ItemType = BasketItemType.VIRTUAL.ToString(); secondBasketItem.Price = "0.5"; basketItems.Add(secondBasketItem); BasketItem thirdBasketItem = new BasketItem(); thirdBasketItem.Id = "BI103"; thirdBasketItem.Name = "Usb"; thirdBasketItem.Category1 = "Electronics"; thirdBasketItem.Category2 = "Usb / Cable"; thirdBasketItem.ItemType = BasketItemType.PHYSICAL.ToString(); thirdBasketItem.Price = "0.2"; basketItems.Add(thirdBasketItem); request.BasketItems = basketItems; ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, options); PrintResponse <ThreedsInitialize>(threedsInitialize); Assert.AreEqual(Status.SUCCESS.ToString(), threedsInitialize.Status); Assert.AreEqual(Locale.TR.ToString(), threedsInitialize.Locale); Assert.AreEqual("123456789", threedsInitialize.ConversationId); Assert.IsNotNull(threedsInitialize.SystemTime); Assert.IsNull(threedsInitialize.ErrorCode); Assert.IsNull(threedsInitialize.ErrorMessage); Assert.IsNull(threedsInitialize.ErrorGroup); Assert.IsNotNull(threedsInitialize.HtmlContent); }
public override void DoOperation() { try { //Validate Reques Header / Constants this.baseResponseMessage = ValidateInput(); if (!this.baseResponseMessage.header.IsSuccess) { throw new Exception(this.baseResponseMessage.header.ResponseMessage); } Options baseHeader = null; string errMsg = ""; string errCode = ""; bool result = true; //Operation switch (this.request.Header.OperationTypes) { case (int)OperationType.OperationTypes.ADD: #region PAYMENT //Create payments Iyzipay.Request.CreatePaymentRequest paymentRequest = PrepareRequest(ref result, ref errMsg, ref baseHeader, ref errCode); Payment payment = Payment.Create(paymentRequest, baseHeader); RetrievePaymentRequest request = new RetrievePaymentRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = payment.ConversationId; request.PaymentId = payment.PaymentId; request.PaymentConversationId = payment.ConversationId; //check payments Payment Checkpayments = Payment.Retrieve(request, baseHeader); if (Checkpayments.Status == Status.FAILURE.ToString()) { throw new Exception("Odeme basarısız"); } bool checkvalue = false; //add transaction CommonServices.AddTransaction(this.request, ref checkvalue); //response this.response = new ResponsePayment { CALLBACK_URL = paymentRequest.CallbackUrl, CARD_HOLDER_NAME = paymentRequest.PaymentCard.CardHolderName, CARD_REF_NUMBER = paymentRequest.PaymentCard.CardNumber, CONVERSATION_ID = payment.ConversationId, CURRENCY = payment.Currency, CUSTOMER_NUMBER = Convert.ToInt64(paymentRequest.Buyer.Id), IP = paymentRequest.Buyer.Ip, PAID_PRICE = payment.PaidPrice, PRICE = payment.Price, PAYMENT_CHANNEL = paymentRequest.PaymentChannel, PAYMENT_ID = Checkpayments.PaymentId, header = new ResponseHeader { IsSuccess = checkvalue == false ? false : true, ResponseCode = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS, ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE } }; #endregion break; case (int)OperationType.OperationTypes.DELETE: #region REFUND //Create ReFund FillOptionHeader(ref baseHeader); CreateRefundRequest refundRequest = new CreateRefundRequest(); refundRequest.ConversationId = this.request.CONVERSATION_ID; refundRequest.Locale = Locale.TR.ToString(); refundRequest.PaymentTransactionId = this.request.PAYMENT_ID; refundRequest.Price = this.request.PRICE; refundRequest.Ip = this.request.IP; refundRequest.Currency = this.request.CURRENCY; //check refund Refund refund = Refund.Create(refundRequest, baseHeader); if (refund.Status == Status.FAILURE.ToString()) { throw new Exception(" Geri ödeme basarısız"); } //Transaction checkvalue = false; //add transaction CommonServices.AddTransaction(this.request, ref checkvalue); //response this.response = new ResponsePayment { CALLBACK_URL = this.request.CALLBACK_URL, CARD_HOLDER_NAME = this.request.CARD_HOLDER_NAME, CARD_REF_NUMBER = this.request.CARD_REF_NUMBER, CONVERSATION_ID = refundRequest.ConversationId, CURRENCY = refundRequest.Currency, CUSTOMER_NUMBER = this.request.CUSTOMER_NUMBER, IP = refundRequest.Ip, PAID_PRICE = refundRequest.Price, PRICE = refundRequest.Price, PAYMENT_CHANNEL = this.request.PAYMENT_CHANNEL, PAYMENT_ID = refundRequest.PaymentTransactionId, header = new ResponseHeader { IsSuccess = checkvalue == false ? false : true, ResponseCode = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS, ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE } }; #endregion break; case (int)OperationType.OperationTypes.UPDATE: #region BKM PAYMENT CreateBkmInitializeRequest requestBKM = PrepareBkmRequest(ref baseHeader); BkmInitialize bkmInitialize = BkmInitialize.Create(requestBKM, baseHeader); RetrieveBkmRequest retrieveBKM = new RetrieveBkmRequest(); retrieveBKM.Locale = Locale.TR.ToString(); retrieveBKM.ConversationId = "123456789"; retrieveBKM.Token = "token"; Bkm bkm = Bkm.Retrieve(retrieveBKM, baseHeader); if (bkm.Status == Status.FAILURE.ToString()) { throw new Exception("Odeme basarısız"); } //Transaction checkvalue = false; //add transaction CommonServices.AddTransaction(this.request, ref checkvalue); //response this.response = new ResponsePayment { CALLBACK_URL = requestBKM.CallbackUrl, CARD_HOLDER_NAME = "", CARD_REF_NUMBER = "", CONVERSATION_ID = requestBKM.ConversationId, CURRENCY = "", CUSTOMER_NUMBER = Convert.ToInt64(requestBKM.Buyer.Id), IP = requestBKM.Buyer.Ip, PAID_PRICE = requestBKM.Price, PRICE = requestBKM.Price, PAYMENT_CHANNEL = requestBKM.PaymentSource, PAYMENT_ID = requestBKM.BasketId, header = new ResponseHeader { IsSuccess = checkvalue == false ? false : true, ResponseCode = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS, ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE } }; #endregion break; case (int)OperationType.OperationTypes.GET: #region 3D PAYMENT //Initialize 3D Payment Iyzipay.Request.CreatePaymentRequest payment3DRequest = Prepare3DRequest(ref baseHeader); ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(payment3DRequest, baseHeader); if (threedsInitialize.Status == Status.FAILURE.ToString()) { throw new Exception("Odeme basarısız"); } //Create 3D Payment CreateThreedsPaymentRequest create3Drequestpayment = new CreateThreedsPaymentRequest(); create3Drequestpayment.Locale = Locale.TR.ToString(); create3Drequestpayment.ConversationId = payment3DRequest.ConversationId; create3Drequestpayment.PaymentId = this.request.PAYMENT_ID; create3Drequestpayment.ConversationData = "conversation data"; // ????? ThreedsPayment threedsPayment = ThreedsPayment.Create(create3Drequestpayment, baseHeader); if (threedsPayment.Status == Status.FAILURE.ToString()) { throw new Exception("Odeme basarısız"); } //Transaction checkvalue = false; //add transaction CommonServices.AddTransaction(this.request, ref checkvalue); //response this.response = new ResponsePayment { CALLBACK_URL = payment3DRequest.CallbackUrl, CARD_HOLDER_NAME = payment3DRequest.PaymentCard.CardHolderName, CARD_REF_NUMBER = payment3DRequest.PaymentCard.CardNumber, CONVERSATION_ID = payment3DRequest.ConversationId, CURRENCY = payment3DRequest.Currency, CUSTOMER_NUMBER = Convert.ToInt64(payment3DRequest.Buyer.Id), IP = payment3DRequest.Buyer.Ip, PAID_PRICE = payment3DRequest.PaidPrice, PRICE = payment3DRequest.Price, PAYMENT_CHANNEL = payment3DRequest.PaymentChannel, PAYMENT_ID = create3Drequestpayment.PaymentId, header = new ResponseHeader { IsSuccess = checkvalue == false ? false : true, ResponseCode = checkvalue == false ? CommonDefinitions.INTERNAL_TRANSACTION_ERROR : CommonDefinitions.SUCCESS, ResponseMessage = checkvalue == false ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE } }; #endregion break; default: break; } } catch (Exception ex) { log.Error("Payment Operation has an ERROR: [ERROR : " + ex.Message + "]"); throw new Exception("Ödeme sirasinda hata oluştu."); } }
/// <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 customer = _customerSerivce.GetCustomerById(postProcessPaymentRequest.Order.CustomerId); var options = IyzicoConfig(); var request = new CreatePaymentRequest(); request.ConversationId = postProcessPaymentRequest.Order.OrderGuid.ToString(); request.Price = postProcessPaymentRequest.Order.OrderTotal.ToString(); request.PaidPrice = postProcessPaymentRequest.Order.OrderTotal.ToString(); request.Currency = Currency.TRY.ToString(); request.Installment = 1; request.BasketId = postProcessPaymentRequest.Order.OrderGuid.ToString(); request.PaymentChannel = PaymentChannel.WEB.ToString(); request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); PaymentCard paymentCard = new PaymentCard(); paymentCard.CardHolderName = _encryptionService.DecryptText(postProcessPaymentRequest.Order.CardName); paymentCard.CardNumber = _encryptionService.DecryptText(postProcessPaymentRequest.Order.CardNumber); paymentCard.ExpireMonth = _encryptionService.DecryptText(postProcessPaymentRequest.Order.CardExpirationMonth.ToString()); paymentCard.ExpireYear = _encryptionService.DecryptText(postProcessPaymentRequest.Order.CardExpirationYear.ToString()); paymentCard.Cvc = _encryptionService.DecryptText(postProcessPaymentRequest.Order.CardCvv2); paymentCard.RegisterCard = 0; // paymentCard. request.PaymentCard = paymentCard; Buyer buyer = new Buyer(); buyer.Id = postProcessPaymentRequest.Order.CustomerId; buyer.Name = customer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName); buyer.Surname = customer.GetAttribute <string>(SystemCustomerAttributeNames.LastName); // SystemCustomerAttributeNames.ImpersonatedCustomerId // buyer.GsmNumber = "+905350000000"; buyer.Email = postProcessPaymentRequest.Order.CustomerEmail; buyer.IdentityNumber = "74300864791"; // buyer.LastLoginDate = "2015-10-05 12:43:35"; // buyer.RegistrationDate = "2013-04-21 15:12:09"; var address = postProcessPaymentRequest.Order.BillingAddress != null ? postProcessPaymentRequest.Order.BillingAddress.Address1 : "No address registred"; buyer.RegistrationAddress = postProcessPaymentRequest.Order.BillingAddress.Address1; buyer.City = postProcessPaymentRequest.Order.BillingAddress.City; var country = _countryService.GetCountryById(postProcessPaymentRequest.Order.BillingAddress.CountryId); buyer.Country = country != null ? country.Name : "USA"; buyer.ZipCode = postProcessPaymentRequest.Order.BillingAddress.ZipPostalCode; buyer.RegistrationAddress = address; buyer.Ip = customer.LastIpAddress; // buyer.City = customer.Addresses.; // buyer.Country = "Turkey"; // buyer.ZipCode = "34732"; request.Buyer = buyer; // This addresses are not right for this part. We have to get the order's addresses. This method need an improvement. Address shippingAddress = new Address(); var shippingCountry = _countryService.GetCountryById(postProcessPaymentRequest.Order.ShippingAddress.CountryId); shippingAddress.ContactName = postProcessPaymentRequest.Order.ShippingAddress.FirstName + " " + postProcessPaymentRequest.Order.ShippingAddress.LastName; shippingAddress.City = postProcessPaymentRequest.Order.ShippingAddress.City; shippingAddress.Country = shippingCountry.Name; shippingAddress.Description = postProcessPaymentRequest.Order.ShippingAddress.Address1 + " " + postProcessPaymentRequest.Order.ShippingAddress.Address2; shippingAddress.ZipCode = postProcessPaymentRequest.Order.ShippingAddress.ZipPostalCode; request.ShippingAddress = shippingAddress; Address billingAddress = new Address(); var billingCountry = _countryService.GetCountryById(postProcessPaymentRequest.Order.BillingAddress.CountryId); billingAddress.ContactName = postProcessPaymentRequest.Order.BillingAddress.FirstName + " " + postProcessPaymentRequest.Order.BillingAddress.LastName; billingAddress.City = postProcessPaymentRequest.Order.BillingAddress.City; billingAddress.Country = billingCountry.Name; billingAddress.Description = postProcessPaymentRequest.Order.BillingAddress.Address1 + " " + postProcessPaymentRequest.Order.BillingAddress.Address2; billingAddress.ZipCode = postProcessPaymentRequest.Order.BillingAddress.ZipPostalCode; request.BillingAddress = billingAddress; List <BasketItem> basketItems = new List <BasketItem>(); var products = postProcessPaymentRequest.Order.OrderItems.Select(i => _productService.GetProductById(i.ProductId)); // var product = _productService.GetProductById(); BasketItem basketItem = new BasketItem(); basketItem.Id = string.Join(',', products.Select(i => i.Id)); basketItem.Name = string.Join(',', products.Select(i => i.Name)); basketItem.Category1 = "Etiket"; basketItem.ItemType = BasketItemType.PHYSICAL.ToString(); basketItem.Price = postProcessPaymentRequest.Order.OrderTotal.ToString(); basketItems.Add(basketItem); request.BasketItems = basketItems; var loc = _webHelper.GetStoreLocation(); request.CallbackUrl = $"{loc}Plugins/Iyzico/Handler"; var payment = ThreedsInitialize.Create(request, options); if (payment.Status.Equals("success")) { _httpContextAccessor.HttpContext.Session.SetString("Iyzico.HtmlContent", payment.HtmlContent); var htmlContentRedirect = $"{loc}Plugins/Iyzico/ThreeDPayment"; _httpContextAccessor.HttpContext.Response.Redirect(htmlContentRedirect); } else { throw new Exception(payment.ErrorMessage); } }
private bool PayWithIyzipay(Order order, CreditCardModel card, String userId, IEnumerable <CartListModel> cart, ref string ErrorMessage, ref string PageContent, ref string ConversationId) { var user = db.Users.Find(userId); var billingCity = db.Cities.Find(order.BillingCityId).Name; var shippingCity = db.Cities.Find(order.ShippingCityId).Name; Options options = new Options(); options.ApiKey = ConfigurationManager.AppSettings["IyziApiKey"].ToString(); options.SecretKey = ConfigurationManager.AppSettings["IyziSecretKey"].ToString(); options.BaseUrl = "https://sandbox-api.iyzipay.com"; CreatePaymentRequest request = new CreatePaymentRequest(); request.Locale = Locale.TR.ToString(); request.ConversationId = order.OrderId.ToString(); request.Price = order.TotalPrice.ToString().Replace(",", "."); request.PaidPrice = order.TotalPrice.ToString().Replace(",", "."); request.Currency = Currency.TRY.ToString(); request.Installment = 1; request.BasketId = order.OrderId.ToString(); request.PaymentChannel = PaymentChannel.WEB.ToString(); request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); request.CallbackUrl = "http://" + Request.Url.Authority + "/Checkout/IyziReturn"; PaymentCard paymentCard = new PaymentCard(); paymentCard.CardHolderName = card.cardHolder; paymentCard.CardNumber = card.cardNumber; paymentCard.ExpireMonth = card.cardExpirationMonth.ToString(); paymentCard.ExpireYear = card.cardExpirationYear.ToString(); paymentCard.Cvc = card.cardCvv.ToString(); paymentCard.RegisterCard = 0; request.PaymentCard = paymentCard; Buyer buyer = new Buyer(); buyer.Id = userId; buyer.Name = order.BillingFirstName; buyer.Surname = order.BillingLastName; buyer.GsmNumber = "+90" + order.BillingTelephone; buyer.Email = order.BillingEmail; buyer.IdentityNumber = "74300864791"; buyer.LastLoginDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", user.LastLoginTime); //"2015-10-05 12:43:35"; buyer.RegistrationDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", user.RegistrationDate); //"2013-04-21 15:12:09"; buyer.RegistrationAddress = order.BillingStreet1 + " " + order.BillingStreet2; buyer.Ip = Request.UserHostAddress; buyer.City = billingCity; buyer.Country = "Turkey"; buyer.ZipCode = order.BillingZip; request.Buyer = buyer; Address shippingAddress = new Address(); shippingAddress.ContactName = order.ShippingFirstName + " " + order.ShippingLastName; shippingAddress.City = shippingCity; shippingAddress.Country = "Turkey"; shippingAddress.Description = order.ShippingStreet1 + " " + order.ShippingStreet2; shippingAddress.ZipCode = order.ShippingZip; request.ShippingAddress = shippingAddress; Address billingAddress = new Address(); billingAddress.ContactName = order.BillingFirstName + " " + order.BillingLastName; billingAddress.City = billingCity; billingAddress.Country = "Turkey"; billingAddress.Description = order.BillingStreet1 + " " + order.BillingStreet2; billingAddress.ZipCode = order.BillingZip; request.BillingAddress = billingAddress; List <BasketItem> basketItems = new List <BasketItem>(); foreach (CartListModel item in cart) { BasketItem basketItem = new BasketItem(); basketItem.Id = item.VariantId.ToString(); basketItem.Name = item.VariantName + " " + item.ProductName; basketItem.Category1 = "Giyim"; basketItem.ItemType = BasketItemType.PHYSICAL.ToString(); basketItem.Price = item.TotalPrice.ToString().Replace(",", "."); basketItems.Add(basketItem); } BasketItem shippingItem = new BasketItem(); shippingItem.Id = "K1"; shippingItem.Name = "Kargo"; shippingItem.Category1 = "Kargo"; shippingItem.ItemType = BasketItemType.VIRTUAL.ToString(); shippingItem.Price = order.ShippingCost.ToString().Replace(",", "."); basketItems.Add(shippingItem); request.BasketItems = basketItems; //Payment payment = Payment.Create(request, options); ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, options); //PrintResponse<Payment>(payment); bool success = threedsInitialize.Status == "success"; if (!success) { ErrorMessage = threedsInitialize.ErrorMessage; } else { ConversationId = threedsInitialize.ConversationId; PageContent = threedsInitialize.HtmlContent; } return(success); }
private ThreedsInitialize sendIyzico(AppUser appUser, List <Cart> carts, CheckoutModel_req checkoutModel_Req, UserAddress userAddress, string orderId, string ip) { Options options = new Options(); options.ApiKey = "sandbox-OPMmAWhaJiQntmjPPVrolCuJ8XLWITGd"; options.SecretKey = "sandbox-wPykKvg4r9BZUGAlvFP08eOf90iYY9oS"; options.BaseUrl = "https://sandbox-api.iyzipay.com"; List <BasketItem> basketItems = new List <BasketItem>(); double totalPrice = 0; CreatePaymentRequest request = new CreatePaymentRequest(); for (int i = 0; i < carts.Count; i++) { BasketItem basket = new BasketItem(); basket.Id = carts[i].ProductAmountType.Id.ToString(); basket.Name = carts[i].ProductAmountType.Product.ProductName; basket.ItemType = BasketItemType.PHYSICAL.ToString(); basket.Price = carts[i].ProductAmountType.Price.ToString(); basket.Category1 = carts[i].ProductAmountType.Product.ProductCategories[0].Category.CategoryName; basketItems.Add(basket); totalPrice = totalPrice + carts[i].ProductAmountType.Price; } request.BasketItems = basketItems; request.Locale = Locale.TR.ToString(); request.ConversationId = orderId; request.Price = totalPrice.ToString(); request.PaidPrice = totalPrice.ToString(); request.Currency = Currency.TRY.ToString(); request.Installment = checkoutModel_Req.Installment; request.BasketId = orderId; request.PaymentChannel = PaymentChannel.WEB.ToString(); request.PaymentGroup = PaymentGroup.PRODUCT.ToString(); request.CallbackUrl = "http://192.168.1.100:2176/api/checkout/callback"; PaymentCard paymentCard = new PaymentCard(); paymentCard.CardHolderName = checkoutModel_Req.FullName; paymentCard.CardNumber = checkoutModel_Req.CardNumber; paymentCard.ExpireMonth = checkoutModel_Req.Mounth; paymentCard.ExpireYear = "20" + checkoutModel_Req.Year; paymentCard.Cvc = checkoutModel_Req.Cvc; paymentCard.RegisterCard = 0; request.PaymentCard = paymentCard; Buyer buyer = new Buyer(); buyer.Id = appUser.Id; buyer.Name = appUser.FirstName; buyer.Surname = appUser.LastName; buyer.GsmNumber = appUser.UserName; buyer.Email = appUser.Email; buyer.IdentityNumber = appUser.Tckn; buyer.RegistrationAddress = checkoutModel_Req.Address; buyer.City = checkoutModel_Req.City; buyer.Country = checkoutModel_Req.District; buyer.Ip = ip; request.Buyer = buyer; Address shippingAddress = new Address(); shippingAddress.ContactName = appUser.FirstName + " " + appUser.LastName; shippingAddress.City = userAddress.City; shippingAddress.Country = "Turkey"; shippingAddress.Description = userAddress.Adress; request.ShippingAddress = shippingAddress; Address billingAddress = new Address(); billingAddress.ContactName = appUser.FirstName + " " + appUser.LastName; billingAddress.City = userAddress.City; billingAddress.Country = "Turkey"; billingAddress.Description = userAddress.Adress; request.BillingAddress = billingAddress; ThreedsInitialize threedsInitialize = ThreedsInitialize.Create(request, options); return(threedsInitialize); }
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); }