Skip to content

Commit

Permalink
[DE-572] Fixed response schema for "Promote Product Price Point to De…
Browse files Browse the repository at this point in the history
…fault" endpoint (#42)
  • Loading branch information
patryk-grudzien-keen authored Dec 1, 2023
1 parent 58f0c57 commit 29647cf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 37 deletions.
61 changes: 44 additions & 17 deletions doc/controllers/product-price-points.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
```
Expand All @@ -485,7 +485,7 @@ ProductPricePointResponse setDefaultPricePointForProduct(

## Response Type

[`ProductPricePointResponse`](../../doc/models/product-price-point-response.md)
[`ProductResponse`](../../doc/models/product-response.md)

## Example Usage

Expand All @@ -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();
Expand All @@ -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": []
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -344,23 +345,23 @@ private ApiCall<ProductPricePointResponse, ApiException> 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<ProductPricePointResponse, ApiException> prepareSetDefaultPricePointForProductRequest(
private ApiCall<ProductResponse, ApiException> preparePromoteProductPricePointToDefaultRequest(
final int productId,
final int pricePointId) throws IOException {
return new ApiCall.Builder<ProductPricePointResponse, ApiException>()
return new ApiCall.Builder<ProductResponse, ApiException>()
.globalConfig(getGlobalConfiguration())
.requestBuilder(requestBuilder -> requestBuilder
.server(Server.ENUM_DEFAULT.value())
Expand All @@ -374,7 +375,7 @@ private ApiCall<ProductPricePointResponse, ApiException> 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
Expand Down
51 changes: 39 additions & 12 deletions src/main/java/com/maxio/advancedbilling/models/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Product {
private Integer id;
private String name;
private OptionalNullable<String> handle;
private String description;
private OptionalNullable<String> description;
private OptionalNullable<String> accountingCode;
private Boolean requestCreditCard;
private OptionalNullable<Integer> expirationInterval;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -226,9 +226,9 @@ public Product(
* @param productPricePointHandle String value for productPricePointHandle.
*/

protected Product(Integer id, String name, OptionalNullable<String> handle, String description,
OptionalNullable<String> accountingCode, Boolean requestCreditCard,
OptionalNullable<Integer> expirationInterval,
protected Product(Integer id, String name, OptionalNullable<String> handle,
OptionalNullable<String> description, OptionalNullable<String> accountingCode,
Boolean requestCreditCard, OptionalNullable<Integer> expirationInterval,
OptionalNullable<ProductExpirationIntervalUnit> expirationIntervalUnit,
ZonedDateTime createdAt, ZonedDateTime updatedAt, Long priceInCents, Integer interval,
IntervalUnit intervalUnit, OptionalNullable<Long> initialChargeInCents,
Expand Down Expand Up @@ -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<String> internalGetDescription() {
return this.description;
}

/**
* Getter for Description.
* The product description
* @return Returns the String
*/
public String getDescription() {
return description;
return OptionalNullable.getFrom(description);
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -1406,7 +1424,6 @@ public Builder toBuilder() {
Builder builder = new Builder()
.id(getId())
.name(getName())
.description(getDescription())
.requestCreditCard(getRequestCreditCard())
.createdAt(getCreatedAt())
.updatedAt(getUpdatedAt())
Expand All @@ -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();
Expand All @@ -1451,7 +1469,7 @@ public static class Builder {
private Integer id;
private String name;
private OptionalNullable<String> handle;
private String description;
private OptionalNullable<String> description;
private OptionalNullable<String> accountingCode;
private Boolean requestCreditCard;
private OptionalNullable<Integer> expirationInterval;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 29647cf

Please sign in to comment.