Subversion Repositories SmartDukaan

Rev

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

package in.shop2020.payment.handler;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import in.shop2020.payment.domain.Payment;
import in.shop2020.payment.persistence.PaymentMapper;
import in.shop2020.payments.PaymentStatus;

@Service
public class PaymentHandler{
        
        @Autowired
        private PaymentMapper paymentMapper;
        
        @Transactional
        public long insertPayment(Payment payment){
                paymentMapper.insertPayment(payment);
                return payment.getId();
        }
        
        public Payment getPayment(long id){
                return paymentMapper.getPayment(id);
        }
        
        @Transactional
        public void updatePayment(Payment payment, Map<String, String> attributes){
                paymentMapper.updatePayment(payment);
                for(Entry<String, String> entry: attributes.entrySet()){
                        paymentMapper.insertPaymentAttribute(payment.getId(), entry.getKey(), entry.getValue());
                }
        }
        
        public List<Payment> getPayments(long tFromTime, long tToTime, int status, long gatewayId){
                SimpleDateFormat mysqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                String fromTime = mysqlDateFormatter.format(new Date(tFromTime));
                String toTime = mysqlDateFormatter.format(new Date(tToTime));
                return paymentMapper.getPayments(fromTime, toTime, status, gatewayId);
        }

        public List<Payment> getPaymentsByCapturedDate(long tFromTime, long tToTime, long gatewayId){
                SimpleDateFormat mysqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                String fromTime = mysqlDateFormatter.format(new Date(tFromTime));
                String toTime = mysqlDateFormatter.format(new Date(tToTime));
                return paymentMapper.getPaymentsByCapturedDate(fromTime, toTime, PaymentStatus.SUCCESS.getValue(), gatewayId);
        }
        
        public List<Payment> getPaymentsForUser(long userId, long tFromTime, long tToTime, int status, long gatewayId){
                SimpleDateFormat mysqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
                String fromTime = mysqlDateFormatter.format(new Date(tFromTime));
                String toTime = mysqlDateFormatter.format(new Date(tToTime));
                return paymentMapper.getPaymentsForUser(userId, fromTime, toTime, status, gatewayId);
        }
        
        public List<Payment> getPaymentForTxn(long merchantTxnId){
                return paymentMapper.getPaymentForTxn(merchantTxnId);
        }
        
        public List<Payment> getPaymentForRechargeTxn(long merchantTxnId){
        return paymentMapper.getPaymentForRechargeTxn(merchantTxnId);
    }
        
        public Map<String, Float> getMinMaxPaymentAmount(){
                return paymentMapper.getMinMaxPaymentAmount();
        }
}