Exemplo n.º 1
0
        /// <summary>
        /// Builds an instance of <see cref="InitializePaymentParam"/> that will be used to make the request to the repository.
        /// </summary>
        /// <param name="cart">Cart previously retrieved from the UpdatePaymentMethodAsync call.</param>
        /// <param name="updatePaymentMethodParam">Parameters passed to the UpdatePaymentMethodAsync method.</param>
        /// <returns>Instance of the <see cref="InitializePaymentParam"/> that will be used to make the call.</returns>
        /// <remarks>It may be useful to override this method to augment the request with AdditionalData or Options for the request.</remarks>
        protected virtual InitializePaymentParam BuildInitializePaymentParam(Overture.ServiceModel.Orders.Cart cart,
                                                                             UpdatePaymentMethodParam updatePaymentMethodParam)
        {
            var param = new InitializePaymentParam
            {
                CartName    = updatePaymentMethodParam.CartName,
                CultureInfo = updatePaymentMethodParam.CultureInfo,
                CustomerId  = updatePaymentMethodParam.CustomerId,
                PaymentId   = updatePaymentMethodParam.PaymentId,
                Scope       = updatePaymentMethodParam.Scope,
                PaymentType = updatePaymentMethodParam.PaymentType
            };

            return(param);
        }
Exemplo n.º 2
0
        public async Task WHEN_param_ok_SHOULD_call_Overture_InitializePaymentRequest()
        {
            //Arrange
            var param = new InitializePaymentParam()
            {
                CartName    = GetRandom.String(10),
                CultureInfo = CultureInfo.InvariantCulture,
                CustomerId  = GetRandom.Guid(),
                PaymentId   = GetRandom.Guid(),
                Scope       = GetRandom.String(10)
            };

            var sut = _container.CreateInstance <PaymentRepository>();

            //Act
            var cart = await sut.InitializePaymentAsync(param);

            //Assert
            cart.Should().NotBeNull();
            _container.Verify <IOvertureClient>(ov => ov.SendAsync(It.IsNotNull <InitializePaymentRequest>()));
        }
Exemplo n.º 3
0
        public void WHEN_param_PaymentId_is_invalid_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var param = new InitializePaymentParam
            {
                CartName    = GetRandom.String(10),
                CultureInfo = CultureInfo.InvariantCulture,
                CustomerId  = GetRandom.Guid(),
                PaymentId   = Guid.Empty,
                Scope       = GetRandom.String(10)
            };

            var sut = _container.CreateInstance <PaymentRepository>();

            //Act
            var exception = Assert.Throws <ArgumentException>(() => sut.InitializePaymentAsync(param));

            //Assert
            exception.ParamName.Should().BeEquivalentTo("param");
            exception.Message.Should().ContainEquivalentOf("paymentId");
        }
Exemplo n.º 4
0
        public void WHEN_param_CartName_is_invalid_SHOULD_throw_ArgumentException(string cartName)
        {
            //Arrange
            var param = new InitializePaymentParam
            {
                CartName    = cartName,
                CultureInfo = CultureInfo.InvariantCulture,
                CustomerId  = GetRandom.Guid(),
                PaymentId   = GetRandom.Guid(),
                Scope       = GetRandom.String(10)
            };

            var sut = _container.CreateInstance <PaymentRepository>();

            //Act
            Expression <Func <Task <Overture.ServiceModel.Orders.Cart> > > expression = () => sut.InitializePaymentAsync(param);
            var exception = Assert.Throws <ArgumentException>(() => expression.Compile().Invoke());

            //Assert
            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.CartName)));
        }
Exemplo n.º 5
0
 public Task <Overture.ServiceModel.Orders.Cart> InitializePaymentAsync(Overture.ServiceModel.Orders.Cart cart, InitializePaymentParam param)
 {
     return(Task.FromResult(cart));
 }
        /// <summary>
        /// Initializes the payment based on the PaymentProvider logic.
        /// </summary>
        /// <param name="cart">Cart.</param>
        /// <param name="param">Parameters used to make the request.</param>
        /// <returns></returns>
        public Task <Overture.ServiceModel.Orders.Cart> InitializePaymentAsync(Overture.ServiceModel.Orders.Cart cart, InitializePaymentParam param)
        {
            PaymentMethodType paymentMethodType;

            if (!string.IsNullOrWhiteSpace(param.PaymentType) &&
                Enum.TryParse(param.PaymentType, out paymentMethodType))
            {
                if (paymentMethodType == PaymentMethodType.SavedCreditCard)
                {
                    return(Task.FromResult(cart));
                }
            }
            return(PaymentRepository.InitializePaymentAsync(param));
        }
        /// <summary>
        /// Initializes the specified payment in the cart.
        /// </summary>
        /// <param name="param">Parameters used to initialized the Payment.</param>
        /// <returns>The updated processed cart.</returns>
        public virtual Task <Overture.ServiceModel.Orders.Cart> InitializePaymentAsync(InitializePaymentParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (param.PaymentId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.PaymentId)), nameof(param));
            }

            var cacheKey = BuildCartCacheKey(param.Scope, param.CartName, param.CustomerId);

            var request = new InitializePaymentRequest
            {
                AdditionalData = param.AdditionalData == null ? null : new PropertyBag(param.AdditionalData),
                CartName       = param.CartName,
                CultureName    = param.CultureInfo.Name,
                CustomerId     = param.CustomerId,
                Options        = param.Options == null ? null : new PropertyBag(param.Options),
                PaymentId      = param.PaymentId,
                ScopeId        = param.Scope
            };

            return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request)));
        }