From 29647cf480daf7b64c2ef090f3f4be232b771c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Grudzie=C5=84?= <59444374+patryk-grudzien-keen@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:41:33 +0100 Subject: [PATCH] [DE-572] Fixed response schema for "Promote Product Price Point to Default" endpoint (#42) --- doc/controllers/product-price-points.md | 61 +++++++++++++------ .../ProductPricePointsController.java | 15 ++--- .../maxio/advancedbilling/models/Product.java | 51 ++++++++++++---- .../ProductsControllerListProductsTest.java | 2 +- 4 files changed, 92 insertions(+), 37 deletions(-) diff --git a/doc/controllers/product-price-points.md b/doc/controllers/product-price-points.md index 59b76620..1bc088e2 100644 --- a/doc/controllers/product-price-points.md +++ b/doc/controllers/product-price-points.md @@ -16,7 +16,7 @@ ProductPricePointsController productPricePointsController = client.getProductPri * [Read Product Price Point](../../doc/controllers/product-price-points.md#read-product-price-point) * [Archive Product Price Point](../../doc/controllers/product-price-points.md#archive-product-price-point) * [Unarchive Product Price Point](../../doc/controllers/product-price-points.md#unarchive-product-price-point) -* [Set Default Price Point for Product](../../doc/controllers/product-price-points.md#set-default-price-point-for-product) +* [Promote Product Price Point to Default](../../doc/controllers/product-price-points.md#promote-product-price-point-to-default) * [Create Product Price Points](../../doc/controllers/product-price-points.md#create-product-price-points) * [Create Product Currency Prices](../../doc/controllers/product-price-points.md#create-product-currency-prices) * [Update Product Currency Prices](../../doc/controllers/product-price-points.md#update-product-currency-prices) @@ -464,14 +464,14 @@ try { ``` -# Set Default Price Point for Product +# Promote Product Price Point to Default Use this endpoint to make a product price point the default for the product. Note: Custom product price points are not able to be set as the default for a product. ```java -ProductPricePointResponse setDefaultPricePointForProduct( +ProductResponse promoteProductPricePointToDefault( final int productId, final int pricePointId) ``` @@ -485,7 +485,7 @@ ProductPricePointResponse setDefaultPricePointForProduct( ## Response Type -[`ProductPricePointResponse`](../../doc/models/product-price-point-response.md) +[`ProductResponse`](../../doc/models/product-response.md) ## Example Usage @@ -494,7 +494,7 @@ int productId = 202; int pricePointId = 10; try { - ProductPricePointResponse result = productPricePointsController.setDefaultPricePointForProduct(productId, pricePointId); + ProductResponse result = productPricePointsController.promoteProductPricePointToDefault(productId, pricePointId); System.out.println(result); } catch (ApiException e) { e.printStackTrace(); @@ -507,25 +507,52 @@ try { ```json { - "price_point": { - "id": 283, + "product": { + "id": 29778, "name": "Educational", "handle": "educational", - "price_in_cents": 1000, - "interval": 1, + "description": null, + "accounting_code": null, + "request_credit_card": true, + "expiration_interval": 12, + "expiration_interval_unit": "month", + "created_at": "2023-12-01T06:56:12-05:00", + "updated_at": "2023-12-01T06:56:26-05:00", + "price_in_cents": 100, + "interval": 2, "interval_unit": "month", + "initial_charge_in_cents": 120000, "trial_price_in_cents": 4900, "trial_interval": 1, "trial_interval_unit": "month", - "trial_type": "payment_expected", - "initial_charge_in_cents": 120000, + "archived_at": null, + "require_credit_card": true, + "return_params": null, + "taxable": false, + "update_return_url": null, + "tax_code": null, "initial_charge_after_trial": false, - "expiration_interval": 12, - "expiration_interval_unit": "month", - "product_id": 901, - "archived_at": "2023-11-30T06:37:20-05:00", - "created_at": "2023-11-27T06:37:20-05:00", - "updated_at": "2023-11-27T06:37:20-05:00" + "version_number": 1, + "update_return_params": null, + "default_product_price_point_id": 32395, + "request_billing_address": false, + "require_billing_address": false, + "require_shipping_address": false, + "use_site_exchange_rate": true, + "item_category": null, + "product_price_point_id": 32395, + "product_price_point_name": "Default", + "product_price_point_handle": "uuid:8c878f50-726e-013c-c71b-0286551bb34f", + "product_family": { + "id": 933860, + "name": "Acme Projects", + "description": "Amazing project management tool", + "handle": "acme-projects", + "accounting_code": null, + "created_at": "2023-12-01T06:56:12-05:00", + "updated_at": "2023-12-01T06:56:12-05:00" + }, + "public_signup_pages": [] } } ``` diff --git a/src/main/java/com/maxio/advancedbilling/controllers/ProductPricePointsController.java b/src/main/java/com/maxio/advancedbilling/controllers/ProductPricePointsController.java index 26a5a43e..229c4caf 100644 --- a/src/main/java/com/maxio/advancedbilling/controllers/ProductPricePointsController.java +++ b/src/main/java/com/maxio/advancedbilling/controllers/ProductPricePointsController.java @@ -25,6 +25,7 @@ import com.maxio.advancedbilling.models.PricePointType; import com.maxio.advancedbilling.models.ProductPricePointCurrencyPrice; import com.maxio.advancedbilling.models.ProductPricePointResponse; +import com.maxio.advancedbilling.models.ProductResponse; import com.maxio.advancedbilling.models.UpdateCurrencyPricesRequest; import com.maxio.advancedbilling.models.UpdateProductPricePointRequest; import io.apimatic.core.ApiCall; @@ -344,23 +345,23 @@ private ApiCall prepareUnarchiveProduct * @param productId Required parameter: The Chargify id of the product to which the price * point belongs * @param pricePointId Required parameter: The Chargify id of the product price point - * @return Returns the ProductPricePointResponse response from the API call + * @return Returns the ProductResponse response from the API call * @throws ApiException Represents error response from the server. * @throws IOException Signals that an I/O exception of some sort has occurred. */ - public ProductPricePointResponse setDefaultPricePointForProduct( + public ProductResponse promoteProductPricePointToDefault( final int productId, final int pricePointId) throws ApiException, IOException { - return prepareSetDefaultPricePointForProductRequest(productId, pricePointId).execute(); + return preparePromoteProductPricePointToDefaultRequest(productId, pricePointId).execute(); } /** - * Builds the ApiCall object for setDefaultPricePointForProduct. + * Builds the ApiCall object for promoteProductPricePointToDefault. */ - private ApiCall prepareSetDefaultPricePointForProductRequest( + private ApiCall preparePromoteProductPricePointToDefaultRequest( final int productId, final int pricePointId) throws IOException { - return new ApiCall.Builder() + return new ApiCall.Builder() .globalConfig(getGlobalConfiguration()) .requestBuilder(requestBuilder -> requestBuilder .server(Server.ENUM_DEFAULT.value()) @@ -374,7 +375,7 @@ private ApiCall prepareSetDefaultPriceP .httpMethod(HttpMethod.PATCH)) .responseHandler(responseHandler -> responseHandler .deserializer( - response -> ApiHelper.deserialize(response, ProductPricePointResponse.class)) + response -> ApiHelper.deserialize(response, ProductResponse.class)) .nullify404(false) .globalErrorCase(GLOBAL_ERROR_CASES)) .endpointConfiguration(param -> param diff --git a/src/main/java/com/maxio/advancedbilling/models/Product.java b/src/main/java/com/maxio/advancedbilling/models/Product.java index 7a25d32e..0b3adcd3 100644 --- a/src/main/java/com/maxio/advancedbilling/models/Product.java +++ b/src/main/java/com/maxio/advancedbilling/models/Product.java @@ -25,7 +25,7 @@ public class Product { private Integer id; private String name; private OptionalNullable handle; - private String description; + private OptionalNullable description; private OptionalNullable accountingCode; private Boolean requestCreditCard; private OptionalNullable expirationInterval; @@ -148,7 +148,7 @@ public Product( this.id = id; this.name = name; this.handle = OptionalNullable.of(handle); - this.description = description; + this.description = OptionalNullable.of(description); this.accountingCode = OptionalNullable.of(accountingCode); this.requestCreditCard = requestCreditCard; this.expirationInterval = OptionalNullable.of(expirationInterval); @@ -226,9 +226,9 @@ public Product( * @param productPricePointHandle String value for productPricePointHandle. */ - protected Product(Integer id, String name, OptionalNullable handle, String description, - OptionalNullable accountingCode, Boolean requestCreditCard, - OptionalNullable expirationInterval, + protected Product(Integer id, String name, OptionalNullable handle, + OptionalNullable description, OptionalNullable accountingCode, + Boolean requestCreditCard, OptionalNullable expirationInterval, OptionalNullable expirationIntervalUnit, ZonedDateTime createdAt, ZonedDateTime updatedAt, Long priceInCents, Integer interval, IntervalUnit intervalUnit, OptionalNullable initialChargeInCents, @@ -363,14 +363,24 @@ public void unsetHandle() { } /** - * Getter for Description. + * Internal Getter for Description. * The product description - * @return Returns the String + * @return Returns the Internal String */ @JsonGetter("description") @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonSerialize(using = OptionalNullable.Serializer.class) + protected OptionalNullable internalGetDescription() { + return this.description; + } + + /** + * Getter for Description. + * The product description + * @return Returns the String + */ public String getDescription() { - return description; + return OptionalNullable.getFrom(description); } /** @@ -380,7 +390,15 @@ public String getDescription() { */ @JsonSetter("description") public void setDescription(String description) { - this.description = description; + this.description = OptionalNullable.of(description); + } + + /** + * UnSetter for Description. + * The product description + */ + public void unsetDescription() { + description = null; } /** @@ -1406,7 +1424,6 @@ public Builder toBuilder() { Builder builder = new Builder() .id(getId()) .name(getName()) - .description(getDescription()) .requestCreditCard(getRequestCreditCard()) .createdAt(getCreatedAt()) .updatedAt(getUpdatedAt()) @@ -1426,6 +1443,7 @@ public Builder toBuilder() { .defaultProductPricePointId(getDefaultProductPricePointId()) .productPricePointId(getProductPricePointId()); builder.handle = internalGetHandle(); + builder.description = internalGetDescription(); builder.accountingCode = internalGetAccountingCode(); builder.expirationInterval = internalGetExpirationInterval(); builder.expirationIntervalUnit = internalGetExpirationIntervalUnit(); @@ -1451,7 +1469,7 @@ public static class Builder { private Integer id; private String name; private OptionalNullable handle; - private String description; + private OptionalNullable description; private OptionalNullable accountingCode; private Boolean requestCreditCard; private OptionalNullable expirationInterval; @@ -1533,7 +1551,16 @@ public Builder unsetHandle() { * @return Builder */ public Builder description(String description) { - this.description = description; + this.description = OptionalNullable.of(description); + return this; + } + + /** + * UnSetter for description. + * @return Builder + */ + public Builder unsetDescription() { + description = null; return this; } diff --git a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java index 18eb9d79..8b43d927 100644 --- a/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java +++ b/tests/src/test/java/com/maxio/advancedbilling/controllers/products/ProductsControllerListProductsTest.java @@ -44,7 +44,7 @@ static void setupProducts() throws IOException, ApiException { ProductPricePoint pricePoint = productPricePointsController .createProductPricePoint(productWithChangedPricePoint.getId(), createProductPricePointRequest) .getPricePoint(); - productPricePointsController.setDefaultPricePointForProduct(productWithChangedPricePoint.getId(), pricePoint.getId()); + productPricePointsController.promoteProductPricePointToDefault(productWithChangedPricePoint.getId(), pricePoint.getId()); productWithChangedPricePoint = productsController.readProduct(productWithChangedPricePoint.getId()).getProduct(); savedProducts.add(productWithChangedPricePoint); }