public static TaxRateDraftBuilder of(final TaxRateDraft 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; }); }
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 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 TaxRateDraftBuilder of(final TaxRateDraft taxRate) { return of(taxRate.getName(), taxRate.getAmount(), taxRate.isIncludedInPrice(), taxRate.getCountry()) .state(taxRate.getState()) .subRates(taxRate.getSubRates()); }
private TaxCategory createTaxCategory() { final TaxRateDraft taxRate = TaxRateDraft.of("GERMAN default tax", 0.19, false, DE); final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder.of("German tax", singletonList(taxRate), "Normal-Steuersatz").key(KEY).build(); final TaxCategory taxCategory = client().executeBlocking(TaxCategoryCreateCommand.of(taxCategoryDraft)); return taxCategory; } }
@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); }