示例#1
0
        /// <summary>
        /// Gets the payment options.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <returns>
        /// The manager response where the payment option list is returned in the Result.
        /// </returns>
        public ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> > GetPaymentOptions([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");

            var result = new GetPaymentOptionsResult {
                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 <GetPaymentOptionsResult, IEnumerable <PaymentOption> >(result, null));
            }

            // TODO: CS Connect does not sport passing in a Cart.
            // var request = new GetPaymentOptionsRequest(storefront.ShopName, cart);
            var request = new GetPaymentOptionsRequest(storefront.ShopName);

            result = this.PaymentServiceProvider.GetPaymentOptions(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> >(result, result.PaymentOptions.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]);
        }
        public void GetBillingInfo_IfGetPaymentOptionsFailed_ShouldReturnsError(
            CartResult cartResult,
            GetPaymentOptionsResult optionsResult,
            SystemMessage systemMessage)
        {
            //arrange
            cartResult.Success = true;
            this.cartManager.LoadCart(Arg.Any <string>(), Arg.Any <string>()).Returns(cartResult);

            optionsResult.Success = false;
            optionsResult.SystemMessages.Add(systemMessage);
            this.paymentManager.GetPaymentOptions(Arg.Any <string>(), Arg.Any <Cart>()).Returns(optionsResult);

            //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]);
        }
示例#4
0
        public ManagerResponse <GetPaymentOptionsResult, IEnumerable <Entities.Payments.PaymentOption> > GetPaymentOptions(string shopName, Cart cart)
        {
            var request = new GetPaymentOptionsRequest(shopName, cart);
            GetPaymentOptionsResult paymentOptions = this.paymentServiceProvider.GetPaymentOptions(request);

            return(new ManagerResponse <GetPaymentOptionsResult, IEnumerable <Entities.Payments.PaymentOption> >(paymentOptions, paymentOptions.PaymentOptions.ToList()));
        }
示例#5
0
        public ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> > GetPaymentOptions(string userId)
        {
            var result = new GetPaymentOptionsResult {
                Success = false
            };
            var cartResult = CartManager.GetCart(userId);

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

            if (StorefrontContext.Current == null)
            {
                throw new InvalidOperationException("Cannot be called without a valid storefront context.");
            }
            var request = new GetPaymentOptionsRequest(StorefrontContext.Current.ShopName, cartResult.Result);

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

            return(new ManagerResponse <GetPaymentOptionsResult, IEnumerable <PaymentOption> >(result, result.PaymentOptions.ToList()));
        }
示例#6
0
        /// <summary>
        /// Translateoes the type of the payment option.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="result">The result.</param>
        /// <returns>The full PaymentOptionType.</returns>
        protected virtual PaymentOptionType TranslatePaymentOptionType(int value, GetPaymentOptionsResult result)
        {
            PaymentOptionType returnValue;

            switch (value)
            {
            case 0:
                returnValue = PaymentOptionType.None;
                break;

            case 1:
                returnValue = PaymentOptionType.PayCard;
                break;

            case 2:
                returnValue = PaymentOptionType.PayLoyaltyCard;
                break;

            case 3:
                returnValue = PaymentOptionType.PayGiftCard;
                break;

            default:
                returnValue = PaymentOptionType.None;
                string errorMessage = String.Format(CultureInfo.InvariantCulture, "The given PaymentOptionType value is unsupported: {0}", value);
                result.SystemMessages.Add(new SystemMessage()
                {
                    Message = errorMessage
                });
                result.Success = false;
                CommerceLog.Current.Error(errorMessage, this);
                break;
            }

            return(returnValue);
        }
        /// <summary>
        /// Translates to payment option.
        /// </summary>
        /// <param name="paymentOptionItem">The payment option item.</param>
        /// <param name="paymentOption">The payment option.</param>
        /// <param name="result">The result.</param>
        protected virtual void TranslateToPaymentOption(Item paymentOptionItem, PaymentOption paymentOption, GetPaymentOptionsResult result)
        {
            paymentOption.ExternalId = paymentOptionItem.ID.Guid.ToString();
            paymentOption.Name = paymentOptionItem.DisplayName;
            paymentOption.ShopName = this.GetShopName();

            int enumValue = MainUtil.GetInt(paymentOptionItem[CommerceServerStorefrontConstants.KnownFieldNames.PaymentOptionValue], 0);
            paymentOption.PaymentOptionType = this.TranslatePaymentOptionType(enumValue, result);
        }
        /// <summary>
        /// Translateoes the type of the payment option.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="result">The result.</param>
        /// <returns>The full PaymentOptionType.</returns>
        protected virtual PaymentOptionType TranslatePaymentOptionType(int value, GetPaymentOptionsResult result)
        {
            PaymentOptionType returnValue;

            switch (value)
            {
                case 0:
                    returnValue = PaymentOptionType.None;
                    break;

                case 1:
                    returnValue = PaymentOptionType.PayCard;
                    break;

                case 2:
                    returnValue = PaymentOptionType.PayLoyaltyCard;
                    break;

                case 3:
                    returnValue = PaymentOptionType.PayGiftCard;
                    break;

                default:
                    returnValue = PaymentOptionType.None;
                    string errorMessage = String.Format(CultureInfo.InvariantCulture, "The given PaymentOptionType value is unsupported: {0}", value);
                    result.SystemMessages.Add(new SystemMessage() { Message = errorMessage });
                    result.Success = false;
                    CommerceLog.Current.Error(errorMessage, this);
                    break;
            }

            return returnValue;
        }
示例#9
0
        /// <summary>
        /// Translates to payment option.
        /// </summary>
        /// <param name="paymentOptionItem">The payment option item.</param>
        /// <param name="paymentOption">The payment option.</param>
        /// <param name="result">The result.</param>
        protected virtual void TranslateToPaymentOption(Item paymentOptionItem, PaymentOption paymentOption, GetPaymentOptionsResult result)
        {
            paymentOption.ExternalId = paymentOptionItem.ID.Guid.ToString();
            paymentOption.Name       = paymentOptionItem.DisplayName;
            paymentOption.ShopName   = this.GetShopName();

            int enumValue = MainUtil.GetInt(paymentOptionItem[CommerceServerStorefrontConstants.KnownFieldNames.PaymentOptionValue], 0);

            paymentOption.PaymentOptionType = this.TranslatePaymentOptionType(enumValue, result);
        }
        /// <summary>
        /// Translates to payment option.
        /// </summary>
        /// <param name="paymentOptionItem">The payment option item.</param>
        /// <param name="paymentOption">The payment option.</param>
        /// <param name="result">The result.</param>
        protected virtual void TranslateToPaymentOption(Item paymentOptionItem, PaymentOption paymentOption, GetPaymentOptionsResult result)
        {
            paymentOption.ExternalId  = paymentOptionItem.ID.Guid.ToString();
            paymentOption.Name        = paymentOptionItem.DisplayName;
            paymentOption.Description = paymentOptionItem.DisplayName;
            paymentOption.ShopName    = this.GetShopName();

            var paymentOptionTypeId = paymentOptionItem[Sitecore.Commerce.Constants.Templates.PaymentOption.Fields.PaymentOptionType];

            var paymentOptionTypeItem = Sitecore.Context.Database.GetItem(paymentOptionTypeId);

            Assert.IsNotNull(paymentOptionTypeItem, string.Format(CultureInfo.InvariantCulture, "The Payment Option Type is undefined in Sitecore.  ID: {0}", paymentOptionTypeId));

            int enumValue = MainUtil.GetInt(paymentOptionTypeItem[CommerceServerStorefrontConstants.KnownFieldNames.TypeId], 0);

            paymentOption.PaymentOptionType = this.TranslatePaymentOptionType(enumValue, result);
        }
        /// <summary>
        /// Gets the payment options.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <returns>
        /// The manager response where the payment option list is returned in the Result.
        /// </returns>
        public ManagerResponse<GetPaymentOptionsResult, IEnumerable<PaymentOption>> GetPaymentOptions([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");

            var result = new GetPaymentOptionsResult { 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<GetPaymentOptionsResult, IEnumerable<PaymentOption>>(result, null);
            }

            var request = new GetPaymentOptionsRequest(storefront.ShopName, cartResult.Result);
            result = this.PaymentServiceProvider.GetPaymentOptions(request);

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

            return new ManagerResponse<GetPaymentOptionsResult, IEnumerable<PaymentOption>>(result, result.PaymentOptions.ToList());
        }