Exemple #1
0
        private CreatePaymentRequest Create3dPayment(CreditCardInfoFormVm request, Order order, CartVm cartVm, User currentUser)
        {
            var paymentRequest = CreatePaymentRequest(request, order, cartVm, currentUser);

            paymentRequest.CallbackUrl = new Uri($"{Request.Scheme}://{Request.Host}/iyzico/threeds").AbsolutePath;
            return(paymentRequest);
        }
Exemple #2
0
        private Payment CreatePayment(CreditCardInfoFormVm request, Order order, CartVm cartVm, User currentUser)
        {
            var paymentRequest = CreatePaymentRequest(request, order, cartVm, currentUser);
            var options        = GetIyzcioOptions();

            return(Payment.Create(paymentRequest, options));
        }
Exemple #3
0
        public async Task <IActionResult> Pay(CreditCardInfoFormVm request)
        {
            var currentUser = await _workContext.GetCurrentUser();

            var order = await _orderService.CreateOrder(currentUser, "Iyzico");

            var cart = await _cartService.GetCart(currentUser.Id);

            var status = CreatePayment(request, order.Value, cart, currentUser);

            if (status.Status == Status.SUCCESS.ToString())
            {
                return(View("Shared/success"));
            }
            return(View("Shared/unsuccessful", new UnsuccessfulVm {
                Status = status.Status, ErrorMessage = status.ErrorMessage
            }));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        private CreatePaymentRequest CreatePaymentRequest(CreditCardInfoFormVm request, Order order, CartVm cartVm, User currentUser)
        {
            var paymentRequest = new CreatePaymentRequest
            {
                Locale         = Locale.TR.ToString(),
                ConversationId = "123456789",
                Price          = Convert.ToString(cartVm.OrderTotal),
                PaidPrice      = "0",
                Currency       = Currency.TRY.ToString(),
                Installment    = 1,
                BasketId       = order.Id.ToString(),
                PaymentChannel = PaymentChannel.WEB.ToString(),
                PaymentGroup   = PaymentGroup.PRODUCT.ToString(),
            };
            var paymentCard = new PaymentCard
            {
                CardHolderName = request.CardHolderName,
                CardNumber     = request.CardNumber,
                ExpireMonth    = request.ExpiryMonth.ToString(),
                ExpireYear     = request.ExpiryYear.ToString(),
                Cvc            = request.Cvv.ToString(),
                RegisterCard   = 0
            };

            paymentRequest.PaymentCard = paymentCard;
            var buyer = new Buyer
            {
                Id               = currentUser.Id.ToString(),
                Name             = order.BillingAddress.ContactName,
                Surname          = order.BillingAddress.LastName,
                GsmNumber        = currentUser.PhoneNumber,
                Email            = currentUser.Email,
                IdentityNumber   = order.BillingAddress.TaxId.ToString(),
                RegistrationDate = currentUser.CreatedOn.Date.ToString(),
                Ip               = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(),
                City             = order.BillingAddress.City,
                Country          = "Turkey",
                ZipCode          = order.BillingAddress.PostalCode
            };

            paymentRequest.Buyer = buyer;
            var shippingAddress = new Address
            {
                ContactName = order.ShippingAddress.ContactName,
                City        = order.ShippingAddress.City,
                Country     = "Turkey",
                Description =
                    $"{order.ShippingAddress.AddressLine1} {order.ShippingAddress.AddressLine2} {order.ShippingAddress.District} {order.ShippingAddress.City}",
                ZipCode = order.ShippingAddress.PostalCode
            };

            paymentRequest.ShippingAddress = shippingAddress;
            var billingAddress = new Address
            {
                ContactName = order.BillingAddress.ContactName,
                City        = order.BillingAddress.City,
                Country     = "Turkey",
                Description =
                    $"{order.BillingAddress.AddressLine1} {order.BillingAddress.AddressLine2} {order.BillingAddress.District} {order.BillingAddress.City}",
                ZipCode = order.ShippingAddress.PostalCode
            };

            paymentRequest.BillingAddress = billingAddress;
            foreach (var orderItem in order.OrderItems)
            {
                var productCategory = _productCategoryRepository.Query().FirstOrDefault(f => f.ProductId == orderItem.ProductId);
                var category        = _categoryRepository.Query().FirstOrDefault(f => f.Id == productCategory.CategoryId);

                paymentRequest.BasketItems.Add(new BasketItem
                {
                    Id        = orderItem.Id.ToString(),
                    Name      = orderItem.Product.Name,
                    Category1 = category.Name,
                    ItemType  = BasketItemType.PHYSICAL.ToString(),
                    Price     = Convert.ToString(orderItem.ProductPrice)
                });
            }
            paymentRequest.PaymentCard = paymentCard;
            return(paymentRequest);
        }