Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.schematic.api.resources.billing.requests.SearchBillingPricesRequest;
import com.schematic.api.resources.billing.types.CountBillingProductsResponse;
import com.schematic.api.resources.billing.types.CountCustomersResponse;
import com.schematic.api.resources.billing.types.DeleteBillingProductResponse;
import com.schematic.api.resources.billing.types.DeleteProductPriceResponse;
import com.schematic.api.resources.billing.types.ListBillingProductsResponse;
import com.schematic.api.resources.billing.types.ListCouponsResponse;
Expand Down Expand Up @@ -668,11 +669,6 @@ public ListPaymentMethodsResponse listPaymentMethods(
httpUrl.addQueryParameter("company_id", request.getCompanyId().get());
}
httpUrl.addQueryParameter("customer_external_id", request.getCustomerExternalId());
if (request.getSubscriptionExternalId().isPresent()) {
httpUrl.addQueryParameter(
"subscription_external_id",
request.getSubscriptionExternalId().get());
}
if (request.getLimit().isPresent()) {
httpUrl.addQueryParameter("limit", request.getLimit().get().toString());
}
Expand Down Expand Up @@ -807,7 +803,7 @@ public SearchBillingPricesResponse searchBillingPrices(
httpUrl.addQueryParameter("interval", request.getInterval().get());
}
if (request.getUsageType().isPresent()) {
httpUrl.addQueryParameter("usage_type", request.getUsageType().get());
httpUrl.addQueryParameter("usage_type", request.getUsageType().get().toString());
}
if (request.getPrice().isPresent()) {
httpUrl.addQueryParameter("price", request.getPrice().get().toString());
Expand Down Expand Up @@ -923,6 +919,60 @@ public UpsertBillingPriceResponse upsertBillingPrice(
}
}

public DeleteBillingProductResponse deleteBillingProduct(String billingId) {
return deleteBillingProduct(billingId, null);
}

public DeleteBillingProductResponse deleteBillingProduct(String billingId, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("billing/product")
.addPathSegment(billingId)
.build();
Request okhttpRequest = new Request.Builder()
.url(httpUrl)
.method("DELETE", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.build();
OkHttpClient client = clientOptions.httpClient();
if (requestOptions != null && requestOptions.getTimeout().isPresent()) {
client = clientOptions.httpClientWithTimeout(requestOptions);
}
try (Response response = client.newCall(okhttpRequest).execute()) {
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DeleteBillingProductResponse.class);
}
String responseBodyString = responseBody != null ? responseBody.string() : "{}";
try {
switch (response.code()) {
case 400:
throw new BadRequestError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
case 401:
throw new UnauthorizedError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
case 403:
throw new ForbiddenError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
case 500:
throw new InternalServerError(
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, ApiError.class));
}
} catch (JsonProcessingException ignored) {
// unable to map error response, throwing generic error
}
throw new BaseSchematicApiException(
"Error with status code " + response.code(),
response.code(),
ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class));
} catch (IOException e) {
throw new BaseSchematicException("Network error executing HTTP request", e);
}
}

public ListProductPricesResponse listProductPrices() {
return listProductPrices(ListProductPricesRequest.builder().build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
public final class CreateBillingCustomerRequestBody {
private final Optional<String> companyId;

private final Optional<String> defaultPaymentMethodId;

private final String email;

private final String externalId;
Expand All @@ -38,13 +40,15 @@ public final class CreateBillingCustomerRequestBody {

private CreateBillingCustomerRequestBody(
Optional<String> companyId,
Optional<String> defaultPaymentMethodId,
String email,
String externalId,
boolean failedToImport,
Map<String, String> meta,
String name,
Map<String, Object> additionalProperties) {
this.companyId = companyId;
this.defaultPaymentMethodId = defaultPaymentMethodId;
this.email = email;
this.externalId = externalId;
this.failedToImport = failedToImport;
Expand All @@ -58,6 +62,11 @@ public Optional<String> getCompanyId() {
return companyId;
}

@JsonProperty("default_payment_method_id")
public Optional<String> getDefaultPaymentMethodId() {
return defaultPaymentMethodId;
}

@JsonProperty("email")
public String getEmail() {
return email;
Expand Down Expand Up @@ -96,6 +105,7 @@ public Map<String, Object> getAdditionalProperties() {

private boolean equalTo(CreateBillingCustomerRequestBody other) {
return companyId.equals(other.companyId)
&& defaultPaymentMethodId.equals(other.defaultPaymentMethodId)
&& email.equals(other.email)
&& externalId.equals(other.externalId)
&& failedToImport == other.failedToImport
Expand All @@ -105,7 +115,14 @@ private boolean equalTo(CreateBillingCustomerRequestBody other) {

@java.lang.Override
public int hashCode() {
return Objects.hash(this.companyId, this.email, this.externalId, this.failedToImport, this.meta, this.name);
return Objects.hash(
this.companyId,
this.defaultPaymentMethodId,
this.email,
this.externalId,
this.failedToImport,
this.meta,
this.name);
}

@java.lang.Override
Expand Down Expand Up @@ -142,6 +159,10 @@ public interface _FinalStage {

_FinalStage companyId(String companyId);

_FinalStage defaultPaymentMethodId(Optional<String> defaultPaymentMethodId);

_FinalStage defaultPaymentMethodId(String defaultPaymentMethodId);

_FinalStage meta(Map<String, String> meta);

_FinalStage putAllMeta(Map<String, String> meta);
Expand All @@ -162,6 +183,8 @@ public static final class Builder

private Map<String, String> meta = new LinkedHashMap<>();

private Optional<String> defaultPaymentMethodId = Optional.empty();

private Optional<String> companyId = Optional.empty();

@JsonAnySetter
Expand All @@ -172,6 +195,7 @@ private Builder() {}
@java.lang.Override
public Builder from(CreateBillingCustomerRequestBody other) {
companyId(other.getCompanyId());
defaultPaymentMethodId(other.getDefaultPaymentMethodId());
email(other.getEmail());
externalId(other.getExternalId());
failedToImport(other.getFailedToImport());
Expand Down Expand Up @@ -228,6 +252,19 @@ public _FinalStage meta(Map<String, String> meta) {
return this;
}

@java.lang.Override
public _FinalStage defaultPaymentMethodId(String defaultPaymentMethodId) {
this.defaultPaymentMethodId = Optional.ofNullable(defaultPaymentMethodId);
return this;
}

@java.lang.Override
@JsonSetter(value = "default_payment_method_id", nulls = Nulls.SKIP)
public _FinalStage defaultPaymentMethodId(Optional<String> defaultPaymentMethodId) {
this.defaultPaymentMethodId = defaultPaymentMethodId;
return this;
}

@java.lang.Override
public _FinalStage companyId(String companyId) {
this.companyId = Optional.ofNullable(companyId);
Expand All @@ -244,7 +281,14 @@ public _FinalStage companyId(Optional<String> companyId) {
@java.lang.Override
public CreateBillingCustomerRequestBody build() {
return new CreateBillingCustomerRequestBody(
companyId, email, externalId, failedToImport, meta, name, additionalProperties);
companyId,
defaultPaymentMethodId,
email,
externalId,
failedToImport,
meta,
name,
additionalProperties);
}
}
}
Loading