CancelOrderWithRefundOrderEventHandlerImpl extends CancelOrderEventHandlerImpl implements OrderEventHandler { @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { synchronized (OrderEventHandler.syncMonitor) { final CustomerOrder order = orderEvent.getCustomerOrder(); final Shop pgShop = order.getShop().getMaster() != null ? order.getShop().getMaster() : order.getShop(); final PaymentProcessor paymentProcessor = paymentProcessorFactory.create(order.getPgLabel(), pgShop.getCode()); if (!paymentProcessor.isPaymentGatewayEnabled()) { throw new PGDisabledException("PG " + order.getPgLabel() + " is disabled in " + order.getShop().getCode(), order.getPgLabel()); } if (paymentProcessor.getPaymentGateway().getPaymentGatewayFeatures().isOnlineGateway()) { creditQuantity(orderEvent); final String resultCancel = paymentProcessor.cancelOrder(order, isForceProcessing(orderEvent), Collections.emptyMap()); if (!Payment.PAYMENT_STATUS_OK.equals(resultCancel)) { orderEvent.getRuntimeParams().put("cancelFailed", Boolean.TRUE); } } else { final String resultCancel = paymentProcessor.cancelOrder(order, isForceProcessing(orderEvent), Collections.emptyMap()); if (!Payment.PAYMENT_STATUS_OK.equals(resultCancel)) { return false; } creditQuantity(orderEvent); } handleInternal(orderEvent); return true; } } CancelOrderWithRefundOrderEventHandlerImpl(final PaymentProcessorFactory paymentProcessorFactory,
                                                      final WarehouseService warehouseService,
                                                      final InventoryResolver inventoryResolver,
                                                      final ProductService productService); @Override boolean handle(final OrderEvent orderEvent);  }
@Test public void testHandleStandardPaymentProcessingOnlineAuth() throws Exception { configureTestPG(true, true, TestPaymentGatewayImpl.PROCESSING); String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertSinglePaymentEntry(customerOrder.getOrdernum(), "689.74", PaymentGateway.AUTH, Payment.PAYMENT_STATUS_PROCESSING, false); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleFullMixedMultiPaymentProcessingPartialOnlineAuthPerShipment() throws Exception { configureTestPG(true, true, TestPaymentGatewayImpl.PROCESSING_NO + "84.77"); String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.FULL, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING_NO + "84.77"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST9", "0.00", "0.00"); assertTrue(customerOrder.getDelivery().size() == 4); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "444.95", "689.74", "259.74", "444.95"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.AUTH, PaymentGateway.AUTH, PaymentGateway.AUTH, PaymentGateway.REVERSE_AUTH, PaymentGateway.REVERSE_AUTH, PaymentGateway.REVERSE_AUTH), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE) ); assertEquals("1479.20", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardPaymentProcessingOnlineCapture() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.VOID_CAPTURE), Arrays.asList(Payment.PAYMENT_STATUS_PROCESSING,Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardPaymentProcessingOnlineCaptureFailedVoid() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING); activateTestPgParameterSetOn(TestPaymentGatewayImpl.VOID_CAPTURE_FAIL); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.VOID_CAPTURE), Arrays.asList(Payment.PAYMENT_STATUS_PROCESSING,Payment.PAYMENT_STATUS_FAILED), Arrays.asList(Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED_WAITING_PAYMENT, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentProcessingOnlineCapturePerShipment() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.VOID_CAPTURE), Arrays.asList(Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentProcessingOnlineCapturePerShipmentVoidFailed() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING); activateTestPgParameterSetOn(TestPaymentGatewayImpl.VOID_CAPTURE_FAIL_NO + "259.74"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.VOID_CAPTURE, PaymentGateway.VOID_CAPTURE), Arrays.asList(Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED_WAITING_PAYMENT, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentProcessingPartialOnlineCapturePerShipment() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentProcessingPartialOnlineCapturePerShipmentRefund() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); activateTestPgParameterSetOn(TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.VOID_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED), Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("84.77", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED_WAITING_PAYMENT, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardPaymentOkOfflineAuth() throws Exception { String label = assertPgFeatures("courierPaymentGateway", false, false, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertNoPaymentEntries(customerOrder.getOrdernum()); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentOkOnlineAuthPerShipment() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), new HashMap<String, String>() {{ put(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); put(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_DATE_WAIT); put(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); }}); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.AUTH, PaymentGateway.AUTH, PaymentGateway.REVERSE_AUTH, PaymentGateway.REVERSE_AUTH, PaymentGateway.REVERSE_AUTH), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentOkOnlineCapturePerShipment() throws Exception { configureTestPG(false, true); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), new HashMap<String, String>() {{ put(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); put(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_DATE_WAIT); put(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); }}); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleMixedMultiPaymentOkOnlineCapturePerShipmentRefundFailed() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), new HashMap<String, String>() {{ put(CustomerOrderDelivery.STANDARD_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); put(CustomerOrderDelivery.DATE_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_DATE_WAIT); put(CustomerOrderDelivery.INVENTORY_WAIT_DELIVERY_GROUP, CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); }}); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "0.00"); assertEquals(customerOrder.getDelivery().size(), 3); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "259.74", "84.77", "689.74", "259.74", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED), Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("1034.25", customerOrder.getOrderTotal().toPlainString()); assertEquals("84.77", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED_WAITING_PAYMENT, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryAllocatedAuth() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_ALLOCATED); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.REVERSE_AUTH), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryPackingAuth() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_PACKING); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.REVERSE_AUTH), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShipReadyAuth() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_READY); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.REVERSE_AUTH), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippingAuth() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_IN_PROGRESS); orderService.update(customerOrder); try { handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP)); fail("Cancellation during shipping in progress is not allowed"); } catch (OrderException oe) { } customerOrder = orderService.findByReference(customerOrder.getOrdernum()); assertInventory(WAREHOUSE_ID, "CC_TEST1", "7.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "0.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_IN_PROGRESS); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.TRUE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("689.74", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_IN_PROGRESS, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippedAuth() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(shippedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPPED); assertEquals(CustomerOrder.ORDER_STATUS_COMPLETED, customerOrder.getOrderStatus()); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "7.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "0.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_RETURNED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippedAuthRefundFailed() throws Exception { configureTestPG(true, true, TestPaymentGatewayImpl.REFUND_FAIL); String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(shippedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPPED); assertEquals(CustomerOrder.ORDER_STATUS_COMPLETED, customerOrder.getOrderStatus()); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "7.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "0.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_RETURNED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED), Arrays.asList(Boolean.FALSE, Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("689.74", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED_WAITING_PAYMENT, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippingAuthNoCapture() throws Exception { configureTestPG(true, true, TestPaymentGatewayImpl.CAPTURE_FAIL); String label = assertPgFeatures("testPaymentGateway", false, true, true, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_READY_WAITING_PAYMENT); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE, PaymentGateway.REVERSE_AUTH), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryAllocatedCapture() throws Exception { configureTestPG(false, true); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_ALLOCATED); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryPackingCapture() throws Exception { configureTestPG(false, true); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_PACKING); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShipReadyCapture() throws Exception { configureTestPG(false, true); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_READY); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_DEALLOCATED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippingCapture() throws Exception { configureTestPG(false, true); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_IN_PROGRESS); orderService.update(customerOrder); try { handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP)); fail("Cancellation during shipping in progress is not allowed"); } catch (OrderException oe) { } customerOrder = orderService.findByReference(customerOrder.getOrdernum()); assertInventory(WAREHOUSE_ID, "CC_TEST1", "7.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "0.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPMENT_IN_PROGRESS); assertSinglePaymentEntry(customerOrder.getOrdernum(), "689.74", PaymentGateway.AUTH_CAPTURE, Payment.PAYMENT_STATUS_OK, true); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("689.74", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_IN_PROGRESS, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippedCapture() throws Exception { configureTestPG(false, true); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(shippedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPPED); assertEquals(CustomerOrder.ORDER_STATUS_COMPLETED, customerOrder.getOrderStatus()); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "7.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "0.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_RETURNED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardInventoryShippedCaptureRefundFailed() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.REFUND_FAIL); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_ALLOCATION_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(allocationHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packingHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(packedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(releaseHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertTrue(shippedHandler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_SHIPPED); assertEquals(CustomerOrder.ORDER_STATUS_COMPLETED, customerOrder.getOrderStatus()); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "7.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "0.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_RETURNED); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED), Arrays.asList(Boolean.TRUE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("689.74", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED_WAITING_PAYMENT, customerOrder.getOrderStatus()); }
@Test public void testHandleStandardPaymentProcessingOnlineCaptureSub() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestSubOrder(TestOrderType.STANDARD, label, false); assertTrue(pendingHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_RESERVATION); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.VOID_CAPTURE), Arrays.asList(Payment.PAYMENT_STATUS_PROCESSING,Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.FALSE)); assertEquals("689.74", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); }