/// <summary>
        /// Gets the payment methods.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="paymentOption">The payment option.</param>
        /// <returns>The manager response where the payment method list is returned in the Result.</returns>
        public ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> > GetPaymentMethods([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, PaymentOption paymentOption)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNull(paymentOption, "paymentOption");

            var result = new GetPaymentMethodsResult {
                Success = false
            };
            var cartResult = this.CartManager.GetCurrentCart(storefront, visitorContext);

            if (!cartResult.ServiceProviderResult.Success || cartResult.Result == null)
            {
                result.SystemMessages.ToList().AddRange(cartResult.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >(result, null));
            }

            var request = new Sitecore.Commerce.Engine.Connect.Services.Payments.GetPaymentMethodsRequest(cartResult.Result, paymentOption);

            result = this.PaymentServiceProvider.GetPaymentMethods(request);

            if (!result.Success)
            {
                Helpers.LogSystemMessages(result.SystemMessages, result);
            }

            return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >(result, result.PaymentMethods.ToList()));
        }
        public void GetBillingInfo_IfGetPaymentMethodsFailed_ShouldReturnsError(
            CartResult cartResult,
            GetPaymentOptionsResult optionsResult,
            GetPaymentMethodsResult methodsResult,
            SystemMessage systemMessage,
            List <Models.Entities.Payment.PaymentOption> mappedPaymentOptions)
        {
            //arrange
            cartResult.Success = true;
            this.cartManager.LoadCart(Arg.Any <string>(), Arg.Any <string>()).Returns(cartResult);

            optionsResult.Success = true;
            this.paymentManager.GetPaymentOptions(Arg.Any <string>(), Arg.Any <Cart>()).Returns(optionsResult);

            methodsResult.Success = false;
            methodsResult.SystemMessages.Add(systemMessage);
            this.paymentManager.GetPaymentMethods(Arg.Any <Cart>(), Arg.Any <PaymentOption>()).Returns(methodsResult);

            this.paymentMapper.Map <IReadOnlyCollection <PaymentOption>, List <Models.Entities.Payment.PaymentOption> >(optionsResult.PaymentOptions)
            .Returns(mappedPaymentOptions);

            //act
            Result <BillingInfo> result;

            using (new SiteContextSwitcher(this.siteContext))
            {
                result = this.billingService.GetBillingInfo();
            }

            //assert
            Assert.False(result.Success);
            Assert.Equal(systemMessage.Message, result.Errors[0]);
        }
Esempio n. 3
0
        public ManagerResponse <GetPaymentMethodsResult, IEnumerable <Entities.Payments.PaymentMethod> > GetPaymentMethods(Cart cart, Entities.Payments.PaymentOption paymentOption)
        {
            var request = new Services.Payments.GetPaymentMethodsRequest(cart as CommerceCart, paymentOption);

            GetPaymentMethodsResult paymentMethods = this.paymentServiceProvider.GetPaymentMethods(request);

            return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <Entities.Payments.PaymentMethod> >(paymentMethods, paymentMethods.PaymentMethods.ToList()));
        }
Esempio n. 4
0
        public ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> > GetPaymentMethods(string userId, PaymentOption paymentOption)
        {
            Assert.ArgumentNotNull(paymentOption, nameof(paymentOption));

            var result = new GetPaymentMethodsResult {
                Success = false
            };
            var cartResult = CartManager.GetCart(userId);

            if (!cartResult.ServiceProviderResult.Success || cartResult.Result == null)
            {
                result.SystemMessages.ToList().AddRange(cartResult.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >(result, null));
            }

            var request = new GetPaymentMethodsRequest(cartResult.Result, paymentOption);

            result = PaymentServiceProvider.GetPaymentMethods(request);
            result.WriteToSitecoreLog();

            return(new ManagerResponse <GetPaymentMethodsResult, IEnumerable <PaymentMethod> >(result, result.PaymentMethods.ToList()));
        }
Esempio n. 5
0
        public void ShouldGetPaymentMethodsByPaymentOption()
        {
            var request = new GetPaymentMethodsRequest(new PaymentOption()
            {
                ShopName          = "My Store",
                PaymentOptionType = PaymentOptionType.PayCard
            });

            var result = new GetPaymentMethodsResult();
            var args   = new ServicePipelineArgs(request, result);

            _client.GetPaymentMethods(request.PaymentOption.ShopName).Returns(new ResponseModelOfArrayOfPaymentMethodModelQBnDdvBq()
            {
                Success = true,
                Result  = new []
                {
                    new PaymentMethodModel()
                    {
                        MethodName = "Credit Card",
                        ShopName   = "My Store",
                        SystemName = "Payments.Manual"
                    },
                    new PaymentMethodModel()
                    {
                        MethodName = "Credit Card",
                        ShopName   = "My Store",
                        SystemName = "Payments.AuthorizeNet"
                    },
                }
            });


            var xml      = new XmlDocument();
            var rootNode = xml.CreateElement("map");

            xml.AppendChild(rootNode);

            var shippingOptionValue = xml.CreateAttribute("paymentOptionValue");
            var systemName          = xml.CreateAttribute("systemName");
            var methodName          = xml.CreateAttribute("methodName");

            shippingOptionValue.Value = "1";
            systemName.Value          = "Payments.Manual";
            methodName.Value          = "Credit Card";

            rootNode.Attributes.Append(shippingOptionValue);
            rootNode.Attributes.Append(systemName);
            rootNode.Attributes.Append(methodName);

            _processor.Map(rootNode);

            shippingOptionValue.Value = "1";
            systemName.Value          = "Payments.AuthorizeNet";
            methodName.Value          = "Credit Card";

            _processor.Map(rootNode);

            _processor.Process(args);

            result.Should().NotBeNull();
            result.Success.Should().BeTrue();
            result.PaymentMethods.Should().HaveCount(2);
            result.PaymentMethods.ElementAt(0).ExternalId.Should().Be("Payments.Manual");
            result.PaymentMethods.ElementAt(0).Name.Should().Be("Credit Card");
            result.PaymentMethods.ElementAt(1).ExternalId.Should().Be("Payments.AuthorizeNet");
            result.PaymentMethods.ElementAt(1).Name.Should().Be("Credit Card");
        }