Search in sources :

Example 1 with CheckoutResponse

use of org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutTest method testCheckout.

@Test(groups = { "checkout" }, dependsOnGroups = { "createCartForCustomer", "testShippingInsert" }, dataProvider = "USCurrency", dataProviderClass = BroadleafCurrencyProvider.class)
@Transactional
public void testCheckout(BroadleafCurrency usCurrency) throws Exception {
    HashMap currencyConsiderationContext = new HashMap();
    currencyConsiderationContext.put("aa", "bb");
    CurrencyConversionContext.setCurrencyConversionContext(currencyConsiderationContext);
    CurrencyConversionContext.setCurrencyConversionService(new CurrencyConversionService() {

        @Override
        public Money convertCurrency(Money source, Currency destinationCurrency, int destinationScale) {
            return source;
        }
    });
    String userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    Order order = orderService.createNewCartForCustomer(customer);
    usCurrency = currencyService.save(usCurrency);
    order.setCurrency(usCurrency);
    Address address = buildAddress();
    FulfillmentGroup group = buildFulfillmentGroup(order, address);
    addSampleItemToOrder(order, group);
    order.setTotalShipping(new Money(0D));
    addPaymentToOrder(order, address);
    // execute pricing for this order
    orderService.save(order, true);
    CheckoutResponse response = checkoutService.performCheckout(order);
    assert (order.getTotal().greaterThan(order.getSubTotal()));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Address(org.broadleafcommerce.profile.core.domain.Address) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer) Currency(java.util.Currency) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) CurrencyConversionService(org.broadleafcommerce.common.money.CurrencyConversionService) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with CheckoutResponse

use of org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse in project BroadleafCommerce by BroadleafCommerce.

the class DefaultPaymentGatewayCheckoutService method initiateCheckout.

@Override
public String initiateCheckout(Long orderId) throws Exception {
    Order order = orderService.findOrderById(orderId, true);
    if (order == null || order instanceof NullOrderImpl) {
        throw new IllegalArgumentException("Could not order with id " + orderId);
    }
    CheckoutResponse response;
    try {
        response = checkoutService.performCheckout(order);
    } catch (CheckoutException e) {
        throw new Exception(e);
    }
    if (response.getOrder().getOrderNumber() == null) {
        LOG.error("Order Number for Order ID: " + order.getId() + " is null.");
    }
    return response.getOrder().getOrderNumber();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) CheckoutException(org.broadleafcommerce.core.checkout.service.exception.CheckoutException) CheckoutException(org.broadleafcommerce.core.checkout.service.exception.CheckoutException)

Aggregations

CheckoutResponse (org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse)2 Order (org.broadleafcommerce.core.order.domain.Order)2 Currency (java.util.Currency)1 HashMap (java.util.HashMap)1 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 CurrencyConversionService (org.broadleafcommerce.common.money.CurrencyConversionService)1 Money (org.broadleafcommerce.common.money.Money)1 CheckoutException (org.broadleafcommerce.core.checkout.service.exception.CheckoutException)1 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)1 NullOrderImpl (org.broadleafcommerce.core.order.domain.NullOrderImpl)1 Address (org.broadleafcommerce.profile.core.domain.Address)1 Customer (org.broadleafcommerce.profile.core.domain.Customer)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Test (org.testng.annotations.Test)1