public static ExternalTaxRateDraftBuilder ofSubRates(final List<SubRate> subRates, final String name, final CountryCode country) { return new ExternalTaxRateDraftBuilder(name, country).subRates(subRates); }
public static ExternalTaxRateDraftBuilder ofAmount(final Double amount, final String name, final CountryCode country) { return new ExternalTaxRateDraftBuilder(name, country).amount(amount); }
@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; }); }
@Test public void addLineItemOnPlatformCart() { withProductOfPrices(client(), singletonList(PriceDraft.of(EURO_10)), (Product product) -> { final CartDraft draft = CartDraft.of(EUR);//uses by default platform! withCartDraft(client(), draft, (Cart cart) -> { final int quantity = 3; final int variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final String taxRateName = "special tax"; final double taxRate = 0.20; final List<SubRate> subRates = asList(SubRate.of("foo", 0.11), SubRate.of("bar", 0.09)); final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE) .subRates(subRates) .build(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity) .withExternalTaxRate(externalTaxRate); final Throwable throwable = catchThrowable(() -> client().executeBlocking(CartUpdateCommand.of(cart, updateAction))); //the error message is sth. like "Cannot set an external tax rate on a cart with taxMode 'Platform'." assertThat(throwable).isInstanceOf(ErrorResponseException.class); return cart; }); }); }
@Test public void setLineItemTaxAmount() throws Exception { withFilledCartWithTaxMode(client(), TaxMode.EXTERNAL_AMOUNT, cart -> { final LineItem originalLineItem = cart.getLineItems().get(0); final ExternalTaxRateDraft taxRate = ExternalTaxRateDraftBuilder .ofAmount(1.0, "Test Tax", CountryCode.DE) .build(); final MonetaryAmount totalGross = MoneyImpl.ofCents(1000, EUR); final ExternalTaxAmountDraftDsl taxAmountDraft = ExternalTaxAmountDraftBuilder .of(totalGross, taxRate) .build(); final SetLineItemTaxAmount setLineItemTaxAmount = SetLineItemTaxAmount.of(originalLineItem.getId(), taxAmountDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, setLineItemTaxAmount)); final LineItem updatedLineItem = updatedCart.getLineItems().get(0); assertThat(updatedLineItem.getTaxedPrice().getTotalGross()).isEqualTo(totalGross); }); }
final List<SubRate> subRates = asList(SubRate.of("foo", 0.11), SubRate.of("bar", 0.09)); final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(rate, taxRateName, DE) .subRates(subRates) .build(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity) .withExternalTaxRate(externalTaxRate);
@Test public void setCustomLineItemTaxAmount() throws Exception { withCustomLineItemFilledCartWithTaxMode(client(), TaxMode.EXTERNAL_AMOUNT, cart -> { final CustomLineItem originalCustomLineItem = cart.getCustomLineItems().get(0); final ExternalTaxRateDraft taxRate = ExternalTaxRateDraftBuilder .ofAmount(1.0, "Test Tax", CountryCode.DE) .build(); final MonetaryAmount totalGross = MoneyImpl.ofCents(1000, EUR); final ExternalTaxAmountDraftDsl taxAmountDraft = ExternalTaxAmountDraftBuilder .of(totalGross, taxRate) .build(); final SetCustomLineItemTaxAmount setCustomLineItemTaxAmount = SetCustomLineItemTaxAmount.of(originalCustomLineItem.getId(), taxAmountDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, setCustomLineItemTaxAmount)); final CustomLineItem updatedCustomLineItem = updatedCart.getCustomLineItems().get(0); assertThat(updatedCustomLineItem.getTaxedPrice().getTotalGross()).isEqualTo(totalGross); return updatedCart; }); }
final List<SubRate> subRates = asList(SubRate.of("foo", 0.11), SubRate.of("bar", 0.09)); final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(rate, taxRateName, DE) .subRates(subRates) .build(); final AddLineItem updateAction = AddLineItem.of(product, variantId, quantity) .withExternalTaxRate(externalTaxRate);
public static ExternalTaxRateDraftBuilder ofSubRates(final List<SubRate> subRates, final String name, final CountryCode country) { return new ExternalTaxRateDraftBuilder(name, country).subRates(subRates); }
public static ExternalTaxRateDraftBuilder ofAmount(final Double amount, final String name, final CountryCode country) { return new ExternalTaxRateDraftBuilder(name, country).amount(amount); }
@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; }); }
final Channel distributionChannel = ChannelFixtures.persistentChannelOfRole(client(), ChannelRole.PRODUCT_DISTRIBUTION); final MonetaryAmount externalPrice = EURO_1; final ExternalTaxRateDraft externalTaxRate = ExternalTaxRateDraftBuilder.ofAmount(1.2, "tax rate name", CountryCode.AU).build(); final ExternalLineItemTotalPrice externalTotalPrice = ExternalLineItemTotalPrice.ofPriceAndTotalPrice(EURO_5, EURO_15); final String sku = "sku";
@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; }); }); }
@Test public void setShippingMethodTaxAmount() throws Exception { withShippingMethodForGermany(client(), shippingMethod -> { withCustomLineItemFilledCartWithTaxMode(client(), TaxMode.EXTERNAL_AMOUNT, cart -> { final Cart cartWithShippingMethod = client().executeBlocking(CartUpdateCommand.of(cart, SetShippingMethod.of(shippingMethod))); assertThat(cartWithShippingMethod.getShippingInfo()).isNotNull(); assertThat(cartWithShippingMethod.getShippingInfo().getTaxedPrice()).isNull(); final ExternalTaxRateDraft taxRate = ExternalTaxRateDraftBuilder .ofAmount(1.0, "Test Tax", CountryCode.DE) .build(); final MonetaryAmount totalGross = MoneyImpl.ofCents(100000, EUR); final ExternalTaxAmountDraftDsl taxAmountDraft = ExternalTaxAmountDraftBuilder .of(totalGross, taxRate) .build(); final SetShippingMethodTaxAmount setShippingMethodTaxAmount = SetShippingMethodTaxAmount.of(taxAmountDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cartWithShippingMethod, setShippingMethodTaxAmount)); final TaxedItemPrice taxedPrice = updatedCart.getShippingInfo().getTaxedPrice(); assertThat(taxedPrice.getTotalGross()).isEqualTo(totalGross); return updatedCart; }); }); }