public final class SetShippingMethodTaxRate extends UpdateActionImpl<Cart>
See also CartInStoreUpdateCommand.
final CartDraft draft = CartDraft.of(EUR)
.withTaxMode(TaxMode.EXTERNAL)
.withShippingAddress(Address.of(DE));
withCartDraft(client(), draft, (Cart cart) -> {
final ShippingRate shippingRate = ShippingRate.of(EURO_10,null, Collections.emptyList());
final SetCustomShippingMethod action =
SetCustomShippingMethod.ofExternalTaxCalculation("name", shippingRate);
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()).isNull();
assertThat(shippingInfo.getTaxRate()).isNull();
final String taxRateName = "special tax";
final double taxRate = 0.20;
final ExternalTaxRateDraft externalTaxRate =
ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).build();
final CartUpdateCommand cmd =
CartUpdateCommand.of(cartWithShippingMethod, SetShippingMethodTaxRate.of(externalTaxRate));
final Cart cartWithTaxedShippingMethod = client().executeBlocking(cmd);
final CartShippingInfo taxedShippingInfo = cartWithTaxedShippingMethod.getShippingInfo();
assertThat(taxedShippingInfo).isNotNull();
assertThat(taxedShippingInfo.getShippingRate()).isEqualTo(shippingRate);
assertThat(taxedShippingInfo.getTaxCategory()).isNull();
assertThat(taxedShippingInfo.getTaxedPrice().getTotalNet()).isEqualTo(EURO_10);
assertThat(taxedShippingInfo.getTaxedPrice().getTotalGross()).isEqualTo(EURO_12);
assertThat(taxedShippingInfo.getTaxRate().getName()).isEqualTo(taxRateName);
return cartWithTaxedShippingMethod;
});
See the test code.
Modifier and Type | Method and Description |
---|---|
ExternalTaxRateDraft |
getExternalTaxRate() |
static SetShippingMethodTaxRate |
of(ExternalTaxRateDraft externalTaxRate) |
getAction
public static SetShippingMethodTaxRate of(@Nullable ExternalTaxRateDraft externalTaxRate)
@Nullable public ExternalTaxRateDraft getExternalTaxRate()