RefundProcessedOrderEventHandlerImpl extends AbstractOrderEventHandlerImpl 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()); } boolean handled = false; if (paymentProcessor.getPaymentGateway().getPaymentGatewayFeatures().isOnlineGateway()) { final String result = paymentProcessor.cancelOrder(orderEvent.getCustomerOrder(), isForceProcessing(orderEvent), orderEvent.getParams()); if (Payment.PAYMENT_STATUS_OK.equals(result)) { handleInternal(orderEvent); handled = true; } } return handled; } } RefundProcessedOrderEventHandlerImpl(final PaymentProcessorFactory paymentProcessorFactory); @Override boolean handle(final OrderEvent orderEvent);  }
@Test public void testHandleMixedMultiPaymentPartialOnlineCapturePerShipmentRefundFailed() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrderOnlineProcessing(TestOrderType.MIXED, label, false); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); activateTestPgParameterSetOn(TestPaymentGatewayImpl.AUTH_CAPTURE_FAIL); activateTestPgParameterSetOn(TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); assertTrue(paymentProcessedHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.AUTH_CAPTURE_FAIL); deactivateTestPgParameter(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", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, 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 testHandleMixedMultiPaymentPartialOnlineCapturePerShipmentRefundManual() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestOrderOnlineProcessing(TestOrderType.MIXED, label, false); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); activateTestPgParameterSetOn(TestPaymentGatewayImpl.AUTH_CAPTURE_FAIL); activateTestPgParameterSetOn(TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); assertTrue(paymentProcessedHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.AUTH_CAPTURE_FAIL); assertFalse(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING, Boolean.TRUE); put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING_MESSAGE, "Manual message"); put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_USER, "manager@test.com"); }}))); 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", "84.77", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, 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 testHandleStandardReserveFailedPaymentOkRefundNotSupportedExternalForce() throws Exception { configureTestExtPG("4"); String label = assertPgFeatures("testExtFormPaymentGateway", true, true, false, false); CustomerOrder customerOrder = createTestOrderFailedReserve(TestOrderType.STANDARD, label, false); assertTrue(cancelNewOrderHandler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(TestExtFormPaymentGatewayImpl.AUTH_RESPONSE_CODE_PARAM_KEY, "1"); }}))); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING, Boolean.TRUE); put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING_MESSAGE, "Manual message"); put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_USER, "manager@test.com"); }}))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "0.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_WAIT); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_MANUAL_PROCESSING_REQUIRED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, 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 testHandleStandardReserveFailedPaymentOkRefundNotSupportedExternalCallback() throws Exception { configureTestExtPG("4"); String label = assertPgFeatures("testExtFormPaymentGateway", true, true, false, false); CustomerOrder customerOrder = createTestOrderFailedReserve(TestOrderType.STANDARD, label, false); assertTrue(cancelNewOrderHandler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(TestExtFormPaymentGatewayImpl.AUTH_RESPONSE_CODE_PARAM_KEY, "1"); }}))); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(CallbackAware.CALLBACK_PARAM, new BasicCallbackInfoImpl( customerOrder.getOrdernum(), CallbackAware.CallbackOperation.REFUND, new BigDecimal("689.74"), Collections.singletonMap(TestExtFormPaymentGatewayImpl.REFUND_RESPONSE_CODE_PARAM_KEY, "1"), true ) ); }}))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "0.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_WAIT); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_MANUAL_PROCESSING_REQUIRED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, 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 testHandleFullMixedReserveFailedPaymentOkRefundProcessingExternal() throws Exception { configureTestExtPG("3"); String label = assertPgFeatures("testExtFormPaymentGateway", true, true, false, false); CustomerOrder customerOrder = createTestOrderFailedReserve(TestOrderType.FULL, label, false); assertTrue(cancelNewOrderHandler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(TestExtFormPaymentGatewayImpl.AUTH_RESPONSE_CODE_PARAM_KEY, "1"); }}))); configureTestExtPG("1"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(CallbackAware.CALLBACK_PARAM, new BasicCallbackInfoImpl( customerOrder.getOrdernum(), CallbackAware.CallbackOperation.REFUND, new BigDecimal("1479.20"), Collections.singletonMap(TestExtFormPaymentGatewayImpl.REFUND_RESPONSE_CODE_PARAM_KEY, "1"), true ) ); }}))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "0.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_WAIT); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("1479.20", "1479.20", "1479.20"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, 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 testHandleFullMixedReserveFailedPaymentOkRefundProcessingExternalCallback() throws Exception { configureTestExtPG("3"); String label = assertPgFeatures("testExtFormPaymentGateway", true, true, false, false); CustomerOrder customerOrder = createTestOrderFailedReserve(TestOrderType.FULL, label, false); assertTrue(cancelNewOrderHandler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(TestExtFormPaymentGatewayImpl.AUTH_RESPONSE_CODE_PARAM_KEY, "1"); }}))); configureTestExtPG("1"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "0.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_WAIT); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("1479.20", "1479.20", "1479.20"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, 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 testHandleMixedMultiPaymentOkOnlineCapturePerShipmentRefund() 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(cancelWithRefundHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED_WAITING_PAYMENT, customerOrder.getOrderStatus()); deactivateTestPgParameter(TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); 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", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, 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, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, 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 testHandleMixedMultiPaymentOkOnlineCapturePerShipmentRefund2() 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(cancelWithRefundHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); assertEquals(CustomerOrder.ORDER_STATUS_CANCELLED_WAITING_PAYMENT, customerOrder.getOrderStatus()); assertFalse(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); deactivateTestPgParameter(TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); 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", "84.77", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND, 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, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, 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 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))); assertTrue(cancelWithRefundHandler.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); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED_WAITING_PAYMENT, customerOrder.getOrderStatus()); deactivateTestPgParameter(TestPaymentGatewayImpl.REFUND_FAIL); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, 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 testHandleStandardInventoryShippedAuthRefundFailed2() 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))); assertTrue(cancelWithRefundHandler.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); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED_WAITING_PAYMENT, customerOrder.getOrderStatus()); assertFalse(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_FAILED), Arrays.asList(Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, 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 testHandleStandardInventoryShippedAuthRefundFailedManual() 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))); assertTrue(cancelWithRefundHandler.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); assertEquals(CustomerOrder.ORDER_STATUS_RETURNED_WAITING_PAYMENT, customerOrder.getOrderStatus()); assertFalse(handler.handle( new OrderEventImpl("", customerOrder, null, Collections.emptyMap()))); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING, Boolean.TRUE); put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING_MESSAGE, "Manual message"); put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_USER, "manager@test.com"); }}))); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH, PaymentGateway.CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, 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 testHandleMixedMultiPaymentPartialOnlineCapturePerShipmentRefundFailedSub() throws Exception { configureTestPG(false, true, TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); String label = assertPgFeatures("testPaymentGateway", false, true, false, true); CustomerOrder customerOrder = createTestSubOrderOnlineProcessing(TestOrderType.MIXED, label, false); deactivateTestPgParameter(TestPaymentGatewayImpl.PROCESSING_NO + "259.74"); activateTestPgParameterSetOn(TestPaymentGatewayImpl.AUTH_CAPTURE_FAIL); activateTestPgParameterSetOn(TestPaymentGatewayImpl.REFUND_FAIL_NO + "84.77"); assertTrue(paymentProcessedHandler.handle( new OrderEventImpl("", customerOrder, null, Collections.EMPTY_MAP))); deactivateTestPgParameter(TestPaymentGatewayImpl.AUTH_CAPTURE_FAIL); deactivateTestPgParameter(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", "84.77"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_PROCESSING, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_FAILED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, 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 testHandleStandardReserveFailedPaymentOkRefundNotSupportedExternalSub() throws Exception { configureTestExtPG("4"); String label = assertPgFeatures("testExtFormPaymentGateway", true, true, false, false); CustomerOrder customerOrder = createTestSubOrderFailedReserve(TestOrderType.STANDARD, label, false); assertTrue(cancelNewOrderHandler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(TestExtFormPaymentGatewayImpl.AUTH_RESPONSE_CODE_PARAM_KEY, "1"); }}))); assertTrue(handler.handle( new OrderEventImpl("", customerOrder, null, new HashMap() {{ put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING, Boolean.TRUE); put(AttributeNamesKeys.CustomerOrder.ORDER_PAYMENT_FORCE_MANUAL_PROCESSING_MESSAGE, "Manual message"); put(AttributeNamesKeys.CustomerOrder.ORDER_TRANSITION_USER, "manager@test.com"); }}))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "0.00", "0.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "0.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_VOID_WAIT); assertMultiPaymentEntry(customerOrder.getOrdernum(), Arrays.asList("689.74", "689.74", "689.74"), Arrays.asList(PaymentGateway.AUTH_CAPTURE, PaymentGateway.REFUND, PaymentGateway.REFUND), Arrays.asList(Payment.PAYMENT_STATUS_OK, Payment.PAYMENT_STATUS_MANUAL_PROCESSING_REQUIRED, Payment.PAYMENT_STATUS_OK), Arrays.asList(Boolean.TRUE, 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()); }