Search in sources :

Example 1 with BroadleafCurrency

use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency 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 BroadleafCurrency

use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.

the class OrderToPaymentRequestDTOServiceImpl method translateOrder.

@Override
public PaymentRequestDTO translateOrder(Order order) {
    if (order != null) {
        final Long id = order.getId();
        final BroadleafCurrency currency = order.getCurrency();
        PaymentRequestDTO requestDTO = new PaymentRequestDTO().orderId(id.toString());
        if (LOG.isTraceEnabled()) {
            LOG.trace(String.format("Translating Order (ID:%s) into a PaymentRequestDTO for the configured " + "gateway.", id));
        }
        if (currency != null) {
            requestDTO.orderCurrencyCode(currency.getCurrencyCode());
        }
        populateCustomerInfo(order, requestDTO);
        populateShipTo(order, requestDTO);
        populateBillTo(order, requestDTO);
        populateTotals(order, requestDTO);
        populateDefaultLineItemsAndSubtotal(order, requestDTO);
        return requestDTO;
    }
    return null;
}
Also used : BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) PaymentRequestDTO(org.broadleafcommerce.common.payment.dto.PaymentRequestDTO)

Example 3 with BroadleafCurrency

use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafCurrencyProvider method provideFRCurrency.

@DataProvider(name = "FRCurrency")
public static Object[][] provideFRCurrency() {
    BroadleafCurrency currency = new BroadleafCurrencyImpl();
    currency.setCurrencyCode("EUR");
    currency.setDefaultFlag(true);
    currency.setFriendlyName("EURO Dollar");
    return new Object[][] { { currency } };
}
Also used : BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) BroadleafCurrencyImpl(org.broadleafcommerce.common.currency.domain.BroadleafCurrencyImpl) DataProvider(org.testng.annotations.DataProvider)

Example 4 with BroadleafCurrency

use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafCurrencyDaoImpl method findCurrencyByCode.

/**
 * @return The locale for the passed in code
 */
@Override
public BroadleafCurrency findCurrencyByCode(String currencyCode) {
    Query query = em.createNamedQuery("BC_READ_CURRENCY_BY_CODE");
    query.setParameter("currencyCode", currencyCode);
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    List<BroadleafCurrency> currencyList = query.getResultList();
    if (currencyList.size() >= 1) {
        return currencyList.get(0);
    }
    return null;
}
Also used : Query(javax.persistence.Query) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency)

Example 5 with BroadleafCurrency

use of org.broadleafcommerce.common.currency.domain.BroadleafCurrency in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafCurrencyDaoImpl method findDefaultBroadleafCurrency.

@Override
public BroadleafCurrency findDefaultBroadleafCurrency() {
    Query query = em.createNamedQuery("BC_READ_DEFAULT_CURRENCY");
    query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
    List<BroadleafCurrency> currencyList = query.getResultList();
    if (currencyList.size() >= 1) {
        return currencyList.get(0);
    }
    return null;
}
Also used : Query(javax.persistence.Query) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency)

Aggregations

BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)15 Money (org.broadleafcommerce.common.money.Money)5 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)2 Currency (java.util.Currency)2 HashMap (java.util.HashMap)2 Query (javax.persistence.Query)2 BroadleafCurrencyImpl (org.broadleafcommerce.common.currency.domain.BroadleafCurrencyImpl)2 Locale (org.broadleafcommerce.common.locale.domain.Locale)2 Offer (org.broadleafcommerce.core.offer.domain.Offer)2 DataProvider (org.testng.annotations.DataProvider)2 NumberFormat (java.text.NumberFormat)1 List (java.util.List)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 NullComparator (org.apache.commons.collections.comparators.NullComparator)1 ReverseComparator (org.apache.commons.collections.comparators.ReverseComparator)1 BroadleafRequestedCurrencyDto (org.broadleafcommerce.common.currency.domain.BroadleafRequestedCurrencyDto)1 ClonePolicyCollectionOverride (org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyCollectionOverride)1 CurrencyConversionService (org.broadleafcommerce.common.money.CurrencyConversionService)1 PaymentRequestDTO (org.broadleafcommerce.common.payment.dto.PaymentRequestDTO)1