Subversion Repositories SmartDukaan

Rev

Rev 2976 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.payment.persistence;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

import in.shop2020.payment.domain.Payment;
import in.shop2020.payment.domain.PaymentAttribute;

public interface PaymentMapper {
        int insertPayment(Payment payment);
        
        void updatePayment(Payment payment);

        // TODO: All getPayment methods currently employ the simple N+1 strategy to
        // load the attributes. This is not desirable. Instead, more labour should
        // be spent into writing the long result maps which will use a single query.
        Payment getPayment(long id);
        
        List<Payment> getPaymentsForUser(@Param("userId") long userId,
                        @Param("fromTime") String fromTime, @Param("toTime") String toTime,
                        @Param("status") int status, @Param("gatewayId") long gatewayId);
        
        List<Payment> getPayments(@Param("fromTime") String fromTime, @Param("toTime") String toTime,
                        @Param("status") int status, @Param("gatewayId") long gatewayId);

        List<Payment> getPaymentsByCapturedDate(@Param("fromTime") String fromTime, @Param("toTime") String toTime,
                        @Param("status") int status, @Param("gatewayId") long gatewayId);
    /**
     * Currently, it returns the last payment for a transaction assuming that
     * it is the only one which can be successful.
     * 
     * @param merchantTxnId
     *            The merchant transaction for which payments are required.
     * @return A list of payments
     */
        List<Payment> getPaymentForTxn(long merchantTxnId);

    /**
     * Finds the maximum and minimum amount among the successful payments.
     * 
     * @return A map containing the maximum and minimum amount keyed using MAX
     *         and MIN as keys respectively.
     */
        Map<String, Float> getMinMaxPaymentAmount();

    /**
     * Get the list of attributes of a payment.
     * 
     * @param id
     *            Id of the payment whose attributes are required.
     * @return A list of all the attributes of a payment.
     */
        List<PaymentAttribute> getAttributesForPayment(long id);

    /**
     * Inserts an attribute for the given payments. If the attribute is already
     * present, just updates its value.
     * 
     * @param paymentId
     *            Id of the payment for which the attribute has to be added or
     *            updated.
     * @param name
     *            Name of the attribute
     * @param value
     *            Value of the attribute
     */
        void insertPaymentAttribute(@Param("paymentId") long paymentId,
                        @Param("name") String name, @Param("value") String value);
}