protected IReturn <ProcessedCart> BuildAddPaymentRequest(AddPaymentParam param) { return(new AddPaymentRequest { Amount = param.Amount, BillingAddress = param.BillingAddress, CartName = param.CartName, CultureName = param.CultureInfo.Name, CustomerId = param.CustomerId, ScopeId = param.Scope }); }
/// <summary> /// Adds a payment on the first shipment of the specified cart. /// </summary> /// <param name="param">Parameters used to add a payment to the cart.</param> /// <returns></returns> public virtual async Task <ProcessedCart> AddPaymentAsync(AddPaymentParam param) { if (param == null) { throw new ArgumentNullException("param", "param is required"); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("param.CartName is required", "param"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope is required", "param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo is required", "param"); } if (param.CustomerId == Guid.Empty) { throw new ArgumentException("param.CustomerId is required", "param"); } var request = BuildAddPaymentRequest(param); // NOTE (SIMON.BERUBE) : // Not caching the result because of the MyWallet workflow when updating a payment... // When updating a payment we are doing the following OCC requests : // 1. RemovePaymentRequest (in PaymentRepository) // 2. AddPaymentRequest (in CartRepository) // 3. UpdatePaymentMethodRequest (in PaymentRepository) // 4. GetCartRequest (in CartRepository) // // Because PaymentRepository and CartRepository doesn't share the same cache // (CacheProvider is registred as Transient in ComposerHost) if we cache the result of // AddPaymentRequest after, when doing the GetCartRequest, we are getting a cached cart with // no payment method. // // The fix is to register the CacheProvider to be Singleton and let the cache client handle the // lifetime of the cache OR to move the methods that use the BuildCartCacheKey method // from PaymentRepository to CartRepository. return(await OvertureClient.SendAsync(request).ConfigureAwait(false)); }
public async Task WHEN_param_ok_no_shipmentId_SHOULD_call_overture_with_AddPaymentRequest_and_SHOULD_return_ProcessedCart(bool includeBillingAddress) { //Arrange var sut = _container.CreateInstance <CartRepository>(); var billingAddress = includeBillingAddress ? new Address { City = GetRandom.String(7), CountryCode = GetRandom.UpperCaseString(2), RegionCode = GetRandom.Usa.State(), Email = GetRandom.Email(), FirstName = GetRandom.FirstName(), LastName = GetRandom.LastName(), IsPreferredBilling = GetRandom.Boolean(), IsPreferredShipping = GetRandom.Boolean(), Line1 = GetRandom.String(25), PhoneNumber = GetRandom.Usa.PhoneNumber(), PostalCode = GetRandom.String(6) } : null; var param = new AddPaymentParam { Amount = GetRandom.PositiveDecimal(1000.0m), CartName = GetRandom.String(10), BillingAddress = billingAddress, CultureInfo = CultureInfo.InvariantCulture, CustomerId = GetRandom.Guid(), Scope = GetRandom.String(10) }; //Act var cart = await sut.AddPaymentAsync(param); //Assert cart.Should().NotBeNull(); cart.Payments.Should().NotBeNullOrEmpty(); var payment = cart.Payments.First(); payment.BillingAddress.Should().Be(billingAddress); _container.Verify <IOvertureClient>(c => c.SendAsync(It.IsAny <AddPaymentRequest>())); }
public void WHEN_param_CartName_is_invalid_SHOULD_throw_ArgumentException(string cartName) { //Arrange var sut = _container.CreateInstance <CartRepository>(); var param = new AddPaymentParam { Amount = GetRandom.PositiveDecimal(1000.0m), CartName = cartName, CultureInfo = CultureInfo.InvariantCulture, CustomerId = GetRandom.Guid(), Scope = GetRandom.String(7) }; //Act var exception = Assert.ThrowsAsync <ArgumentException>(() => sut.AddPaymentAsync(param)); //Assert exception.ParamName.Should().BeEquivalentTo("param"); exception.Message.Should().ContainEquivalentOf("param.CartName"); }
public void WHEN_param_CartName_is_invalid_SHOULD_throw_ArgumentException(string cartName) { //Arrange var sut = _container.CreateInstance <CartRepository>(); var param = new AddPaymentParam { Amount = GetRandom.PositiveDecimal(1000.0m), CartName = cartName, CultureInfo = CultureInfo.InvariantCulture, CustomerId = GetRandom.Guid(), Scope = GetRandom.String(7) }; //Act Expression <Func <Task <ProcessedCart> > > expression = () => sut.AddPaymentAsync(param); var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke()); //Assert exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name); exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.CartName))); }
public Task <ProcessedCart> AddPaymentAsync(AddPaymentParam param) { throw new NotImplementedException(); }