@Test public void testHandlePaymentCallbackOutOfStock() throws Exception { Customer customer = createCustomer(); ShoppingCart shoppingCart = getShoppingCart2(customer.getEmail()); final ShoppingCartCommandFactory commands = ctx().getBean("shoppingCartCommandFactory", ShoppingCartCommandFactory.class); Map<String, String> param = new HashMap<String, String>(); param = new HashMap<String, String>(); param.put(ShoppingCartCommand.CMD_SETQTYSKU, "CC_TEST1"); param.put(ShoppingCartCommand.CMD_SETQTYSKU_P_QTY, "20000.00"); commands.execute(shoppingCart, (Map) param); CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart); customerOrder = deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, true); customerOrder.setPgLabel("testExtFormPaymentGatewayLabel"); customerOrder = customerOrderService.create(customerOrder); assertEquals( "Order must be in ORDER_STATUS_NONE state", CustomerOrder.ORDER_STATUS_NONE, customerOrder.getOrderStatus()); final String ordGuid = customerOrder.getCartGuid(); ShopCodeContext.setShopCode(customerOrder.getShop().getCode()); paymentCallBackHandlerFacade.handlePaymentCallback( new HashMap<String, String>() { { put(TestExtFormPaymentGatewayImpl.ORDER_GUID_PARAM_KEY, ordGuid); put(TestExtFormPaymentGatewayImpl.RESPONSE_CODE_PARAM_KEY, "1"); // 1 - means ok } }, "testExtFormPaymentGatewayLabel"); ShopCodeContext.clear(); customerOrder = customerOrderService.findByGuid(customerOrder.getCartGuid()); assertEquals( "Order must be in ORDER_STATUS_CANCELLED state", // because item is out of stock CustomerOrder.ORDER_STATUS_CANCELLED, customerOrder.getOrderStatus()); final List<CustomerOrderPayment> payments = customerOrderPaymentService.findBy(customerOrder.getOrdernum(), null, null, null); assertNotNull(payments); assertEquals(payments.size(), 2); assertEquals(PaymentGateway.AUTH_CAPTURE, payments.get(0).getTransactionOperation()); assertEquals("1", payments.get(0).getTransactionOperationResultCode()); assertEquals(PaymentGateway.REFUND, payments.get(1).getTransactionOperation()); assertEquals("1", payments.get(1).getTransactionOperationResultCode()); }
@Test public void testHandlePaymentCallbackEnoughStock() throws Exception { Customer customer = createCustomer(); ShoppingCart shoppingCart = getShoppingCart2(customer.getEmail()); CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart); customerOrder = deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, true); customerOrder.setPgLabel("testExtFormPaymentGatewayLabel"); customerOrder = customerOrderService.create(customerOrder); assertEquals( "Order must be in ORDER_STATUS_NONE state", CustomerOrder.ORDER_STATUS_NONE, customerOrder.getOrderStatus()); final String ordGuid = customerOrder.getCartGuid(); ShopCodeContext.setShopCode(customerOrder.getShop().getCode()); paymentCallBackHandlerFacade.handlePaymentCallback( new HashMap<String, String>() { { put(TestExtFormPaymentGatewayImpl.ORDER_GUID_PARAM_KEY, ordGuid); put(TestExtFormPaymentGatewayImpl.RESPONSE_CODE_PARAM_KEY, "1"); // 1 - means ok } }, "testExtFormPaymentGatewayLabel"); ShopCodeContext.clear(); customerOrder = customerOrderService.findByGuid(customerOrder.getCartGuid()); assertEquals( "Order must be in ORDER_STATUS_PARTIALLY_SHIPPED state", // because one of the delivery is // electronic delivery CustomerOrder.ORDER_STATUS_PARTIALLY_SHIPPED, customerOrder.getOrderStatus()); final List<CustomerOrderPayment> payments = customerOrderPaymentService.findBy(customerOrder.getOrdernum(), null, null, null); assertNotNull(payments); assertEquals(payments.size(), 1); assertEquals(PaymentGateway.AUTH_CAPTURE, payments.get(0).getTransactionOperation()); assertEquals("1", payments.get(0).getTransactionOperationResultCode()); }