public static TaxRateDraftBuilder of(final TaxRate taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .state(taxRate.getState()) .subRates(taxRate.getSubRates()); }
public static TaxRateBuilder of(final TaxRate taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .id(taxRate.getId()) .state(taxRate.getState()); }
public static TaxRateDraftBuilder of(final TaxRate taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .state(taxRate.getState()) .subRates(taxRate.getSubRates()); }
@Test public void addTaxRate() { withUpdateableTaxCategory(client(), taxCategory -> { //add tax rate final String name = "ag7"; final CountryCode countryCode = CountryCode.AG; final TaxRateDraft de7 = TaxRateDraftBuilder.of(name, 0.07, true, countryCode).build(); final TaxCategory taxCategoryWithTaRate = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategory, AddTaxRate.of(de7))); final TaxRate actual = taxCategoryWithTaRate.getTaxRates().stream().filter(rate -> name.equals(rate.getName())).findFirst().get(); assertThat(actual.getCountry()).isEqualTo(countryCode); assertThat(actual.getAmount()).isEqualTo(0.07); assertThat(actual.getId()) .overridingErrorMessage("the tax rate fetched from API has an id") .isNotNull(); assertThat(actual.getName()).isEqualTo(de7.getName()); //remove tax rate final TaxCategory updatedTaxCategory = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategoryWithTaRate, RemoveTaxRate.of(actual.getId()))); assertThat(updatedTaxCategory.getTaxRates()).matches(rates -> !rates.stream().anyMatch(rate -> name.equals(rate.getName()))); return updatedTaxCategory; }); }
@Test public void replaceTaxRate() { withUpdateableTaxCategory(client(), taxCategory -> { final TaxRate old = taxCategory.getTaxRates().get(0); final double newAmount = old.getAmount() * 2; final TaxRateDraft newTaxRate = TaxRateDraftBuilder.of(old).amount(newAmount).build(); final TaxCategory updatedTaxCategory = client().executeBlocking(TaxCategoryUpdateCommand.of(taxCategory, ReplaceTaxRate.of(old.getId(), newTaxRate))); final TaxRate actual = updatedTaxCategory.getTaxRates().get(0); assertThat(actual.getCountry()).isEqualTo(old.getCountry()); assertThat(actual.getAmount()).isEqualTo(newAmount); assertThat(actual.getName()).isEqualTo(old.getName()); return updatedTaxCategory; }); } }
assertThat(lineItem.getVariant().getPrices().get(0).getValue()).isEqualTo(EURO_20); assertThat(lineItem.getVariant().getAttribute("foo").getValue(AttributeAccess.ofString())).isEqualTo("bar"); assertThat(lineItem.getTaxRate().getName()).isEqualTo("default-tax"); assertThat(lineItem.getTaxRate().isIncludedInPrice()).isTrue(); assertThat(lineItem.getTaxRate().getCountry()).isEqualTo(CountryCode.DE);
@Test public void addCustomShippingMethod() { final CartDraft draft = CartDraft.of(EUR) .withTaxMode(TaxMode.EXTERNAL) .withShippingAddress(Address.of(DE)); withCartDraft(client(), draft, (Cart cart) -> { final String taxRateName = "special tax"; final double taxRate = 0.20; final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).build(); final ShippingRate shippingRate = ShippingRate.of(EURO_10,null, Collections.emptyList()); final SetCustomShippingMethod action = SetCustomShippingMethod.ofExternalTaxCalculation("name", shippingRate, externalTaxRate); final Cart cartWithShippingMethod = client().executeBlocking(CartUpdateCommand.of(cart, action)); final CartShippingInfo shippingInfo = cartWithShippingMethod.getShippingInfo(); assertThat(shippingInfo).isNotNull(); assertThat(shippingInfo.getShippingRate()).isEqualTo(shippingRate); assertThat(shippingInfo.getTaxCategory()).isNull(); assertThat(shippingInfo.getTaxedPrice().getTotalNet()).isEqualTo(EURO_10); assertThat(shippingInfo.getTaxedPrice().getTotalGross()).isEqualTo(EURO_12); assertThat(shippingInfo.getTaxRate().getName()).isEqualTo(taxRateName); return cartWithShippingMethod; }); }
assertThat(taxedShippingInfo.getTaxedPrice().getTotalNet()).isEqualTo(EURO_10); assertThat(taxedShippingInfo.getTaxedPrice().getTotalGross()).isEqualTo(EURO_12); assertThat(taxedShippingInfo.getTaxRate().getName()).isEqualTo(taxRateName);
@Test public void addCustomLineItem() { final CartDraft draft = CartDraft.of(EUR) .withTaxMode(TaxMode.EXTERNAL) .withShippingAddress(Address.of(DE)); withCartDraft(client(), draft, (Cart cart) -> { final MonetaryAmount money = MoneyImpl.of("23.50", EUR); final String slug = "thing-slug"; final LocalizedString name = en("thing"); final long quantity = 5; final String taxRateName = "special tax"; final double taxRate = 0.20; final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).build(); final CustomLineItemDraft item = CustomLineItemDraft.ofExternalTaxCalculation(name, slug, money, externalTaxRate, quantity); final Cart cartWithCustomLineItems = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(item))); assertThat(cartWithCustomLineItems.getCustomLineItems()).hasSize(1); final CustomLineItem customLineItem = cartWithCustomLineItems.getCustomLineItems().get(0); assertThat(customLineItem.getTaxCategory()).isNull(); assertThat(customLineItem.getTaxedPrice().getTotalNet()).isEqualTo(MoneyImpl.of("117.50", EUR)); assertThat(customLineItem.getTaxedPrice().getTotalGross()).isEqualTo(MoneyImpl.of("141.00", EUR)); assertThat(customLineItem.getTaxRate().getName()).isEqualTo(taxRateName); return cartWithCustomLineItems; }); }
@Test public void setLineItemTaxRate() { withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_10)), (Product product) -> { final CartDraft draft = CartDraft.of(EUR).withTaxMode(TaxMode.EXTERNAL); withCartDraft(client(), draft, (Cart cart) -> { final int quantity = 3; final int variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity); final Cart cartWithLineItem = client().executeBlocking(CartUpdateCommand.of(cart, updateAction)); final LineItem lineItem = cartWithLineItem.getLineItems().get(0); assertThat(lineItem.getTaxRate()).isNull(); assertThat(lineItem.getTotalPrice()).isEqualTo(EURO_30); assertThat(lineItem.getTaxedPrice()).isNull(); //now add the taxes final String taxRateName = "special tax"; final double taxRate = 0.20; final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).build(); final SetLineItemTaxRate setLineItemTaxRate = SetLineItemTaxRate.of(lineItem.getId(), externalTaxRate); final Cart cartWithTaxedLineItem = client().executeBlocking(CartUpdateCommand.of(cartWithLineItem, setLineItemTaxRate)); final LineItem taxedLineItem = cartWithTaxedLineItem.getLineItems().get(0); assertThat(taxedLineItem.getTaxRate().getName()).isEqualTo(taxRateName); assertThat(taxedLineItem.getTotalPrice()).isEqualTo(EURO_30); assertThat(taxedLineItem.getTaxedPrice().getTotalGross()).isEqualTo(EURO_36); assertThat(taxedLineItem.getTaxedPrice().getTotalNet()).isEqualTo(EURO_30); return cartWithTaxedLineItem; }); }); }
assertThat(taxRate.getCountry()).isEqualTo(DE); assertThat(taxRate.getId()).isNull(); assertThat(taxRate.getName()).isEqualTo(taxRateName); assertThat(taxRate.getAmount()).isEqualTo(0.2); assertThat(taxRate.isIncludedInPrice()).isFalse();
assertThat(taxedCustomLineItem.getTaxedPrice().getTotalNet()).isEqualTo(MoneyImpl.of("117.50", EUR)); assertThat(taxedCustomLineItem.getTaxedPrice().getTotalGross()).isEqualTo(MoneyImpl.of("141.00", EUR)); assertThat(taxedCustomLineItem.getTaxRate().getName()).isEqualTo(taxRateName);
assertThat(taxRate.getName()).isEqualTo(taxRateName);
s.assertThat(taxRate.getName()).isEqualTo(taxRateName); s.assertThat(taxRate.getAmount()).isEqualTo(rate); s.assertThat(taxRate.getCountry()).isEqualTo(DE);
@Test public void shippingMethodQuery() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCart(client(), createCartWithShippingAddress(client()), cart -> { final CartUpdateCommand updateCommand = CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod)) .plusExpansionPaths(m -> m.shippingInfo().shippingMethod().taxCategory()) .plusExpansionPaths(m -> m.shippingInfo().taxCategory()); final Cart cartWithShippingMethod = client().executeBlocking(updateCommand); final CartShippingInfo shippingInfo = cartWithShippingMethod.getShippingInfo(); final CartQuery query = CartQuery.of() .plusPredicates(m -> m.id().is(cart.getId())) .plusPredicates(m -> m.shippingInfo().shippingMethodName().is(shippingMethod.getName())) .plusPredicates(m -> m.shippingInfo().price().centAmount().is(MoneyImpl.centAmountOf(shippingInfo.getPrice()))) .plusPredicates(m -> m.shippingInfo().taxRate().name().is(shippingInfo.getTaxRate().getName())) .plusPredicates(m -> m.shippingInfo().taxRate().includedInPrice().is(shippingInfo.getTaxRate().isIncludedInPrice())) .plusPredicates(m -> m.shippingInfo().taxRate().country().is(shippingInfo.getTaxRate().getCountry())) .plusPredicates(m -> m.shippingInfo().shippingMethod().is(shippingMethod)) .plusPredicates(m -> m.shippingInfo().discountedPrice().isNotPresent()); assertThat(client().executeBlocking(query).head().get()).isEqualTo(cartWithShippingMethod); return cartWithShippingMethod; }); }); }