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

com.adyen.model.Amount Maven / Gradle / Ivy

There is a newer version: 28.4.0
Show newest version
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Java API Library
 *
 * Copyright (c) 2017 Adyen B.V.
 * This file is open source and available under the MIT license.
 * See the LICENSE file for more info.
 */
package com.adyen.model;

import java.math.BigDecimal;
import java.util.Objects;
import com.adyen.Util.Util;
import com.google.gson.annotations.SerializedName;

/**
 * Amount
 */
public class Amount {
    @SerializedName("value")
    private Long value = null;

    @SerializedName("currency")
    private String currency = null;

    public BigDecimal getDecimalValue() {
        BigDecimal amountValue =  BigDecimal.valueOf(getValue(), Util.getDecimalPlaces(getCurrency()));
        return amountValue;
    }

    public Amount value(Long value) {
        this.value = value;
        return this;
    }

    /**
     * the amount's value in minor units
     *
     * @return value
     **/
    public Long getValue() {
        return value;
    }

    public void setValue(Long value) {
        this.value = value;
    }

    public Amount currency(String currency) {
        this.currency = currency;
        return this;
    }

    /**
     * the amount's three letter currency code (ISO 4217)
     *
     * @return currency
     **/
    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Amount amount = (Amount) o;
        return Objects.equals(this.value, amount.value) &&
                Objects.equals(this.currency, amount.currency);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value, currency);
    }


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class Amount {\n");

        sb.append("    value: ").append(toIndentedString(value)).append("\n");
        sb.append("    currency: ").append(toIndentedString(currency)).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    ");
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy