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 @@ -25,6 +25,7 @@
import com.schematic.api.resources.billing.requests.CreateMeterRequestBody;
import com.schematic.api.resources.billing.requests.CreatePaymentMethodRequestBody;
import com.schematic.api.resources.billing.requests.ListBillingProductsRequest;
import com.schematic.api.resources.billing.requests.ListCouponsRequest;
import com.schematic.api.resources.billing.requests.ListCustomersRequest;
import com.schematic.api.resources.billing.requests.ListInvoicesRequest;
import com.schematic.api.resources.billing.requests.ListMetersRequest;
Expand All @@ -35,6 +36,7 @@
import com.schematic.api.resources.billing.types.CountCustomersResponse;
import com.schematic.api.resources.billing.types.DeleteProductPriceResponse;
import com.schematic.api.resources.billing.types.ListBillingProductsResponse;
import com.schematic.api.resources.billing.types.ListCouponsResponse;
import com.schematic.api.resources.billing.types.ListCustomersResponse;
import com.schematic.api.resources.billing.types.ListInvoicesResponse;
import com.schematic.api.resources.billing.types.ListMetersResponse;
Expand Down Expand Up @@ -66,6 +68,74 @@ public BillingClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}

public ListCouponsResponse listCoupons() {
return listCoupons(ListCouponsRequest.builder().build());
}

public ListCouponsResponse listCoupons(ListCouponsRequest request) {
return listCoupons(request, null);
}

public ListCouponsResponse listCoupons(ListCouponsRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("billing/coupons");
if (request.getIsActive().isPresent()) {
httpUrl.addQueryParameter("is_active", request.getIsActive().get().toString());
}
if (request.getQ().isPresent()) {
httpUrl.addQueryParameter("q", request.getQ().get());
}
if (request.getLimit().isPresent()) {
httpUrl.addQueryParameter("limit", request.getLimit().get().toString());
}
if (request.getOffset().isPresent()) {
httpUrl.addQueryParameter("offset", request.getOffset().get().toString());
}
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json");
Request okhttpRequest = _requestBuilder.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(), ListCouponsResponse.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 UpsertBillingCouponResponse upsertBillingCoupon(CreateCouponRequestBody request) {
return upsertBillingCoupon(request, null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.schematic.api.resources.billing.requests;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.schematic.api.core.ObjectMappers;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@JsonInclude(JsonInclude.Include.NON_ABSENT)
@JsonDeserialize(builder = ListCouponsRequest.Builder.class)
public final class ListCouponsRequest {
private final Optional<Boolean> isActive;

private final Optional<String> q;

private final Optional<Integer> limit;

private final Optional<Integer> offset;

private final Map<String, Object> additionalProperties;

private ListCouponsRequest(
Optional<Boolean> isActive,
Optional<String> q,
Optional<Integer> limit,
Optional<Integer> offset,
Map<String, Object> additionalProperties) {
this.isActive = isActive;
this.q = q;
this.limit = limit;
this.offset = offset;
this.additionalProperties = additionalProperties;
}

@JsonProperty("is_active")
public Optional<Boolean> getIsActive() {
return isActive;
}

@JsonProperty("q")
public Optional<String> getQ() {
return q;
}

/**
* @return Page limit (default 100)
*/
@JsonProperty("limit")
public Optional<Integer> getLimit() {
return limit;
}

/**
* @return Page offset (default 0)
*/
@JsonProperty("offset")
public Optional<Integer> getOffset() {
return offset;
}

@java.lang.Override
public boolean equals(Object other) {
if (this == other) return true;
return other instanceof ListCouponsRequest && equalTo((ListCouponsRequest) other);
}

@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}

private boolean equalTo(ListCouponsRequest other) {
return isActive.equals(other.isActive)
&& q.equals(other.q)
&& limit.equals(other.limit)
&& offset.equals(other.offset);
}

@java.lang.Override
public int hashCode() {
return Objects.hash(this.isActive, this.q, this.limit, this.offset);
}

@java.lang.Override
public String toString() {
return ObjectMappers.stringify(this);
}

public static Builder builder() {
return new Builder();
}

@JsonIgnoreProperties(ignoreUnknown = true)
public static final class Builder {
private Optional<Boolean> isActive = Optional.empty();

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

private Optional<Integer> limit = Optional.empty();

private Optional<Integer> offset = Optional.empty();

@JsonAnySetter
private Map<String, Object> additionalProperties = new HashMap<>();

private Builder() {}

public Builder from(ListCouponsRequest other) {
isActive(other.getIsActive());
q(other.getQ());
limit(other.getLimit());
offset(other.getOffset());
return this;
}

@JsonSetter(value = "is_active", nulls = Nulls.SKIP)
public Builder isActive(Optional<Boolean> isActive) {
this.isActive = isActive;
return this;
}

public Builder isActive(Boolean isActive) {
this.isActive = Optional.ofNullable(isActive);
return this;
}

@JsonSetter(value = "q", nulls = Nulls.SKIP)
public Builder q(Optional<String> q) {
this.q = q;
return this;
}

public Builder q(String q) {
this.q = Optional.ofNullable(q);
return this;
}

@JsonSetter(value = "limit", nulls = Nulls.SKIP)
public Builder limit(Optional<Integer> limit) {
this.limit = limit;
return this;
}

public Builder limit(Integer limit) {
this.limit = Optional.ofNullable(limit);
return this;
}

@JsonSetter(value = "offset", nulls = Nulls.SKIP)
public Builder offset(Optional<Integer> offset) {
this.offset = offset;
return this;
}

public Builder offset(Integer offset) {
this.offset = Optional.ofNullable(offset);
return this;
}

public ListCouponsRequest build() {
return new ListCouponsRequest(isActive, q, limit, offset, additionalProperties);
}
}
}
Loading