public PayByIdResponse payById(PayByIdRequest request) { PayByIdResponse response = new PayByIdResponse(); response.setSuccess(false); Long paymentId; try { paymentId = Long.valueOf(request.getPaymentId()); } catch (NumberFormatException e) { return response; } Customer customer = customerDao.get(request.getCustomerId()); if (customer == null) { return response; } Payment payment = paymentDao.get(paymentId); payment.setCustomer(customer); payment.setScore(request.getScore()); payment.setComment(request.getComment()); payment.setStatus(PaymentStatus.DONE); // todo add Pending Service Status payment.setPaymentDate(new Date()); payment.setReferenceNumber( payment.getGeneratedPaymentId() + "-" + payment.getDiscount().getId() + "-" + payment.getId()); paymentDao.saveOrUpdate(payment); // todo important must Service call from in bank response.setSuccess(true); return response; }
public GeneratePaymentIdResponse generatePaymentId(GeneratePaymentIdRequest request) { Long merchantId; GeneratePaymentIdResponse response = new GeneratePaymentIdResponse(); try { merchantId = Long.valueOf(request.getMerchantId()); } catch (NumberFormatException e) { return response; } Merchant merchant = merchantDao.get(merchantId); if (merchant == null) { return response; } Payment payment = new Payment(); Discount discount = merchant.getDiscounts().get(0); payment.setDiscount(discount); payment.setCreationDate(new Date()); payment.setAmount(request.getAmount()); payment.setStatus(PaymentStatus.PENDING); paymentDao.saveOrUpdate(payment); response.setPaymentId(String.valueOf(payment.getGeneratedPaymentId())); return response; }