All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.univapay.sdk.builders.charge.AbstractChargesBuilders Maven / Gradle / Ivy

There is a newer version: 0.2.35
Show newest version
package com.univapay.sdk.builders.charge;

import com.univapay.sdk.builders.DescriptorRetry;
import com.univapay.sdk.builders.IdempotentRetrofitRequestBuilder;
import com.univapay.sdk.builders.Polling;
import com.univapay.sdk.builders.Request;
import com.univapay.sdk.builders.RetrofitRequestBuilder;
import com.univapay.sdk.builders.RetrofitRequestBuilderPaginated;
import com.univapay.sdk.builders.RetrofitRequestCaller;
import com.univapay.sdk.builders.RetryUtils;
import com.univapay.sdk.models.common.ChargeId;
import com.univapay.sdk.models.common.MoneyLike;
import com.univapay.sdk.models.common.StoreId;
import com.univapay.sdk.models.common.TransactionTokenId;
import com.univapay.sdk.models.common.Void;
import com.univapay.sdk.models.request.charge.CardChargeSearch;
import com.univapay.sdk.models.response.charge.Charge;
import com.univapay.sdk.types.MetadataMap;
import com.univapay.sdk.utils.MetadataAdapter;
import java.time.OffsetDateTime;
import retrofit2.Retrofit;

public abstract class AbstractChargesBuilders {

  public abstract static class AbstractListChargesRequestBuilder<
          B extends AbstractListChargesRequestBuilder, R, M extends Charge>
      extends RetrofitRequestBuilderPaginated {

    protected StoreId storeId;
    protected CardChargeSearch propertySearch = new CardChargeSearch();
    protected String metadataSearch;

    protected StoreId getStoreId() {
      return storeId;
    }

    public AbstractListChargesRequestBuilder(Retrofit retrofit) {
      super(retrofit);
    }

    public AbstractListChargesRequestBuilder(Retrofit retrofit, StoreId storeId) {
      super(retrofit);
      this.storeId = storeId;
    }

    public B withCardChargeSearch(CardChargeSearch search) {
      this.propertySearch = search;
      return (B) this;
    }

    public B withMetadataSearch(String search) {
      this.metadataSearch = search;
      return (B) this;
    }
  }

  public abstract static class AbstractGetChargeRequestBuilder<
          B extends AbstractGetChargeRequestBuilder, R, M extends Charge>
      extends RetrofitRequestBuilder implements Polling {

    protected StoreId storeId;
    protected ChargeId chargeId;
    protected Boolean polling;

    protected StoreId getStoreId() {
      return storeId;
    }

    protected ChargeId getChargeId() {
      return chargeId;
    }

    public AbstractGetChargeRequestBuilder(Retrofit retrofit, StoreId storeId, ChargeId chargeId) {
      super(retrofit);
      this.storeId = storeId;
      this.chargeId = chargeId;
    }

    public B withPolling(boolean polling) {
      this.polling = polling;
      return (B) this;
    }
  }

  public abstract static class AbstractCreateChargeRequestBuilder<
          B extends AbstractCreateChargeRequestBuilder, R, M extends Charge>
      extends IdempotentRetrofitRequestBuilder implements DescriptorRetry {

    protected TransactionTokenId transactionTokenId;
    protected MoneyLike money;
    protected Boolean onlyDirectCurrency;
    protected OffsetDateTime captureAt;
    protected Boolean capture;
    protected Boolean ignoreDescriptorOnError = false;
    protected String descriptor;
    protected MetadataMap metadata;

    protected TransactionTokenId getTransactionTokenId() {
      return transactionTokenId;
    }

    public MoneyLike getMoney() {
      return money;
    }

    public Boolean getOnlyDirectCurrency() {
      return onlyDirectCurrency;
    }

    public OffsetDateTime getCaptureAt() {
      return captureAt;
    }

    public Boolean getCapture() {
      return capture;
    }

    public String getDescriptor() {
      return descriptor;
    }

    protected MetadataMap getMetadata() {
      return metadata;
    }

    public AbstractCreateChargeRequestBuilder(
        Retrofit retrofit,
        TransactionTokenId transactionTokenId,
        MoneyLike money,
        Boolean capture) {
      super(retrofit);
      this.transactionTokenId = transactionTokenId;
      this.money = money;
      this.capture = capture;
    }

    public B withOnlyDirectCurrency(Boolean onlyDirectCurrency) {
      this.onlyDirectCurrency = onlyDirectCurrency;
      return (B) this;
    }

    public B withCaptureAt(OffsetDateTime captureAt) {
      this.captureAt = captureAt;
      return (B) this;
    }

    public B withDescriptor(String descriptor) {
      this.descriptor = descriptor;
      return (B) this;
    }

    public B withDescriptor(String descriptor, Boolean ignoreDescriptorOnError) {
      this.descriptor = descriptor;
      this.ignoreDescriptorOnError = ignoreDescriptorOnError;
      return (B) this;
    }

    public B withMetadata(MetadataMap metadata) {
      this.metadata = metadata;
      return (B) this;
    }

    public  B withMetadata(T metadata, MetadataAdapter adapter) {
      this.metadata = adapter.serialize(metadata);
      return (B) this;
    }

    @Override
    public Request build() {

      if (descriptor != null && ignoreDescriptorOnError) {
        Request request = new RetrofitRequestCaller<>(retrofit, createCall());
        return retryIgnoringDescriptor(request);
      } else return super.build();
    }

    @Override
    public Request retryIgnoringDescriptor(Request originalRequest) {
      return RetryUtils.retryIgnoringDescriptor(originalRequest, this);
    }
  }

  public abstract static class AbstractUpdateChargeRequestBuilder<
          B extends AbstractUpdateChargeRequestBuilder, R, M extends Charge>
      extends IdempotentRetrofitRequestBuilder {

    protected StoreId storeId;
    protected ChargeId chargeId;
    protected MetadataMap metadata;

    public StoreId getStoreId() {
      return storeId;
    }

    public ChargeId getChargeId() {
      return chargeId;
    }

    protected MetadataMap getMetadata() {
      return metadata;
    }

    public AbstractUpdateChargeRequestBuilder(
        Retrofit retrofit, StoreId storeId, ChargeId chargeId) {
      super(retrofit);
      this.storeId = storeId;
      this.chargeId = chargeId;
    }

    public B withMetadata(MetadataMap metadata) {
      this.metadata = metadata;
      return (B) this;
    }

    public  B withMetadata(T metadata, MetadataAdapter adapter) {
      this.metadata = adapter.serialize(metadata);
      return (B) this;
    }
  }

  public abstract static class AbstractCaptureAuthorizedChargeRequestBuilder<
          B extends AbstractCaptureAuthorizedChargeRequestBuilder, R>
      extends IdempotentRetrofitRequestBuilder {

    protected StoreId storeId;
    protected ChargeId chargeId;
    protected MoneyLike money;

    public MoneyLike getMoney() {
      return money;
    }

    public StoreId getStoreId() {
      return storeId;
    }

    public ChargeId getChargeId() {
      return chargeId;
    }

    public AbstractCaptureAuthorizedChargeRequestBuilder(
        Retrofit retrofit, StoreId storeId, ChargeId chargeId, MoneyLike money) {
      super(retrofit);
      this.storeId = storeId;
      this.chargeId = chargeId;
      this.money = money;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy