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

com.tinypass.client.publisher.api.PublisherPaymentMethodApi Maven / Gradle / Ivy

There is a newer version: 16.366.0
Show newest version
package com.tinypass.client.publisher.api;

import com.tinypass.client.common.*;
import com.tinypass.client.publisher.model.UserPaymentInfo;

import java.util.*;
import java.math.*;
import java.io.*;

public class PublisherPaymentMethodApi {

	private String basePath = "https://api.piano.io/api/v3";
	private String token;
	private ApiInvoker apiInvoker = null;
	private Map headerParams = new LinkedHashMap();

	public PublisherPaymentMethodApi(String basePath, String token) {
		this.basePath = basePath;
		this.token = token;
	}

	public PublisherPaymentMethodApi(String basePath, String token, ApiInvoker invoker, Map headerParams) {
		this(basePath, token);
		this.apiInvoker = invoker;
		this.headerParams = headerParams;
	}

	public ApiInvoker getInvoker() {
        if(apiInvoker == null) apiInvoker = ApiInvoker.getInstance();
		return apiInvoker;
	}

	public void setApiToken(String token){
		this.token = token;
	}

	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}

	public String getBasePath() {
		return basePath;
	}

	public String toQueryParam(Object arg) {
        if(arg == null)
            return null;
		if (arg instanceof Date) {
			Date date = (Date) arg;
			long epochTime = date.getTime() / 1000;
			return String.valueOf(epochTime);
		} else {
			return String.valueOf(arg);
		}

	}

    public void setQueryParam(Map> params, String paramName, Object value) {
        List currentValues = params.computeIfAbsent(paramName, k -> new ArrayList<>());
        if (value instanceof List) {
            List values = (List) value;
            values.forEach(o -> addQueryParam(currentValues, o));
        } else {
            addQueryParam(currentValues, value);
        }
    }

    private void addQueryParam(List currentValues, Object value) {
        String v = toQueryParam(value);
        if (v != null)
            currentValues.add(v);
    }


    /**
      * API Request for createPaymentInstrument
      */
	public class createPaymentInstrumentRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public createPaymentInstrumentRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public createPaymentInstrumentRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public createPaymentInstrumentRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public createPaymentInstrumentRequest token(String token) {
            setQueryParam(this.formParams, "token", token);
			return this;
		}
		public createPaymentInstrumentRequest setAsDefault(Boolean setAsDefault) {
            setQueryParam(this.formParams, "set_as_default", setAsDefault);
			return this;
		}
		public createPaymentInstrumentRequest userBillingAddress(String userBillingAddress) {
            setQueryParam(this.formParams, "user_billing_address", userBillingAddress);
			return this;
		}
		public createPaymentInstrumentRequest expirationMonth(Integer expirationMonth) {
            setQueryParam(this.formParams, "expiration_month", expirationMonth);
			return this;
		}
		public createPaymentInstrumentRequest expirationYear(Integer expirationYear) {
            setQueryParam(this.formParams, "expiration_year", expirationYear);
			return this;
		}
		public createPaymentInstrumentRequest lastFourDigits(String lastFourDigits) {
            setQueryParam(this.formParams, "last_four_digits", lastFourDigits);
			return this;
		}
		public createPaymentInstrumentRequest additionalInfo(String additionalInfo) {
            setQueryParam(this.formParams, "additional_info", additionalInfo);
			return this;
		}
		public createPaymentInstrumentRequest issuerCountry(String issuerCountry) {
            setQueryParam(this.formParams, "issuer_country", issuerCountry);
			return this;
		}
		public createPaymentInstrumentRequest sourceId(Integer sourceId) {
            setQueryParam(this.formParams, "source_id", sourceId);
			return this;
		}





		public String  execute() throws ApiException{

			String path = "/publisher/payment/method/add".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     String.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public createPaymentInstrumentRequest createPaymentInstrumentRequest(){
		return new createPaymentInstrumentRequest(headerParams);
	}



    /**
      * API Request for deletePaymentInstrument
      */
	public class deletePaymentInstrumentRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public deletePaymentInstrumentRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public deletePaymentInstrumentRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public deletePaymentInstrumentRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public deletePaymentInstrumentRequest paymentMethodId(String paymentMethodId) {
            setQueryParam(this.formParams, "payment_method_id", paymentMethodId);
			return this;
		}





		public Boolean  execute() throws ApiException{

			String path = "/publisher/payment/method/remove".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     Boolean.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public deletePaymentInstrumentRequest deletePaymentInstrumentRequest(){
		return new deletePaymentInstrumentRequest(headerParams);
	}



    /**
      * API Request for getUserPaymentInfo
      */
	public class getUserPaymentInfoRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public getUserPaymentInfoRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }

		public getUserPaymentInfoRequest aid(String aid) {
            setQueryParam(this.queryParams, "aid", aid);
			return this;
		}
		public getUserPaymentInfoRequest uid(String uid) {
            setQueryParam(this.queryParams, "uid", uid);
			return this;
		}
		public getUserPaymentInfoRequest userPaymentInfoId(String userPaymentInfoId) {
            setQueryParam(this.queryParams, "user_payment_info_id", userPaymentInfoId);
			return this;
		}






		public UserPaymentInfo  execute() throws ApiException{

			String path = "/publisher/payment/method/get".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "GET", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     UserPaymentInfo.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public getUserPaymentInfoRequest getUserPaymentInfoRequest(){
		return new getUserPaymentInfoRequest(headerParams);
	}



    /**
      * API Request for updatePaymentInstrument
      */
	public class updatePaymentInstrumentRequest implements ApiRequest {

        Map headerParams;
        Map> queryParams = new HashMap<>();
        Map> formParams = new HashMap<>();
        Object body = null;

        public updatePaymentInstrumentRequest(Map headerParams) {
            this.headerParams = headerParams;
        }

        public Map> getPreparedFormParams() {
            return Collections.unmodifiableMap(formParams);
        }


		public updatePaymentInstrumentRequest aid(String aid) {
            setQueryParam(this.formParams, "aid", aid);
			return this;
		}
		public updatePaymentInstrumentRequest uid(String uid) {
            setQueryParam(this.formParams, "uid", uid);
			return this;
		}
		public updatePaymentInstrumentRequest token(String token) {
            setQueryParam(this.formParams, "token", token);
			return this;
		}
		public updatePaymentInstrumentRequest setAsDefault(Boolean setAsDefault) {
            setQueryParam(this.formParams, "set_as_default", setAsDefault);
			return this;
		}
		public updatePaymentInstrumentRequest userBillingAddress(String userBillingAddress) {
            setQueryParam(this.formParams, "user_billing_address", userBillingAddress);
			return this;
		}
		public updatePaymentInstrumentRequest expirationMonth(Integer expirationMonth) {
            setQueryParam(this.formParams, "expiration_month", expirationMonth);
			return this;
		}
		public updatePaymentInstrumentRequest expirationYear(Integer expirationYear) {
            setQueryParam(this.formParams, "expiration_year", expirationYear);
			return this;
		}
		public updatePaymentInstrumentRequest lastFourDigits(String lastFourDigits) {
            setQueryParam(this.formParams, "last_four_digits", lastFourDigits);
			return this;
		}
		public updatePaymentInstrumentRequest additionalInfo(String additionalInfo) {
            setQueryParam(this.formParams, "additional_info", additionalInfo);
			return this;
		}
		public updatePaymentInstrumentRequest issuerCountry(String issuerCountry) {
            setQueryParam(this.formParams, "issuer_country", issuerCountry);
			return this;
		}
		public updatePaymentInstrumentRequest paymentMethodId(String paymentMethodId) {
            setQueryParam(this.formParams, "payment_method_id", paymentMethodId);
			return this;
		}





		public String  execute() throws ApiException{

			String path = "/publisher/payment/method/update".replaceAll("\\{format\\}","json");

			return getInvoker().invokeAPI(basePath, path, "POST", token,
                                                     queryParams, null,
                                                     headerParams,
                                                     formParams,
                                                     "",
                                                     String.class);
		}

	}


    /**
      * Helper method to create a new request.
      */
	public updatePaymentInstrumentRequest updatePaymentInstrumentRequest(){
		return new updatePaymentInstrumentRequest(headerParams);
	}




}