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

me.pagar.model.Payable Maven / Gradle / Ivy

The newest version!
package me.pagar.model;

import java.math.BigInteger;
import java.util.Collection;
import java.util.Date;

import javax.ws.rs.HttpMethod;

import org.joda.time.DateTime;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;

import me.pagar.model.Transaction.PaymentMethod;
import me.pagar.model.filter.QueriableFields;
import me.pagar.util.JSONUtils;

public class Payable extends PagarMeModel {

    @Expose(serialize = false)
    private Integer amount;

    @Expose(serialize = false)
    private Integer fee;

    @Expose(serialize = false)
    private Integer installment;

    @Expose(serialize = false)
    private BigInteger transactionId;

    @Expose(serialize = false)
    private String splitRuleId;

    @Expose(serialize = false)
    private DateTime paymentDate;

    @Expose(serialize = false)
    private Status status;

    @Expose(serialize = false)
    private Type type;

    @Expose
    private String recipientId;

    @Expose
    private String anticipationFee;

    @Expose
    private String bulkAnticipationId;

    @Expose
    private Date originalPaymentDate;

    @Expose
    private Date accrualDate;

    @Expose
    private PaymentMethod paymentMethod;

    public Payable() {
        super();
    }

    public Payable find(BigInteger id) throws PagarMeException {

        final PagarMeRequest request = new PagarMeRequest(HttpMethod.GET, String.format("/%s/%s", getClassName(), id));

        final Payable other = JSONUtils.getAsObject((JsonObject) request.execute(), Payable.class);
        copy(other);
        flush();

        return other;
    }

    public Collection findCollection(final Integer totalPerPage, Integer page) throws PagarMeException {
        JsonArray response = super.paginate(totalPerPage, page);
        return JSONUtils.getAsList(response, new TypeToken>() {
        }.getType());
    }

    public Collection findCollection(final Integer totalPerPage, Integer page, QueriableFields payableFilter) throws PagarMeException {
        JsonArray response = super.paginate(totalPerPage, page, payableFilter);
        return JSONUtils.getAsList(response, new TypeToken>() {
        }.getType());
    }

    private void copy(Payable other) {
        super.copy(other);
        this.amount = other.amount;
        this.anticipationFee = other.anticipationFee;
        this.bulkAnticipationId = other.bulkAnticipationId;
        this.fee = other.fee;
        this.installment = other.installment;
        this.originalPaymentDate = other.originalPaymentDate;
        this.paymentDate = other.paymentDate;
        this.paymentMethod = other.paymentMethod;
        this.recipientId = other.recipientId;
        this.splitRuleId = other.splitRuleId;
        this.status = other.status;
        this.transactionId = other.transactionId;
        this.type = other.type;
        this.accrualDate = other.accrualDate;
    }

    @Override
    public void setId(BigInteger id) {
        throw new UnsupportedOperationException("Not allowed.");
    }

    public Integer getAmount() {
        return amount;
    }

    public Integer getFee() {
        return fee;
    }

    public Integer getInstallment() {
        return installment;
    }

    public BigInteger getTransactionId() {
        return transactionId;
    }

    public String getSplitRuleId() {
        return splitRuleId;
    }
    
    @Deprecated
    public DateTime getPayment(){
        return paymentDate;
    }

    public DateTime getPaymentDate() {
        return paymentDate;
    }

    public Status getStatus() {
        return status;
    }

    public Type getType() {
        return type;
    }

    public String getRecipientId() {
        return recipientId;
    }

    public String getAnticipationFee() {
        return anticipationFee;
    }

    public String getBulkAnticipationId() {
        return bulkAnticipationId;
    }

    public Date getOriginalPaymentDate() {
        return originalPaymentDate;
    }

    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public void setFee(Integer fee) {
        this.fee = fee;
    }

    public void setInstallment(Integer installment) {
        this.installment = installment;
    }

    public void setTransactionId(BigInteger transactionId) {
        this.transactionId = transactionId;
    }

    public void setSplitRuleId(String splitRuleId) {
        this.splitRuleId = splitRuleId;
    }

    public void setPaymentDate(DateTime paymentDate) {
        this.paymentDate = paymentDate;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public void setRecipientId(String recipientId) {
        this.recipientId = recipientId;
    }

    public void setAnticipationFee(String anticipationFee) {
        this.anticipationFee = anticipationFee;
    }

    public void setBulkAnticipationId(String bulkAnticipationId) {
        this.bulkAnticipationId = bulkAnticipationId;
    }

    public void setOriginalPaymentDate(Date originalPaymentDate) {
        this.originalPaymentDate = originalPaymentDate;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public Date getAccrualDate() {
        return accrualDate;
    }

    public void setAccrualDate(Date accrualDate) {
        this.accrualDate = accrualDate;
    }

    @Override
    public void setClassName(String className) {
        throw new UnsupportedOperationException("Not allowed.");
    }

    public enum Status {

        @SerializedName("paid")
        PAID,

        @SerializedName("waiting_funds")
        WAITING_FUNDS,
        
        @SerializedName("suspended")
        SUSPENDED,

        @SerializedName("prepaid")
        PREPAID
        
    }

    public enum Type {

        @SerializedName("chargeback_refund")
        CHARGEBACK_REFUND, 
        
        @SerializedName("chargeback")
        CHARGEBACK,

        @SerializedName("credit")
        CREDIT,

        @SerializedName("refund")
        REFUND

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy