static TaxCategoryDraft of(final String name, final List<TaxRateDraft> taxRates) { return of(name, taxRates, null); } }
static TaxCategoryDraft of(final String name, final List<TaxRateDraft> taxRates) { return of(name, taxRates, null); } }
public static TaxCategoryDraft of(final String name, final List<TaxRate> taxRates) { return of(name, taxRates, null); }
public static TaxCategoryDraft of(final String name, final String description, final List<TaxRate> taxRates) { return of(name, Optional.ofNullable(description), taxRates); }
public static TaxCategoryDraft of(final String name, final List<TaxRate> taxRates) { return of(name, Optional.empty(), taxRates); }
public static TaxCategoryDraft of(final String name, final List<TaxRate> taxRates) { return of(name, Optional.empty(), taxRates); }
public static TaxCategoryDraft of(final String name, final String description, final List<TaxRate> taxRates) { return of(name, Optional.ofNullable(description), taxRates); }
public static void withTaxCategory(final BlockingSphereClient client, final String name, final Consumer<TaxCategory> user) { final TaxCategoryDraft de19 = TaxCategoryDraft.of(name, singletonList(TaxRateDraftBuilder.of("de19", 0.19, true, CountryCode.DE).build())); withTaxCategory(client, de19, user); }
public static TaxCategory defaultTaxCategory(final BlockingSphereClient client) { final String name = "sdk-default-tax-cat-1"; final TaxCategoryDraft categoryDraft = TaxCategoryDraft.of(name, singletonList(TaxRateDraft.of("xyz", 0.20, true, DE))); return client.executeBlocking(TaxCategoryQuery.of().byName(name)).head().orElseGet(() -> client.executeBlocking(TaxCategoryCreateCommand.of(categoryDraft))); }
public static void withTaxCategory(final BlockingSphereClient client, final Consumer<TaxCategory> user) { final QueryPredicate<TaxCategory> predicate = TaxCategoryQueryModel.of().name().is(STANDARD_TAX_CATEGORY); final List<TaxCategory> results = client.executeBlocking(TaxCategoryQuery.of().withPredicates(predicate)).getResults(); final TaxCategory taxCategory; if (results.isEmpty()) { final List<TaxRateDraft> taxRates = asList(TaxRateDraft.of("5% US", 0.05, false, US), TaxRateDraft.of("19% MwSt", 0.19, true, DE)); taxCategory = client.executeBlocking(TaxCategoryCreateCommand.of(TaxCategoryDraft.of(STANDARD_TAX_CATEGORY, taxRates))); } else { taxCategory = results.get(0); } user.accept(taxCategory); }
public static void withUpdateableTaxCategory(final BlockingSphereClient client, final UnaryOperator<TaxCategory> testApplicationFunction) { final TaxCategoryDraft draft = TaxCategoryDraft.of(randomKey(), singletonList(TaxRateDraftBuilder.of("de19", 0.19, true, CountryCode.DE).build())); final PagedQueryResult<TaxCategory> results = client.executeBlocking(TaxCategoryQuery.of().byName(draft.getName())); results.getResults().forEach(tc -> client.executeBlocking(TaxCategoryDeleteCommand.of(tc))); final TaxCategory taxCategory = client.executeBlocking(TaxCategoryCreateCommand.of(draft)); final TaxCategory updated = testApplicationFunction.apply(taxCategory); client.executeBlocking(TaxCategoryDeleteCommand.of(updated)); } }
private static void withTaxedAndPricedProduct(final BlockingSphereClient client, final long centAmount, final double taxRate, final boolean taxIncluded, final Consumer<Product> operator) { final List<TaxRateDraft> taxRateDrafts = singletonList(TaxRateDraftBuilder.of(randomKey(), taxRate, taxIncluded, CountryCode.DE).build()); final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraft.of(randomString(), taxRateDrafts); withTaxCategory(client, taxCategoryDraft, taxCategory -> withProduct(client, product -> { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.ofCents(centAmount, EUR)).withCountry(DE); final ProductUpdateCommand setPricesCmd = ProductUpdateCommand.of(product, asList( AddPrice.of(MASTER_VARIANT_ID, priceDraft), SetTaxCategory.of(taxCategory), Publish.of())); final Product productWithPrice = client.executeBlocking(setPricesCmd); operator.accept(productWithPrice); }) ); } }
@Test public void execution() throws Exception { final CurrencyUnit currencyUnit = USD; final TaxRateDraft taxRate = TaxRateDraft.of("x20", 0.20, true, COUNTRY_CODE); withZone(client(), zone -> { withTaxCategory(client(), TaxCategoryDraft.of("taxcat", asList(taxRate)), taxCategory -> { final ZoneRateDraft zoneRate = ZoneRateDraftBuilder.of(zone.toResourceIdentifier(), asList(ShippingRate.of(MoneyImpl.of(30, currencyUnit)))).build(); final ShippingMethodDraft draft = ShippingMethodDraft.of("standard shipping", "description", taxCategory, asList(zoneRate)); final ShippingMethod shippingMethod = client().executeBlocking(ShippingMethodCreateCommand.of(draft)); //deletion client().executeBlocking(ShippingMethodDeleteCommand.of(shippingMethod)); }); }, COUNTRY_CODE); }
@Test public void createShippingMethodWithPredicate() throws Exception { final CurrencyUnit currencyUnit = USD; final TaxRateDraft taxRate = TaxRateDraft.of("x20", 0.20, true, COUNTRY_CODE); withZone(client(), zone -> { withTaxCategory(client(), TaxCategoryDraft.of("taxcat", asList(taxRate)), taxCategory -> { final ZoneRateDraft zoneRateDraft = ZoneRateDraftBuilder.of(zone.toResourceIdentifier(), asList(ShippingRate.of(MoneyImpl.of(30, currencyUnit)))).build(); final ShippingMethodDraft draft = ShippingMethodDraftBuilder.of("standard shipping", "description", taxCategory.toReference(), asList(zoneRateDraft), false) .predicate(CartPredicate.of("customer.email = \"john@example.com\"")) .build(); final ShippingMethod shippingMethod = client().executeBlocking(ShippingMethodCreateCommand.of(draft)); //deletion client().executeBlocking(ShippingMethodDeleteCommand.of(shippingMethod)); }); }, COUNTRY_CODE); }