@Test public void testGetOrderAmountCaptureNotOk() { service.create(createCustomerOrderPayment(new BigDecimal("223.00"), "C-PR-223-45", "C-PR-223-45-0", PaymentGateway.CAPTURE, Payment.PAYMENT_STATUS_PROCESSING)); service.create(createCustomerOrderPayment(new BigDecimal("0.45"), "C-PR-223-45", "C-PR-223-45-1", PaymentGateway.CAPTURE, Payment.PAYMENT_STATUS_OK)); assertEquals("0.45", service.getOrderAmount("C-PR-223-45").toPlainString()); }
@Override public BigDecimal getOrderAmount(final String orderNumber) { final List<CustomerOrderPayment> payments = findPayments(orderNumber, null, new String[] { Payment.PAYMENT_STATUS_OK }, new String[] { PaymentGateway.AUTH_CAPTURE, PaymentGateway.CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND }); BigDecimal credit = BigDecimal.ZERO; BigDecimal debit = BigDecimal.ZERO; BigDecimal voided = BigDecimal.ZERO; List<BigDecimal> credited = new ArrayList<>(); for (CustomerOrderPayment payment : payments) { if (PaymentGateway.AUTH_CAPTURE.equals(payment.getTransactionOperation()) || PaymentGateway.CAPTURE.equals(payment.getTransactionOperation())) { credit = credit.add(payment.getPaymentAmount()); credited.add(payment.getPaymentAmount()); } } for (CustomerOrderPayment payment : payments) { if (PaymentGateway.REFUND.equals(payment.getTransactionOperation())) { debit = debit.add(payment.getPaymentAmount()); } else if (PaymentGateway.VOID_CAPTURE.equals(payment.getTransactionOperation())) { final Iterator<BigDecimal> creditedIt = credited.iterator(); while (creditedIt.hasNext()) { if (creditedIt.next().compareTo(payment.getPaymentAmount()) == 0) { debit = debit.add(payment.getPaymentAmount()); creditedIt.remove(); } } } } return credit.subtract(debit).setScale(DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); }
CustomerOrderPaymentServiceImpl extends PaymentModuleGenericServiceImpl<CustomerOrderPayment> implements CustomerOrderPaymentService { @Override public BigDecimal getOrderAmount(final String orderNumber) { final List<CustomerOrderPayment> payments = findPayments(orderNumber, null, new String[] { Payment.PAYMENT_STATUS_OK }, new String[] { PaymentGateway.AUTH_CAPTURE, PaymentGateway.CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND }); BigDecimal credit = BigDecimal.ZERO; BigDecimal debit = BigDecimal.ZERO; BigDecimal voided = BigDecimal.ZERO; List<BigDecimal> credited = new ArrayList<>(); for (CustomerOrderPayment payment : payments) { if (PaymentGateway.AUTH_CAPTURE.equals(payment.getTransactionOperation()) || PaymentGateway.CAPTURE.equals(payment.getTransactionOperation())) { credit = credit.add(payment.getPaymentAmount()); credited.add(payment.getPaymentAmount()); } } for (CustomerOrderPayment payment : payments) { if (PaymentGateway.REFUND.equals(payment.getTransactionOperation())) { debit = debit.add(payment.getPaymentAmount()); } else if (PaymentGateway.VOID_CAPTURE.equals(payment.getTransactionOperation())) { final Iterator<BigDecimal> creditedIt = credited.iterator(); while (creditedIt.hasNext()) { if (creditedIt.next().compareTo(payment.getPaymentAmount()) == 0) { debit = debit.add(payment.getPaymentAmount()); creditedIt.remove(); } } } } return credit.subtract(debit).setScale(DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); } }
CustomerOrderPaymentServiceImpl extends PaymentModuleGenericServiceImpl<CustomerOrderPayment> implements CustomerOrderPaymentService { @Override public BigDecimal getOrderAmount(final String orderNumber) { final List<CustomerOrderPayment> payments = findPayments(orderNumber, null, new String[] { Payment.PAYMENT_STATUS_OK }, new String[] { PaymentGateway.AUTH_CAPTURE, PaymentGateway.CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND }); BigDecimal credit = BigDecimal.ZERO; BigDecimal debit = BigDecimal.ZERO; BigDecimal voided = BigDecimal.ZERO; List<BigDecimal> credited = new ArrayList<>(); for (CustomerOrderPayment payment : payments) { if (PaymentGateway.AUTH_CAPTURE.equals(payment.getTransactionOperation()) || PaymentGateway.CAPTURE.equals(payment.getTransactionOperation())) { credit = credit.add(payment.getPaymentAmount()); credited.add(payment.getPaymentAmount()); } } for (CustomerOrderPayment payment : payments) { if (PaymentGateway.REFUND.equals(payment.getTransactionOperation())) { debit = debit.add(payment.getPaymentAmount()); } else if (PaymentGateway.VOID_CAPTURE.equals(payment.getTransactionOperation())) { final Iterator<BigDecimal> creditedIt = credited.iterator(); while (creditedIt.hasNext()) { if (creditedIt.next().compareTo(payment.getPaymentAmount()) == 0) { debit = debit.add(payment.getPaymentAmount()); creditedIt.remove(); } } } } return credit.subtract(debit).setScale(DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); } CustomerOrderPaymentServiceImpl(final PaymentModuleGenericDAO<CustomerOrderPayment, Long> genericDao); }
CustomerOrderPaymentServiceImpl extends PaymentModuleGenericServiceImpl<CustomerOrderPayment> implements CustomerOrderPaymentService { @Override public BigDecimal getOrderAmount(final String orderNumber) { final List<CustomerOrderPayment> payments = findPayments(orderNumber, null, new String[] { Payment.PAYMENT_STATUS_OK }, new String[] { PaymentGateway.AUTH_CAPTURE, PaymentGateway.CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND }); BigDecimal credit = BigDecimal.ZERO; BigDecimal debit = BigDecimal.ZERO; BigDecimal voided = BigDecimal.ZERO; List<BigDecimal> credited = new ArrayList<>(); for (CustomerOrderPayment payment : payments) { if (PaymentGateway.AUTH_CAPTURE.equals(payment.getTransactionOperation()) || PaymentGateway.CAPTURE.equals(payment.getTransactionOperation())) { credit = credit.add(payment.getPaymentAmount()); credited.add(payment.getPaymentAmount()); } } for (CustomerOrderPayment payment : payments) { if (PaymentGateway.REFUND.equals(payment.getTransactionOperation())) { debit = debit.add(payment.getPaymentAmount()); } else if (PaymentGateway.VOID_CAPTURE.equals(payment.getTransactionOperation())) { final Iterator<BigDecimal> creditedIt = credited.iterator(); while (creditedIt.hasNext()) { if (creditedIt.next().compareTo(payment.getPaymentAmount()) == 0) { debit = debit.add(payment.getPaymentAmount()); creditedIt.remove(); } } } } return credit.subtract(debit).setScale(DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); } CustomerOrderPaymentServiceImpl(final PaymentModuleGenericDAO<CustomerOrderPayment, Long> genericDao); @Override BigDecimal getOrderAmount(final String orderNumber); @Override List<CustomerOrderPayment> findPayments(final int start, final int offset, final String sort, final boolean sortDescending, final Set<String> shops, final Map<String, List> filter); @Override int findCustomerOrderPaymentCount(final Set<String> shops, final Map<String, List> filter); @Override List<CustomerOrderPayment> findPayments(final String orderNumber,
                                                   final String shipmentNumber,
                                                   final String paymentProcessorResult,
                                                   final String transactionOperation); @Override List<CustomerOrderPayment> findPayments(final String orderNumber,
                                                   final String shipmentNumber,
                                                   final String[] paymentProcessorResult,
                                                   final String[] transactionOperation); }
CustomerOrderPaymentServiceImpl extends PaymentModuleGenericServiceImpl<CustomerOrderPayment> implements CustomerOrderPaymentService { @Override public BigDecimal getOrderAmount(final String orderNumber) { final List<CustomerOrderPayment> payments = findPayments(orderNumber, null, new String[] { Payment.PAYMENT_STATUS_OK }, new String[] { PaymentGateway.AUTH_CAPTURE, PaymentGateway.CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND }); BigDecimal credit = BigDecimal.ZERO; BigDecimal debit = BigDecimal.ZERO; BigDecimal voided = BigDecimal.ZERO; List<BigDecimal> credited = new ArrayList<>(); for (CustomerOrderPayment payment : payments) { if (PaymentGateway.AUTH_CAPTURE.equals(payment.getTransactionOperation()) || PaymentGateway.CAPTURE.equals(payment.getTransactionOperation())) { credit = credit.add(payment.getPaymentAmount()); credited.add(payment.getPaymentAmount()); } } for (CustomerOrderPayment payment : payments) { if (PaymentGateway.REFUND.equals(payment.getTransactionOperation())) { debit = debit.add(payment.getPaymentAmount()); } else if (PaymentGateway.VOID_CAPTURE.equals(payment.getTransactionOperation())) { final Iterator<BigDecimal> creditedIt = credited.iterator(); while (creditedIt.hasNext()) { if (creditedIt.next().compareTo(payment.getPaymentAmount()) == 0) { debit = debit.add(payment.getPaymentAmount()); creditedIt.remove(); } } } } return credit.subtract(debit).setScale(DEFAULT_SCALE, BigDecimal.ROUND_HALF_UP); } CustomerOrderPaymentServiceImpl(final PaymentModuleGenericDAO<CustomerOrderPayment, Long> genericDao); @Override BigDecimal getOrderAmount(final String orderNumber); @Override List<CustomerOrderPayment> findPayments(final int start, final int offset, final String sort, final boolean sortDescending, final Set<String> shops, final Map<String, List> filter); @Override int findCustomerOrderPaymentCount(final Set<String> shops, final Map<String, List> filter); @Override List<CustomerOrderPayment> findPayments(final String orderNumber,
                                                   final String shipmentNumber,
                                                   final String paymentProcessorResult,
                                                   final String transactionOperation); @Override List<CustomerOrderPayment> findPayments(final String orderNumber,
                                                   final String shipmentNumber,
                                                   final String[] paymentProcessorResult,
                                                   final String[] transactionOperation);  }