public final class SetCustomLineItemTaxRate extends UpdateActionImpl<Cart>
TaxMode.EXTERNAL
.
See also CartInStoreUpdateCommand.
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 CustomLineItemDraft item = CustomLineItemDraft.ofExternalTaxCalculation(name, slug, money, quantity);
final Cart cartWithCustomLineItem = client().executeBlocking(CartUpdateCommand.of(cart, AddCustomLineItem.of(item)));
assertThat(cartWithCustomLineItem.getCustomLineItems()).hasSize(1);
final CustomLineItem customLineItem = cartWithCustomLineItem.getCustomLineItems().get(0);
assertThat(customLineItem.getTaxCategory()).isNull();
assertThat(customLineItem.getTaxedPrice()).isNull();
assertThat(customLineItem.getTaxRate())
.as("custom line item does not have tax information yet")
.isNull();
final String taxRateName = "special tax";
final double taxRate = 0.20;
final ExternalTaxRateDraft externalTaxRate =
ExternalTaxRateDraftBuilder.ofAmount(taxRate, taxRateName, DE).build();
final SetCustomLineItemTaxRate updateAction = SetCustomLineItemTaxRate.of(customLineItem.getId(), externalTaxRate);
final Cart cartWithTaxedLineItem = client().executeBlocking(CartUpdateCommand.of(cartWithCustomLineItem, updateAction));
final CustomLineItem taxedCustomLineItem = cartWithTaxedLineItem.getCustomLineItems().get(0);
assertThat(taxedCustomLineItem.getTaxCategory()).isNull();
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);
return cartWithTaxedLineItem;
});
See the test code.
Modifier and Type | Method and Description |
---|---|
String |
getCustomLineItemId() |
ExternalTaxRateDraft |
getExternalTaxRate() |
static SetCustomLineItemTaxRate |
of(String customLineItemId,
ExternalTaxRateDraft externalTaxRate) |
getAction
public static SetCustomLineItemTaxRate of(String customLineItemId, @Nullable ExternalTaxRateDraft externalTaxRate)
@Nullable public ExternalTaxRateDraft getExternalTaxRate()
public String getCustomLineItemId()