| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller.checkout;
|
1 |
package com.spice.profitmandi.service.wallet;
|
| 2 |
|
- |
|
| 3 |
import java.time.LocalDateTime;
|
- |
|
| 4 |
import java.util.List;
|
- |
|
| 5 |
import java.util.stream.Collectors;
|
- |
|
| 6 |
|
- |
|
| 7 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 8 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 10 |
import org.springframework.stereotype.Component;
|
- |
|
| 11 |
|
2 |
|
| 12 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 13 |
import com.spice.profitmandi.dao.cart.CartService;
|
4 |
import com.spice.profitmandi.dao.cart.CartService;
|
| 14 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
5 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 15 |
import com.spice.profitmandi.dao.entity.transaction.Payment;
|
6 |
import com.spice.profitmandi.dao.entity.transaction.Payment;
|
| 16 |
import com.spice.profitmandi.dao.entity.transaction.Transaction;
|
7 |
import com.spice.profitmandi.dao.entity.transaction.Transaction;
|
| 17 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
8 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 18 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
9 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
| 19 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
10 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
| 20 |
import com.spice.profitmandi.service.order.OrderService;
|
11 |
import com.spice.profitmandi.service.order.OrderService;
|
| 21 |
import com.spice.profitmandi.service.wallet.WalletService;
|
- |
|
| 22 |
|
- |
|
| 23 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
12 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| - |
|
13 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
14 |
import org.apache.logging.log4j.Logger;
|
| - |
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
16 |
import org.springframework.stereotype.Component;
|
| - |
|
17 |
|
| - |
|
18 |
import java.time.LocalDateTime;
|
| - |
|
19 |
import java.util.List;
|
| - |
|
20 |
import java.util.stream.Collectors;
|
| 24 |
|
21 |
|
| 25 |
@Component
|
22 |
@Component
|
| 26 |
public class CommonPaymentService {
|
23 |
public class CommonPaymentService {
|
| 27 |
|
24 |
|
| 28 |
private static final Logger log = LogManager.getLogger(CommonPaymentService.class);
|
25 |
private static final Logger log = LogManager.getLogger(CommonPaymentService.class);
|
| Line 33... |
Line 30... |
| 33 |
@Autowired
|
30 |
@Autowired
|
| 34 |
private OrderRepository orderRepository;
|
31 |
private OrderRepository orderRepository;
|
| 35 |
|
32 |
|
| 36 |
@Autowired
|
33 |
@Autowired
|
| 37 |
private OrderService orderService;
|
34 |
private OrderService orderService;
|
| 38 |
|
35 |
|
| 39 |
@Autowired
|
36 |
@Autowired
|
| 40 |
private TransactionRepository transactionRepository;
|
37 |
private TransactionRepository transactionRepository;
|
| 41 |
|
38 |
|
| 42 |
@Autowired
|
39 |
@Autowired
|
| 43 |
private PaymentRepository paymentRepository;
|
40 |
private PaymentRepository paymentRepository;
|
| 44 |
|
41 |
|
| 45 |
@Autowired
|
42 |
@Autowired
|
| 46 |
private CartService cartService;
|
43 |
private CartService cartService;
|
| 47 |
|
44 |
|
| 48 |
public void payThroughWallet(int transactionId) throws ProfitMandiBusinessException {
|
45 |
public void payThroughWallet(int transactionId) throws ProfitMandiBusinessException {
|
| 49 |
Transaction transaction = transactionRepository.selectById(transactionId);
|
46 |
Transaction transaction = transactionRepository.selectById(transactionId);
|
| 50 |
List<Order> orders = orderRepository.selectAllByTransactionId(transactionId);
|
47 |
List<Order> orders = orderRepository.selectAllByTransactionId(transactionId);
|
| 51 |
double walletAmount = orders.stream().collect(Collectors.summingDouble(Order::getTotalAmount));
|
48 |
double walletAmount = orders.stream().collect(Collectors.summingDouble(Order::getTotalAmount));
|
| 52 |
walletService.consumeAmountFromWallet(transaction.getRetailerId(), transactionId,
|
49 |
walletService.consumeAmountFromWallet(transaction.getRetailerId(), transactionId,
|
| 53 |
WalletReferenceType.PURCHASE, "Against Order purchase", (float)walletAmount, LocalDateTime.now());
|
50 |
WalletReferenceType.PURCHASE, "Against Order purchase", (float) walletAmount, LocalDateTime.now());
|
| 54 |
this.addPayment(transaction, walletAmount);
|
51 |
this.addPayment(transaction, walletAmount);
|
| 55 |
|
52 |
|
| 56 |
//
|
53 |
//
|
| 57 |
}
|
54 |
}
|
| 58 |
|
55 |
|
| 59 |
private void addPayment(Transaction transaction, double walletAmount) {
|
56 |
private void addPayment(Transaction transaction, double walletAmount) {
|
| 60 |
Payment payment = new Payment();
|
57 |
Payment payment = new Payment();
|
| 61 |
payment.setAmount(walletAmount);
|
58 |
payment.setAmount(walletAmount);
|
| 62 |
payment.setGatewayId(8);
|
59 |
payment.setGatewayId(8);
|
| 63 |
payment.setStatus(2);
|
60 |
payment.setStatus(2);
|