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

com.cashfree.pg.model.CFCardEMI Maven / Gradle / Ivy

There is a newer version: 2.1.7
Show newest version
/*
 * New Payment Gateway APIs
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 2022-01-01
 * Contact: [email protected]
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

package com.cashfree.pg.model;


import com.cashfree.pg.JSON;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;

/** CFCardEMI */
@javax.annotation.Generated(
        value = "org.openapitools.codegen.languages.JavaClientCodegen",
        date = "2023-03-16T14:01:52.135917+05:30[Asia/Kolkata]")
public class CFCardEMI {
    /** The channel for card payments will always be \"link\" */
    @JsonAdapter(ChannelEnum.Adapter.class)
    public enum ChannelEnum {
        LINK("link");

        private String value;

        ChannelEnum(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        @Override
        public String toString() {
            return String.valueOf(value);
        }

        public static ChannelEnum fromValue(String value) {
            for (ChannelEnum b : ChannelEnum.values()) {
                if (b.value.equals(value)) {
                    return b;
                }
            }
            throw new IllegalArgumentException("Unexpected value '" + value + "'");
        }

        public static class Adapter extends TypeAdapter {
            @Override
            public void write(final JsonWriter jsonWriter, final ChannelEnum enumeration)
                    throws IOException {
                jsonWriter.value(enumeration.getValue());
            }

            @Override
            public ChannelEnum read(final JsonReader jsonReader) throws IOException {
                String value = jsonReader.nextString();
                return ChannelEnum.fromValue(value);
            }
        }
    }

    public static final String SERIALIZED_NAME_CHANNEL = "channel";

    @SerializedName(SERIALIZED_NAME_CHANNEL)
    private ChannelEnum channel = ChannelEnum.LINK;

    public static final String SERIALIZED_NAME_CARD_NUMBER = "card_number";

    @SerializedName(SERIALIZED_NAME_CARD_NUMBER)
    private String cardNumber;

    public static final String SERIALIZED_NAME_CARD_HOLDER_NAME = "card_holder_name";

    @SerializedName(SERIALIZED_NAME_CARD_HOLDER_NAME)
    private String cardHolderName;

    public static final String SERIALIZED_NAME_CARD_EXPIRY_MM = "card_expiry_mm";

    @SerializedName(SERIALIZED_NAME_CARD_EXPIRY_MM)
    private String cardExpiryMm;

    public static final String SERIALIZED_NAME_CARD_EXPIRY_YY = "card_expiry_yy";

    @SerializedName(SERIALIZED_NAME_CARD_EXPIRY_YY)
    private String cardExpiryYy;

    public static final String SERIALIZED_NAME_CARD_CVV = "card_cvv";

    @SerializedName(SERIALIZED_NAME_CARD_CVV)
    private String cardCvv;

    public static final String SERIALIZED_NAME_CARD_ALIAS = "card_alias";

    @SerializedName(SERIALIZED_NAME_CARD_ALIAS)
    private String cardAlias;

    /**
     * Card bank name, required for EMI payments. This is the bank user has selected for EMI. One of
     * [\"Kotak\", \"ICICI\", \"RBL\", \"BOB\",
     * \"Standard Chartered\", \"HDFC\"]
     */
    @JsonAdapter(CardBankNameEnum.Adapter.class)
    public enum CardBankNameEnum {
        KOTAK("Kotak"),

        ICICI("ICICI"),

        RBL("RBL"),

        BOB("BOB"),

        STANDARD_CHARTERED("Standard Chartered"),

        HDFC("HDFC");

        private String value;

        CardBankNameEnum(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        @Override
        public String toString() {
            return String.valueOf(value);
        }

        public static CardBankNameEnum fromValue(String value) {
            for (CardBankNameEnum b : CardBankNameEnum.values()) {
                if (b.value.equals(value)) {
                    return b;
                }
            }
            throw new IllegalArgumentException("Unexpected value '" + value + "'");
        }

        public static class Adapter extends TypeAdapter {
            @Override
            public void write(final JsonWriter jsonWriter, final CardBankNameEnum enumeration)
                    throws IOException {
                jsonWriter.value(enumeration.getValue());
            }

            @Override
            public CardBankNameEnum read(final JsonReader jsonReader) throws IOException {
                String value = jsonReader.nextString();
                return CardBankNameEnum.fromValue(value);
            }
        }
    }

    public static final String SERIALIZED_NAME_CARD_BANK_NAME = "card_bank_name";

    @SerializedName(SERIALIZED_NAME_CARD_BANK_NAME)
    private CardBankNameEnum cardBankName;

    public static final String SERIALIZED_NAME_EMI_TENURE = "emi_tenure";

    @SerializedName(SERIALIZED_NAME_EMI_TENURE)
    private Integer emiTenure;

    public CFCardEMI() {}

    public CFCardEMI channel(ChannelEnum channel) {

        this.channel = channel;
        return this;
    }

    /**
     * The channel for card payments will always be \"link\"
     *
     * @return channel
     */
    @javax.annotation.Nonnull
    public ChannelEnum getChannel() {
        return channel;
    }

    public void setChannel(ChannelEnum channel) {
        this.channel = channel;
    }

    public CFCardEMI cardNumber(String cardNumber) {

        this.cardNumber = cardNumber;
        return this;
    }

    /**
     * Customer card number.
     *
     * @return cardNumber
     */
    @javax.annotation.Nonnull
    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    public CFCardEMI cardHolderName(String cardHolderName) {

        this.cardHolderName = cardHolderName;
        return this;
    }

    /**
     * Customer name mentioned on the card.
     *
     * @return cardHolderName
     */
    @javax.annotation.Nullable
    public String getCardHolderName() {
        return cardHolderName;
    }

    public void setCardHolderName(String cardHolderName) {
        this.cardHolderName = cardHolderName;
    }

    public CFCardEMI cardExpiryMm(String cardExpiryMm) {

        this.cardExpiryMm = cardExpiryMm;
        return this;
    }

    /**
     * Card expiry month.
     *
     * @return cardExpiryMm
     */
    @javax.annotation.Nonnull
    public String getCardExpiryMm() {
        return cardExpiryMm;
    }

    public void setCardExpiryMm(String cardExpiryMm) {
        this.cardExpiryMm = cardExpiryMm;
    }

    public CFCardEMI cardExpiryYy(String cardExpiryYy) {

        this.cardExpiryYy = cardExpiryYy;
        return this;
    }

    /**
     * Card expiry year.
     *
     * @return cardExpiryYy
     */
    @javax.annotation.Nonnull
    public String getCardExpiryYy() {
        return cardExpiryYy;
    }

    public void setCardExpiryYy(String cardExpiryYy) {
        this.cardExpiryYy = cardExpiryYy;
    }

    public CFCardEMI cardCvv(String cardCvv) {

        this.cardCvv = cardCvv;
        return this;
    }

    /**
     * CVV mentioned on the card.
     *
     * @return cardCvv
     */
    @javax.annotation.Nonnull
    public String getCardCvv() {
        return cardCvv;
    }

    public void setCardCvv(String cardCvv) {
        this.cardCvv = cardCvv;
    }

    public CFCardEMI cardAlias(String cardAlias) {

        this.cardAlias = cardAlias;
        return this;
    }

    /**
     * Card alias as returned by Cashfree Vault API
     *
     * @return cardAlias
     */
    @javax.annotation.Nullable
    public String getCardAlias() {
        return cardAlias;
    }

    public void setCardAlias(String cardAlias) {
        this.cardAlias = cardAlias;
    }

    public CFCardEMI cardBankName(CardBankNameEnum cardBankName) {

        this.cardBankName = cardBankName;
        return this;
    }

    /**
     * Card bank name, required for EMI payments. This is the bank user has selected for EMI. One of
     * [\"Kotak\", \"ICICI\", \"RBL\", \"BOB\",
     * \"Standard Chartered\", \"HDFC\"]
     *
     * @return cardBankName
     */
    @javax.annotation.Nonnull
    public CardBankNameEnum getCardBankName() {
        return cardBankName;
    }

    public void setCardBankName(CardBankNameEnum cardBankName) {
        this.cardBankName = cardBankName;
    }

    public CFCardEMI emiTenure(Integer emiTenure) {

        this.emiTenure = emiTenure;
        return this;
    }

    /**
     * EMI tenure selected by the user
     *
     * @return emiTenure
     */
    @javax.annotation.Nonnull
    public Integer getEmiTenure() {
        return emiTenure;
    }

    public void setEmiTenure(Integer emiTenure) {
        this.emiTenure = emiTenure;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CFCardEMI cfCardEMI = (CFCardEMI) o;
        return Objects.equals(this.channel, cfCardEMI.channel)
                && Objects.equals(this.cardNumber, cfCardEMI.cardNumber)
                && Objects.equals(this.cardHolderName, cfCardEMI.cardHolderName)
                && Objects.equals(this.cardExpiryMm, cfCardEMI.cardExpiryMm)
                && Objects.equals(this.cardExpiryYy, cfCardEMI.cardExpiryYy)
                && Objects.equals(this.cardCvv, cfCardEMI.cardCvv)
                && Objects.equals(this.cardAlias, cfCardEMI.cardAlias)
                && Objects.equals(this.cardBankName, cfCardEMI.cardBankName)
                && Objects.equals(this.emiTenure, cfCardEMI.emiTenure);
    }

    @Override
    public int hashCode() {
        return Objects.hash(
                channel,
                cardNumber,
                cardHolderName,
                cardExpiryMm,
                cardExpiryYy,
                cardCvv,
                cardAlias,
                cardBankName,
                emiTenure);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class CFCardEMI {\n");
        sb.append("    channel: ").append(toIndentedString(channel)).append("\n");
        sb.append("    cardNumber: ").append(toIndentedString(cardNumber)).append("\n");
        sb.append("    cardHolderName: ").append(toIndentedString(cardHolderName)).append("\n");
        sb.append("    cardExpiryMm: ").append(toIndentedString(cardExpiryMm)).append("\n");
        sb.append("    cardExpiryYy: ").append(toIndentedString(cardExpiryYy)).append("\n");
        sb.append("    cardCvv: ").append(toIndentedString(cardCvv)).append("\n");
        sb.append("    cardAlias: ").append(toIndentedString(cardAlias)).append("\n");
        sb.append("    cardBankName: ").append(toIndentedString(cardBankName)).append("\n");
        sb.append("    emiTenure: ").append(toIndentedString(emiTenure)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    /**
     * Convert the given object to string with each line indented by 4 spaces (except the first
     * line).
     */
    private String toIndentedString(Object o) {
        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n    ");
    }

    public static HashSet openapiFields;
    public static HashSet openapiRequiredFields;

    static {
        // a set of all properties/fields (JSON key names)
        openapiFields = new HashSet();
        openapiFields.add("channel");
        openapiFields.add("card_number");
        openapiFields.add("card_holder_name");
        openapiFields.add("card_expiry_mm");
        openapiFields.add("card_expiry_yy");
        openapiFields.add("card_cvv");
        openapiFields.add("card_alias");
        openapiFields.add("card_bank_name");
        openapiFields.add("emi_tenure");

        // a set of required properties/fields (JSON key names)
        openapiRequiredFields = new HashSet();
        openapiRequiredFields.add("channel");
        openapiRequiredFields.add("card_number");
        openapiRequiredFields.add("card_expiry_mm");
        openapiRequiredFields.add("card_expiry_yy");
        openapiRequiredFields.add("card_cvv");
        openapiRequiredFields.add("card_bank_name");
        openapiRequiredFields.add("emi_tenure");
    }

    /**
     * Validates the JSON Object and throws an exception if issues found
     *
     * @param jsonObj JSON Object
     * @throws IOException if the JSON Object is invalid with respect to CFCardEMI
     */
    public static void validateJsonObject(JsonObject jsonObj) throws IOException {
        if (jsonObj == null) {
            if (!CFCardEMI.openapiRequiredFields
                    .isEmpty()) { // has required fields but JSON object is null
                throw new IllegalArgumentException(
                        String.format(
                                "The required field(s) %s in CFCardEMI is not found in the empty"
                                        + " JSON string",
                                CFCardEMI.openapiRequiredFields.toString()));
            }
        }

        Set> entries = jsonObj.entrySet();
        // check to see if the JSON string contains additional fields
        for (Entry entry : entries) {
            if (!CFCardEMI.openapiFields.contains(entry.getKey())) {
                throw new IllegalArgumentException(
                        String.format(
                                "The field `%s` in the JSON string is not defined in the"
                                        + " `CFCardEMI` properties. JSON: %s",
                                entry.getKey(), jsonObj.toString()));
            }
        }

        // check to make sure all required properties/fields are present in the JSON string
        for (String requiredField : CFCardEMI.openapiRequiredFields) {
            if (jsonObj.get(requiredField) == null) {
                throw new IllegalArgumentException(
                        String.format(
                                "The required field `%s` is not found in the JSON string: %s",
                                requiredField, jsonObj.toString()));
            }
        }
        if (!jsonObj.get("channel").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `channel` to be a primitive type in the JSON"
                                    + " string but got `%s`",
                            jsonObj.get("channel").toString()));
        }
        if (!jsonObj.get("card_number").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_number` to be a primitive type in the JSON"
                                    + " string but got `%s`",
                            jsonObj.get("card_number").toString()));
        }
        if ((jsonObj.get("card_holder_name") != null
                        && !jsonObj.get("card_holder_name").isJsonNull())
                && !jsonObj.get("card_holder_name").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_holder_name` to be a primitive type in the"
                                    + " JSON string but got `%s`",
                            jsonObj.get("card_holder_name").toString()));
        }
        if (!jsonObj.get("card_expiry_mm").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_expiry_mm` to be a primitive type in the"
                                    + " JSON string but got `%s`",
                            jsonObj.get("card_expiry_mm").toString()));
        }
        if (!jsonObj.get("card_expiry_yy").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_expiry_yy` to be a primitive type in the"
                                    + " JSON string but got `%s`",
                            jsonObj.get("card_expiry_yy").toString()));
        }
        if (!jsonObj.get("card_cvv").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_cvv` to be a primitive type in the JSON"
                                    + " string but got `%s`",
                            jsonObj.get("card_cvv").toString()));
        }
        if ((jsonObj.get("card_alias") != null && !jsonObj.get("card_alias").isJsonNull())
                && !jsonObj.get("card_alias").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_alias` to be a primitive type in the JSON"
                                    + " string but got `%s`",
                            jsonObj.get("card_alias").toString()));
        }
        if (!jsonObj.get("card_bank_name").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `card_bank_name` to be a primitive type in the"
                                    + " JSON string but got `%s`",
                            jsonObj.get("card_bank_name").toString()));
        }
    }

    public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
        @SuppressWarnings("unchecked")
        @Override
        public  TypeAdapter create(Gson gson, TypeToken type) {
            if (!CFCardEMI.class.isAssignableFrom(type.getRawType())) {
                return null; // this class only serializes 'CFCardEMI' and its subtypes
            }
            final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
            final TypeAdapter thisAdapter =
                    gson.getDelegateAdapter(this, TypeToken.get(CFCardEMI.class));

            return (TypeAdapter)
                    new TypeAdapter() {
                        @Override
                        public void write(JsonWriter out, CFCardEMI value) throws IOException {
                            JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
                            elementAdapter.write(out, obj);
                        }

                        @Override
                        public CFCardEMI read(JsonReader in) throws IOException {
                            JsonObject jsonObj = elementAdapter.read(in).getAsJsonObject();
                            validateJsonObject(jsonObj);
                            return thisAdapter.fromJsonTree(jsonObj);
                        }
                    }.nullSafe();
        }
    }

    /**
     * Create an instance of CFCardEMI given an JSON string
     *
     * @param jsonString JSON string
     * @return An instance of CFCardEMI
     * @throws IOException if the JSON string is invalid with respect to CFCardEMI
     */
    public static CFCardEMI fromJson(String jsonString) throws IOException {
        return JSON.getGson().fromJson(jsonString, CFCardEMI.class);
    }

    /**
     * Convert an instance of CFCardEMI to an JSON string
     *
     * @return JSON string
     */
    public String toJson() {
        return JSON.getGson().toJson(this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy