| 1946 |
chandransh |
1 |
package in.shop2020.payment.handler;
|
|
|
2 |
|
|
|
3 |
import java.text.SimpleDateFormat;
|
|
|
4 |
import java.util.Date;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
| 2977 |
chandransh |
7 |
import java.util.Map.Entry;
|
| 1946 |
chandransh |
8 |
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Service;
|
|
|
11 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
12 |
|
|
|
13 |
import in.shop2020.payment.domain.Payment;
|
|
|
14 |
import in.shop2020.payment.persistence.PaymentMapper;
|
| 4141 |
chandransh |
15 |
import in.shop2020.payments.PaymentStatus;
|
| 1946 |
chandransh |
16 |
|
|
|
17 |
@Service
|
|
|
18 |
public class PaymentHandler{
|
|
|
19 |
|
|
|
20 |
@Autowired
|
|
|
21 |
private PaymentMapper paymentMapper;
|
|
|
22 |
|
|
|
23 |
@Transactional
|
|
|
24 |
public long insertPayment(Payment payment){
|
|
|
25 |
paymentMapper.insertPayment(payment);
|
|
|
26 |
return payment.getId();
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
public Payment getPayment(long id){
|
|
|
30 |
return paymentMapper.getPayment(id);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
@Transactional
|
|
|
34 |
public void updatePayment(Payment payment, Map<String, String> attributes){
|
|
|
35 |
paymentMapper.updatePayment(payment);
|
| 2977 |
chandransh |
36 |
for(Entry<String, String> entry: attributes.entrySet()){
|
|
|
37 |
paymentMapper.insertPaymentAttribute(payment.getId(), entry.getKey(), entry.getValue());
|
| 1946 |
chandransh |
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public List<Payment> getPayments(long tFromTime, long tToTime, int status, long gatewayId){
|
|
|
42 |
SimpleDateFormat mysqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
43 |
String fromTime = mysqlDateFormatter.format(new Date(tFromTime));
|
|
|
44 |
String toTime = mysqlDateFormatter.format(new Date(tToTime));
|
| 2279 |
chandransh |
45 |
return paymentMapper.getPayments(fromTime, toTime, status, gatewayId);
|
| 1946 |
chandransh |
46 |
}
|
| 4141 |
chandransh |
47 |
|
|
|
48 |
public List<Payment> getPaymentsByCapturedDate(long tFromTime, long tToTime, long gatewayId){
|
|
|
49 |
SimpleDateFormat mysqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
50 |
String fromTime = mysqlDateFormatter.format(new Date(tFromTime));
|
|
|
51 |
String toTime = mysqlDateFormatter.format(new Date(tToTime));
|
|
|
52 |
return paymentMapper.getPaymentsByCapturedDate(fromTime, toTime, PaymentStatus.SUCCESS.getValue(), gatewayId);
|
|
|
53 |
}
|
| 1946 |
chandransh |
54 |
|
|
|
55 |
public List<Payment> getPaymentsForUser(long userId, long tFromTime, long tToTime, int status, long gatewayId){
|
|
|
56 |
SimpleDateFormat mysqlDateFormatter = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
|
|
|
57 |
String fromTime = mysqlDateFormatter.format(new Date(tFromTime));
|
|
|
58 |
String toTime = mysqlDateFormatter.format(new Date(tToTime));
|
|
|
59 |
return paymentMapper.getPaymentsForUser(userId, fromTime, toTime, status, gatewayId);
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public List<Payment> getPaymentForTxn(long merchantTxnId){
|
|
|
63 |
return paymentMapper.getPaymentForTxn(merchantTxnId);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public Map<String, Float> getMinMaxPaymentAmount(){
|
|
|
67 |
return paymentMapper.getMinMaxPaymentAmount();
|
|
|
68 |
}
|
|
|
69 |
}
|