public virtual async Task <IHttpActionResult> AddVaultProfile(AddVaultProfileViewModel request) { if (request == null) { return(BadRequest("Request body cannot be empty.")); } var addCreditCardParam = new AddCreditCardParam { CardHolderName = request.CardHolderName, CartName = CartConfiguration.ShoppingCartName, CustomerId = ComposerContext.CustomerId, ScopeId = ComposerContext.Scope, PaymentId = request.PaymentId.GetValueOrDefault(), VaultTokenId = request.VaultTokenId, IpAddress = Request.GetClientIp(), CultureInfo = ComposerContext.CultureInfo, CreatePaymentProfile = request.CreatePaymentProfile, PaymentProviderName = request.PaymentProviderName }; var creditCartTrustImage = ImageViewService.GetCheckoutTrustImageViewModel(ComposerContext.CultureInfo); var viewModel = await VaultProfileViewService.AddCreditCardAsync(addCreditCardParam); if (viewModel?.ActivePayment != null) { viewModel.ActivePayment.CreditCardTrustImage = creditCartTrustImage; } return(Ok(viewModel)); }
public void WHEN_param_is_null_SHOULD_throw_ArgumentNullException() { //Arrange var sut = Container.CreateInstance <VaultProfileRepository>(); AddCreditCardParam creditCardParam = null; //Act var ex = Assert.ThrowsAsync <ArgumentNullException>(() => sut.AddCreditCardAsync(creditCardParam)); //Assert ex.Message.Should().ContainEquivalentOf("param"); }
/// <summary> /// Adds the credit card. /// </summary> /// <param name="param">The parameter.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">param</exception> /// <exception cref="System.ArgumentException"> /// CardHolderName may not be null or whitespace.;param /// or /// CartName may not be null or whitespace.;param /// or /// CustomerId may not be an empty guid.;param /// or /// PaymentId may not be an empty guid.;param /// or /// TemporaryToken may not be null or whitespace.;param /// or /// IPAddress may not be null or whitespace.;param /// or /// ScopeId may not be null or whitespace.;param /// </exception> public virtual async Task <VaultProfileCreationResult> AddCreditCardAsync(AddCreditCardParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (string.IsNullOrWhiteSpace(param.CardHolderName)) { throw new ArgumentException("CardHolderName may not be null or whitespace.", nameof(param)); } if (string.IsNullOrWhiteSpace(param.CartName)) { throw new ArgumentException("CartName may not be null or whitespace.", nameof(param)); } if (param.CustomerId.Equals(Guid.Empty)) { throw new ArgumentException("CustomerId may not be an empty guid.", nameof(param)); } if (param.PaymentId.Equals(Guid.Empty)) { throw new ArgumentException("PaymentId may not be an empty guid.", nameof(param)); } if (string.IsNullOrWhiteSpace(param.VaultTokenId)) { throw new ArgumentException("TemporaryToken may not be null or whitespace.", nameof(param)); } if (string.IsNullOrWhiteSpace(param.IpAddress)) { throw new ArgumentException("IPAddress may not be null or whitespace.", nameof(param)); } if (string.IsNullOrWhiteSpace(param.ScopeId)) { throw new ArgumentException("ScopeId may not be null or whitespace.", nameof(param)); } var request = new CreateCartPaymentVaultProfileRequest { CardHolderName = param.CardHolderName, CartName = param.CartName, CustomerId = param.CustomerId, PaymentId = param.PaymentId, TemporaryToken = param.VaultTokenId, IP = param.IpAddress, ScopeId = param.ScopeId, CreatePaymentProfile = param.CreatePaymentProfile }; await CacheProvider.RemoveAsync(BuildPaymentMethodCacheKey(param.ScopeId, param.CartName, param.CustomerId, param.PaymentProviderName)).ConfigureAwait(false); return(await OvertureClient.SendAsync(request)); }
public void WHEN_CustomerId_is_empty_guid_should_throw_argument_exception() { //Arrange var addCreditCardParam = new AddCreditCardParam() { CardHolderName = GetRandom.String(10), CartName = GetRandom.String(10), PaymentId = GetRandom.Guid(), ScopeId = GetRandom.String(32), VaultTokenId = GetRandom.String(32), IpAddress = "127.0.0.1" }; var sut = Container.CreateInstance <VaultProfileRepository>(); //Act var ex = Assert.ThrowsAsync <ArgumentException>(() => sut.AddCreditCardAsync(addCreditCardParam)); //Assert ex.ParamName.Should().ContainEquivalentOf("param"); }
public virtual async Task <MonerisAddVaultProfileViewModel> AddCreditCardAsync(AddCreditCardParam addCreditCardParam) { var model = await VaultProfileRepository.AddCreditCardAsync(addCreditCardParam).ConfigureAwait(false); var vm = MapModelToViewModel(model, addCreditCardParam.CultureInfo); return(vm); }