Ejemplo n.º 1
0
        /// <summary>
        /// Gets an enumeration of all available payment providers.
        /// </summary>
        /// <param name="param">Parameters used to retrieve the payment providers.</param>
        /// <returns></returns>
        public virtual async Task <IEnumerable <PaymentProviderViewModel> > GetPaymentProvidersAsync(GetPaymentProvidersParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.Scope == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param.Scope)), nameof(param));
            }

            var providers = PaymentProviderFactory.ResolveAllProviders();

            providers = await FilterAvailablePaymentProviders(param, providers).ConfigureAwait(false);

            var viewModels = new List <PaymentProviderViewModel>();

            foreach (var paymentProvider in providers)
            {
                var vm = MapPaymentProviderViewModel(paymentProvider, param.CultureInfo);
                viewModels.Add(vm);
            }

            return(viewModels);
        }
        public async Task Asseco_GetPaymentParameterResult_Success()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            var provider             = paymentProviderFactory.Create(BankNames.IsBankasi);
            var paymentGatewayResult = await provider.ThreeDGatewayRequest(new PaymentGatewayRequest
            {
                CardHolderName    = "Sefa Can",
                CardNumber        = "4508-0345-0803-4509",
                ExpireMonth       = 12,
                ExpireYear        = 21,
                CvvCode           = "000",
                CardType          = "1",
                Installment       = 1,
                TotalAmount       = 1.60m,
                CustomerIpAddress = IPAddress.Parse("127.0.0.1"),
                CurrencyIsoCode   = "949",
                LanguageIsoCode   = "tr",
                OrderNumber       = Guid.NewGuid().ToString(),
                BankName          = BankNames.IsBankasi,
                BankParameters    = provider.TestParameters,
                CallbackUrl       = new Uri("https://google.com")
            });

            Assert.True(paymentGatewayResult.Success);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CancelReservationProcessingStrategy" /> class.
        /// </summary>
        /// <param name="merchantOrderManager">The merchant order manager.</param>
        /// <param name="paymentProviderFactory">The payment provider factory.</param>
        public CancelReservationProcessingStrategy(MerchantOrderManager merchantOrderManager, PaymentProviderFactory paymentProviderFactory)
        {
            Assert.ArgumentNotNull(merchantOrderManager, "merchantOrderManager");
            Assert.ArgumentNotNull(paymentProviderFactory, "paymentProviderFactory");

            this.merchantOrderManager   = merchantOrderManager;
            this.paymentProviderFactory = paymentProviderFactory;
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="CancelReservationProcessingStrategy" /> class.
    /// </summary>
    /// <param name="merchantOrderManager">The merchant order manager.</param>
    /// <param name="paymentProviderFactory">The payment provider factory.</param>
    public CancelReservationProcessingStrategy(MerchantOrderManager merchantOrderManager, PaymentProviderFactory paymentProviderFactory)
    {
      Assert.ArgumentNotNull(merchantOrderManager, "merchantOrderManager");
      Assert.ArgumentNotNull(paymentProviderFactory, "paymentProviderFactory");

      this.merchantOrderManager = merchantOrderManager;
      this.paymentProviderFactory = paymentProviderFactory;
    }
        public void PaymentProviderFactory_CreateAssecoPaymentProvider(int bankId)
        {
            ServiceCollection      serviceCollection      = new ServiceCollection();
            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            IPaymentProvider       provider = paymentProviderFactory.Create((BankNames)bankId);

            Assert.IsType <NestPayPaymentProvider>(provider);
        }
Ejemplo n.º 6
0
        public void PaymentProviderFactory_CreateAssecoPaymentProvider()
        {
            ServiceCollection      serviceCollection      = new ServiceCollection();
            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            IPaymentProvider       provider = paymentProviderFactory.Create(BankNames.DenizBank);

            Assert.IsType <DenizbankPaymentProvider>(provider);
        }
        public void PaymentProviderFactory_CreateGarantiPaymentProvider()
        {
            ServiceCollection      serviceCollection      = new ServiceCollection();
            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            IPaymentProvider       provider = paymentProviderFactory.Create(BankNames.Garanti);

            Assert.IsType <GarantiPaymentProvider>(provider);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CaptureOrderProcessingStrategy"/> class.
        /// </summary>
        /// <param name="paymentProviderFactory">The payment provider factory.</param>
        /// <param name="transactionDataProvider">The transaction Data Provider.</param>
        /// <param name="pipelineWrapper">The pipeline wrapper.</param>
        public CaptureOrderProcessingStrategy(PaymentProviderFactory paymentProviderFactory, ITransactionData transactionDataProvider, PipelineWrapper pipelineWrapper)
        {
            Assert.ArgumentNotNull(paymentProviderFactory, "paymentProviderFactory");
            Assert.ArgumentNotNull(transactionDataProvider, "transactionDataProvider");
            Assert.ArgumentNotNull(pipelineWrapper, "pipelineWrapper");

            this.paymentProviderFactory  = paymentProviderFactory;
            this.transactionDataProvider = transactionDataProvider;
            this.pipelineWrapper         = pipelineWrapper;
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="CaptureOrderProcessingStrategy"/> class.
    /// </summary>
    /// <param name="paymentProviderFactory">The payment provider factory.</param>
    /// <param name="transactionDataProvider">The transaction Data Provider.</param>
    /// <param name="pipelineWrapper">The pipeline wrapper.</param>
    public CaptureOrderProcessingStrategy(PaymentProviderFactory paymentProviderFactory, ITransactionData transactionDataProvider, PipelineWrapper pipelineWrapper)
    {
      Assert.ArgumentNotNull(paymentProviderFactory, "paymentProviderFactory");
      Assert.ArgumentNotNull(transactionDataProvider, "transactionDataProvider");
      Assert.ArgumentNotNull(pipelineWrapper, "pipelineWrapper");

      this.paymentProviderFactory = paymentProviderFactory;
      this.transactionDataProvider = transactionDataProvider;
      this.pipelineWrapper = pipelineWrapper;
    }
        public async Task Garanti_GetPaymentParameterResult_UnSuccess()
        {
            ServiceCollection      serviceCollection      = new ServiceCollection();
            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            IPaymentProvider provider = paymentProviderFactory.Create(BankNames.Garanti);
            var paymentGatewayResult  = await provider.ThreeDGatewayRequest(null);

            Assert.False(paymentGatewayResult.Success);
        }
        public void PaymentProviderFactory_CreatePaymentForm_EmptyParameters_ThrowNullException()
        {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            Assert.Throws <ArgumentNullException>(() => paymentProviderFactory.CreatePaymentFormHtml(null, new Uri("https://google.com")));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrderTaskFlowButtonsPresenter"/> class.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="merchantOrderManager">The merchant order manager.</param>
        /// <param name="orderSecurity">The order security.</param>
        /// <param name="paymentProviderFactory">The payment provider factory.</param>
        public OrderTaskFlowButtonsPresenter([NotNull] IOrderTaskFlowButtonsView view, [NotNull] MerchantOrderManager merchantOrderManager, [NotNull] MerchantOrderSecurity orderSecurity,  PaymentProviderFactory paymentProviderFactory)
        {
            Assert.ArgumentNotNull(view, "view");
              Assert.ArgumentNotNull(merchantOrderManager, "merchantOrderManager");
              Assert.ArgumentNotNull(orderSecurity, "orderSecurity");

              this.view = view;
              this.view.SmartPanelClosed += this.SmartPanelClosedHandler;
              this.merchantOrderManager = merchantOrderManager;
              this.orderSecurity = orderSecurity;
              this.paymentProviderFactory = paymentProviderFactory;
        }
        public void PaymentProviderFactory_CreateVakifbankPaymentProvider()
        {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            IPaymentProvider       provider = paymentProviderFactory.Create(BankNames.VakifBank);

            Assert.IsType <VakifbankPaymentProvider>(provider);
        }
        public void PaymentProviderFactory_CreateYapikrediPaymentProvider()
        {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            IPaymentProvider       provider = paymentProviderFactory.Create(BankNames.Yapikredi);

            Assert.IsType <PosnetPaymentProvider>(provider);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrderTaskFlowButtonsPresenter"/> class.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="merchantOrderManager">The merchant order manager.</param>
        /// <param name="orderSecurity">The order security.</param>
        /// <param name="paymentProviderFactory">The payment provider factory.</param>
        public OrderTaskFlowButtonsPresenter([NotNull] IOrderTaskFlowButtonsView view, [NotNull] MerchantOrderManager merchantOrderManager, [NotNull] MerchantOrderSecurity orderSecurity, PaymentProviderFactory paymentProviderFactory)
        {
            Assert.ArgumentNotNull(view, "view");
            Assert.ArgumentNotNull(merchantOrderManager, "merchantOrderManager");
            Assert.ArgumentNotNull(orderSecurity, "orderSecurity");

            this.view = view;
            this.view.SmartPanelClosed += this.SmartPanelClosedHandler;
            this.merchantOrderManager   = merchantOrderManager;
            this.orderSecurity          = orderSecurity;
            this.paymentProviderFactory = paymentProviderFactory;
        }
Ejemplo n.º 16
0
        public void PaymentProviderFactory_CreateAssecoPaymentProvider()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            var provider = paymentProviderFactory.Create(BankNames.FinansBank);

            Assert.IsType <FinansbankPaymentProvider>(provider);
        }
        public void PaymentProviderFactory_CreateProvider_ByBank(int bankId)
        {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            IPaymentProvider       provider = paymentProviderFactory.Create((BankNames)bankId);

            //NestPay
            int[] banks = new[] { 46, 64, 12, 10, 32, 99, 206, 135, 123, 59 };
            if (banks.Contains(bankId))
            {
                Assert.IsType <NestPayPaymentProvider>(provider);
            }

            //InterVPOS
            if (bankId == 134)
            {
                Assert.IsType <DenizbankPaymentProvider>(provider);
            }

            //PayFor
            if (bankId == 111)
            {
                Assert.IsType <FinansbankPaymentProvider>(provider);
            }

            //GVP
            if (bankId == 62)
            {
                Assert.IsType <GarantiPaymentProvider>(provider);
            }

            //KuveytTurk
            if (bankId == 205)
            {
                Assert.IsType <KuveytTurkPaymentProvider>(provider);
            }

            //GET 7/24
            if (bankId == 15)
            {
                Assert.IsType <VakifbankPaymentProvider>(provider);
            }

            //Posnet
            if (bankId == 67 || bankId == 203)
            {
                Assert.IsType <PosnetPaymentProvider>(provider);
            }
        }
        public void PaymentProviderFactory_CreateAssecoPaymentProvider(int bankId)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            var provider = paymentProviderFactory.Create((BankNames)bankId);

            Assert.IsType <NestPayPaymentProvider>(provider);
        }
Ejemplo n.º 19
0
        public void PaymentProviderFactory_CreateYapikrediPaymentProvider(int bankId)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();
            serviceCollection.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            var provider = paymentProviderFactory.Create((Banks)bankId);

            Assert.IsType <YapikrediPaymentProvider>(provider);
        }
        public void PaymentProviderFactory_CreateGarantiPaymentProvider()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();
            serviceCollection.AddHttpContextAccessor();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            var provider = paymentProviderFactory.Create(BankNames.Garanti);

            Assert.IsType <GarantiPaymentProvider>(provider);
        }
Ejemplo n.º 21
0
        public void PaymentProviderFactory_CreatePaymentForm_PaymentUri_ThrowNullException()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            var parameters = new Dictionary <string, object>();

            parameters.Add("test", decimal.Zero);
            Assert.Throws <ArgumentNullException>(() => paymentProviderFactory.CreatePaymentForm(parameters, null));
        }
        public async Task Asseco_GetPaymentParameterResult_UnSuccess()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            var provider             = paymentProviderFactory.Create(BankNames.IsBankasi);
            var paymentGatewayResult = await provider.ThreeDGatewayRequest(null);

            Assert.False(paymentGatewayResult.Success);
        }
Ejemplo n.º 23
0
        public async Task Yapikredi_GetPaymentResult_UnSuccess()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();
            serviceCollection.AddHttpContextAccessor();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            var provider             = paymentProviderFactory.Create(BankNames.Garanti);
            var paymentGatewayResult = await provider.ThreeDGatewayRequest(null);

            Assert.False(paymentGatewayResult.Success);
        }
Ejemplo n.º 24
0
        public CheckoutResult CheckoutWithOnSitePayment(CheckoutOrderInfo checkoutOrderInfo)
        {
            if (!checkoutOrderInfo.RequiresPayment)
            {
                checkoutOrderInfo.PaymentProvider = PaymentProviderName.None;
            }

            CheckoutOrderValidator checkoutOrderValidator = new CheckoutOrderValidator();
            ValidationResult       validationResult       = checkoutOrderValidator.Validate(checkoutOrderInfo);

            if (validationResult.IsValid)
            {
                Order pendingOrder = CreateOrder(checkoutOrderInfo, OrderStatusName.Processing);

                if (checkoutOrderInfo.PaymentProvider != PaymentProviderName.None)
                {
                    PaymentStatusName paymentStatus = pendingOrder.PaymentStatus;
                    if (pendingOrder.PaymentStatus != PaymentStatusName.Completed)
                    {
                        PaymentProvider paymentProcessor = PaymentProviderFactory.GetProvider(checkoutOrderInfo.PaymentProvider, storeContext.CurrentStore);

                        HttpWebResponse response = paymentProcessor.SubmitDirectPaymentRequest(pendingOrder, checkoutOrderInfo.CreditCard);
                        paymentStatus = paymentProcessor.ProcessDirectPaymentResponse(pendingOrder, response);
                    }

                    OrderStatusName orderStatus = (paymentStatus == PaymentStatusName.Completed) ? OrderStatusName.Processing : pendingOrder.OrderStatus;
                    UpdateOrderStatus(pendingOrder, orderStatus, paymentStatus);

                    pendingOrder.Save();
                }
                else
                {
                    // does not require payment (free order / order total == 0)
                    UpdateOrderStatus(pendingOrder, OrderStatusName.Processing, PaymentStatusName.Completed);
                }

                return(DoPostCheckoutProcessing(pendingOrder, true));
            }
            else
            {
                // failed validation
                return(new CheckoutResult()
                {
                    SubmittedOrder = null,
                    Errors = validationResult.Errors.ToList().ConvertAll(e => e.ErrorMessage)
                });
            }
        }
Ejemplo n.º 25
0
        public void PaymentProviderFactory_CreateProvider_ByBank(int bankId)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();
            serviceCollection.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            var serviceProvider        = serviceCollection.BuildServiceProvider();
            var paymentProviderFactory = new PaymentProviderFactory(serviceProvider);
            var provider = paymentProviderFactory.Create((BankNames)bankId);

            var banks = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };

            if (banks.Contains(bankId))
            {
                Assert.IsType <NestPayPaymentProvider>(provider);
            }

            if (bankId == 9)
            {
                Assert.IsType <DenizbankPaymentProvider>(provider);
            }

            if (bankId == 10)
            {
                Assert.IsType <FinansbankPaymentProvider>(provider);
            }

            if (bankId == 11)
            {
                Assert.IsType <GarantiPaymentProvider>(provider);
            }

            if (bankId == 12)
            {
                Assert.IsType <KuveytTurkPaymentProvider>(provider);
            }

            if (bankId == 13)
            {
                Assert.IsType <VakifbankPaymentProvider>(provider);
            }

            if (bankId == 14)
            {
                Assert.IsType <YapikrediPaymentProvider>(provider);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Get the default payment provider
        /// </summary>
        /// <returns></returns>
        public static IPaymentProvider GetDefaultProvider()
        {
            List <PaymentProviderSetting> providerList = GetAllProvidersFromDB(true);

            for (int i = 0; i < providerList.Count; i++)
            {
                PaymentProviderSetting providerSetting = providerList[i];
                if (providerSetting.Active)
                {
                    if (providerSetting.IsDefault)
                    {
                        return(PaymentProviderFactory.CreateProvider(providerSetting.ProviderType, providerSetting.ProviderXML));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 27
0
        public virtual async Task <ActivePaymentViewModel> GetActivePayment(GetActivePaymentParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param), ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param)));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param.CustomerId)), nameof(param.CustomerId));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param.CultureInfo)), nameof(param.CultureInfo));
            }
            if (String.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param.CartName)), nameof(param.CartName));
            }
            if (String.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage(nameof(param.Scope)), nameof(param.Scope));
            }

            var cart = await CartRepository.GetCartAsync(new GetCartParam
            {
                CartName    = param.CartName,
                CustomerId  = param.CustomerId,
                CultureInfo = param.CultureInfo,
                Scope       = param.Scope
            });

            var payment = GetActivePayment(cart);

            if (payment == null)
            {
                return(null);
            }

            return(GetActivePaymentViewModel(new GetActivePaymentViewModelParam
            {
                CultureInfo = param.CultureInfo,
                Cart = cart,
                PaymentProvider = PaymentProviderFactory.ResolveProvider(payment.PaymentMethod.PaymentProviderName),
                IsAuthenticated = param.IsAuthenticated
            }));
        }
        public void PaymentProviderFactory_CreatePaymentForm_PaymentUri_ThrowNullException()
        {
            ServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient();

            ServiceProvider        serviceProvider        = serviceCollection.BuildServiceProvider();
            PaymentProviderFactory paymentProviderFactory = new PaymentProviderFactory(serviceProvider);

            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("test", decimal.Zero);
            parameters.Add("test-1", int.MaxValue);
            parameters.Add("test-2", int.MinValue);
            parameters.Add("test-3", string.Empty);

            Assert.Throws <ArgumentNullException>(() => paymentProviderFactory.CreatePaymentFormHtml(parameters, null));
        }
        private void LoadProviders()
        {
            List <PaymentProviderSetting> allSettings = PaymentProviderManger.GetAllProviders();
            int totalSettings = allSettings.Count;

            for (int i = 0; i < totalSettings; i++)
            {
                PaymentProviderSetting settings = allSettings[i];
                if (settings.Active)
                {
                    IPaymentProvider provider = PaymentProviderFactory.CreateProvider(settings.ProviderType, settings.ProviderXML);
                    _allProviders[settings.ProviderType] = provider;

                    if (settings.IsDefault)
                    {
                        _default = settings.ProviderType;
                    }
                }
            }
        }
        protected virtual List <OrderSummaryPaymentViewModel> GetPaymentViewModels(CreateOrderDetailViewModelParam param)
        {
            var paymentVMs    = new List <OrderSummaryPaymentViewModel>();
            var validPayments = param.Order.Cart.Payments.Where(x => !x.IsVoided()).ToList();
            var payments      = validPayments.Any() ? validPayments : param.Order.Cart.Payments.ToList();

            foreach (var payment in payments)
            {
                OrderSummaryPaymentViewModel model;
                try
                {
                    var paymentProvider = PaymentProviderFactory.ResolveProvider(payment.PaymentMethod.PaymentProviderName);
                    model = paymentProvider.BuildOrderSummaryPaymentViewModel(payment, param.CultureInfo);
                }
                catch (ArgumentException)
                {
                    model = new OrderSummaryPaymentViewModel();
                }

                paymentVMs.Add(model);
            }

            return(paymentVMs);
        }
Ejemplo n.º 31
0
        protected virtual async Task <CheckoutPaymentViewModel> MapCheckoutPaymentViewModel(Overture.ServiceModel.Orders.Cart cart, List <IPaymentMethodViewModel> paymentMethodViewModels, CultureInfo cultureInfo, bool isAuthenticated)
        {
            var payment = GetActivePayment(cart);

            if (payment == null)
            {
                return(null);
            }

            var paymentId = payment.Id;

            ActivePaymentViewModel activePaymentVm = null;

            if (payment.PaymentMethod != null)
            {
                var provider = PaymentProviderFactory.ResolveProvider(payment.PaymentMethod.PaymentProviderName);

                activePaymentVm = GetActivePaymentViewModel(new GetActivePaymentViewModelParam
                {
                    Cart            = cart,
                    CultureInfo     = cultureInfo,
                    PaymentProvider = provider,
                    IsAuthenticated = isAuthenticated
                });

                var activePaymentMethodVm =
                    paymentMethodViewModels.FirstOrDefault(
                        pm =>
                        pm.Id == payment.PaymentMethod.Id &&
                        pm.PaymentProviderName == payment.PaymentMethod.PaymentProviderName &&
                        pm.IsValid);

                if (activePaymentMethodVm != null)
                {
                    activePaymentMethodVm.IsSelected = true;
                }

                // If active payment is set to soemthing that doesn't exists anymore
                // Select the first payment method available...
                if (activePaymentVm != null && activePaymentMethodVm == null)
                {
                    activePaymentVm = await UpdateActivePaymentMethodAsync(new UpdatePaymentMethodParam
                    {
                        CartName            = cart.Name,
                        CultureInfo         = cultureInfo,
                        CustomerId          = cart.CustomerId,
                        IsAuthenticated     = isAuthenticated,
                        Scope               = cart.ScopeId,
                        PaymentId           = activePaymentVm.Id,
                        PaymentMethodId     = paymentMethodViewModels.First().Id,
                        PaymentProviderName = paymentMethodViewModels.First().PaymentProviderName,
                    }).ConfigureAwait(false);

                    paymentId = activePaymentVm.Id;

                    paymentMethodViewModels.First().IsSelected = true;
                }
            }

            var vm = new CheckoutPaymentViewModel
            {
                PaymentId              = paymentId,
                PaymentMethods         = paymentMethodViewModels,
                ActivePaymentViewModel = activePaymentVm
            };

            return(vm);
        }
Ejemplo n.º 32
0
 public OrderCommandHandler(RestaurantDbContext context, PaymentProviderFactory paymentProviders, PaymentGateway paymentGateway)
 {
     this.context          = context;
     this.paymentProviders = paymentProviders;
     this.paymentGateway   = paymentGateway;
 }
Ejemplo n.º 33
0
 protected virtual IPaymentProvider ObtainPaymentProvider(string paymentProviderName)
 {
     return(PaymentProviderFactory.ResolveProvider(paymentProviderName));
 }