Search in sources :

Example 6 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class DefaultDynamicSkuPricingFilter method getPricingConsiderations.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public HashMap getPricingConsiderations(ServletRequest request) {
    HashMap pricingConsiderations = new HashMap();
    Customer customer = customerState.getCustomer((HttpServletRequest) request);
    pricingConsiderations.put("customer", customer);
    return pricingConsiderations;
}
Also used : HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 7 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutFormServiceImpl method getCustomerPaymentUsedForOrder.

protected CustomerPayment getCustomerPaymentUsedForOrder() {
    Customer customer = CustomerState.getCustomer();
    List<CustomerPayment> customerPayments = customerPaymentService.readCustomerPaymentsByCustomerId(customer.getId());
    for (CustomerPayment customerPayment : customerPayments) {
        if (cartStateService.cartHasCreditCardPaymentWithSameToken(customerPayment.getPaymentToken())) {
            return customerPayment;
        }
    }
    return null;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment)

Example 8 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class DefaultCustomerPaymentGatewayService method createCustomerPaymentFromResponseDTO.

@Override
public Long createCustomerPaymentFromResponseDTO(PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) throws IllegalArgumentException {
    validateResponseAndConfig(responseDTO, config);
    Long customerId = Long.parseLong(responseDTO.getCustomer().getCustomerId());
    Customer customer = customerService.readCustomerById(customerId);
    if (customer != null) {
        if (isNewDefaultPaymentMethod(responseDTO)) {
            customerPaymentService.clearDefaultPaymentStatus(customer);
        }
        CustomerPayment customerPayment = customerPaymentService.create();
        populateCustomerPayment(customerPayment, responseDTO, config);
        customerPayment.setCustomer(customer);
        customerPayment = customerPaymentService.saveCustomerPayment(customerPayment);
        customer.getCustomerPayments().add(customerPayment);
        return customerPayment.getId();
    }
    return null;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment)

Example 9 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class DefaultPaymentGatewayCheckoutService method applyPaymentToOrder.

@Override
public Long applyPaymentToOrder(PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) {
    // Payments can ONLY be parsed into Order Payments if they are 'valid'
    if (!responseDTO.isValid()) {
        throw new IllegalArgumentException("Invalid payment responses cannot be parsed into the order payment domain");
    }
    if (config == null) {
        throw new IllegalArgumentException("Config service cannot be null");
    }
    Long orderId = Long.parseLong(responseDTO.getOrderId());
    Order order = orderService.findOrderById(orderId);
    if (!OrderStatus.IN_PROCESS.equals(order.getStatus()) && !OrderStatus.CSR_OWNED.equals(order.getStatus()) && !OrderStatus.QUOTE.equals(order.getStatus())) {
        throw new IllegalArgumentException("Cannot apply another payment to an Order that is not IN_PROCESS or CSR_OWNED");
    }
    Customer customer = order.getCustomer();
    if (customer.isAnonymous()) {
        GatewayCustomerDTO<PaymentResponseDTO> gatewayCustomer = responseDTO.getCustomer();
        if (StringUtils.isEmpty(customer.getFirstName()) && gatewayCustomer != null) {
            customer.setFirstName(gatewayCustomer.getFirstName());
        }
        if (StringUtils.isEmpty(customer.getLastName()) && gatewayCustomer != null) {
            customer.setLastName(gatewayCustomer.getLastName());
        }
        if (StringUtils.isEmpty(customer.getEmailAddress()) && gatewayCustomer != null) {
            customer.setEmailAddress(gatewayCustomer.getEmail());
        }
    }
    // If the gateway sends back an email address and the order does not contain one, set it.
    GatewayCustomerDTO<PaymentResponseDTO> gatewayCustomer = responseDTO.getCustomer();
    if (order.getEmailAddress() == null && gatewayCustomer != null) {
        order.setEmailAddress(gatewayCustomer.getEmail());
    }
    // If the gateway sends back Shipping Information, we will save that to the first shippable fulfillment group.
    dtoToEntityService.populateShippingInfo(responseDTO, order);
    // ALWAYS create a new order payment for the payment that comes in. Invalid payments should be cleaned up by
    // invoking {@link #markPaymentAsInvalid}.
    OrderPayment payment = orderPaymentService.create();
    payment.setType(responseDTO.getPaymentType());
    payment.setPaymentGatewayType(responseDTO.getPaymentGatewayType());
    payment.setAmount(responseDTO.getAmount());
    // If this gateway does not support multiple payments then mark all of the existing payments
    // as invalid before adding the new one
    List<OrderPayment> paymentsToInvalidate = new ArrayList<OrderPayment>();
    Address tempBillingAddress = null;
    if (!config.handlesMultiplePayments()) {
        PaymentGatewayType gateway = config.getGatewayType();
        for (OrderPayment p : order.getPayments()) {
            // - The payment being added has the same gateway type of an existing one.
            if (PaymentGatewayType.TEMPORARY.equals(p.getGatewayType()) || (p.isFinalPayment() && payment.isFinalPayment()) || (p.getGatewayType() != null && p.getGatewayType().equals(gateway))) {
                paymentsToInvalidate.add(p);
                if (PaymentGatewayType.TEMPORARY.equals(p.getGatewayType())) {
                    tempBillingAddress = p.getBillingAddress();
                }
            }
        }
    }
    for (OrderPayment invalid : paymentsToInvalidate) {
        // 2
        markPaymentAsInvalid(invalid.getId());
    }
    // The billing address that will be saved on the order will be parsed off the
    // Response DTO sent back from the Gateway as it may have Address Verification or Standardization.
    // If you do not wish to use the Billing Address coming back from the Gateway, you can override the
    // populateBillingInfo() method or set the useBillingAddressFromGateway property.
    dtoToEntityService.populateBillingInfo(responseDTO, payment, tempBillingAddress, isUseBillingAddressFromGateway());
    // Create the transaction for the payment
    PaymentTransaction transaction = orderPaymentService.createTransaction();
    transaction.setAmount(responseDTO.getAmount());
    transaction.setRawResponse(responseDTO.getRawResponse());
    transaction.setSuccess(responseDTO.isSuccessful());
    transaction.setType(responseDTO.getPaymentTransactionType());
    for (Entry<String, String> entry : responseDTO.getResponseMap().entrySet()) {
        transaction.getAdditionalFields().put(entry.getKey(), entry.getValue());
    }
    // Set the Credit Card Info on the Additional Fields Map
    if (responseDTO.getCreditCard() != null && responseDTO.getCreditCard().creditCardPopulated()) {
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.NAME_ON_CARD.getType(), responseDTO.getCreditCard().getCreditCardHolderName());
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.CARD_TYPE.getType(), responseDTO.getCreditCard().getCreditCardType());
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_DATE.getType(), responseDTO.getCreditCard().getCreditCardExpDate());
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.LAST_FOUR.getType(), responseDTO.getCreditCard().getCreditCardLastFour());
    }
    // TODO: validate that this particular type of transaction can be added to the payment (there might already
    // be an AUTHORIZE transaction, for instance)
    // Persist the order payment as well as its transaction
    payment.setOrder(order);
    transaction.setOrderPayment(payment);
    payment.addTransaction(transaction);
    payment = orderPaymentService.save(payment);
    if (transaction.getSuccess()) {
        orderService.addPaymentToOrder(order, payment, null);
    } else {
        // We will have to mark the entire payment as invalid and boot the user to re-enter their
        // billing info and payment information as there may be an error either with the billing address/or credit card
        handleUnsuccessfulTransaction(payment);
    }
    return payment.getId();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) Customer(org.broadleafcommerce.profile.core.domain.Customer) ArrayList(java.util.ArrayList) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) PaymentGatewayType(org.broadleafcommerce.common.payment.PaymentGatewayType) PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Example 10 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupDaoTest method createFulfillmentGroup.

@Test(groups = "createFulfillmentGroup", dataProvider = "basicFulfillmentGroup", dataProviderClass = FulfillmentGroupDataProvider.class)
@Transactional
@Rollback(false)
public void createFulfillmentGroup(FulfillmentGroup fulfillmentGroup) {
    Customer customer = createCustomerWithBasicOrderAndAddresses();
    Address address = (customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId())).get(0).getAddress();
    Order salesOrder = orderDao.readOrdersForCustomer(customer.getId()).get(0);
    FulfillmentGroup newFG = fulfillmentGroupDao.create();
    newFG.setAddress(address);
    newFG.setRetailShippingPrice(fulfillmentGroup.getRetailShippingPrice());
    newFG.setMethod(fulfillmentGroup.getMethod());
    newFG.setService(fulfillmentGroup.getService());
    newFG.setReferenceNumber(fulfillmentGroup.getReferenceNumber());
    newFG.setOrder(salesOrder);
    assert newFG.getId() == null;
    fulfillmentGroup = fulfillmentGroupService.save(newFG);
    assert fulfillmentGroup.getId() != null;
    fulfillmentGroupId = fulfillmentGroup.getId();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) Customer(org.broadleafcommerce.profile.core.domain.Customer) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)98 Order (org.broadleafcommerce.core.order.domain.Order)41 Transactional (org.springframework.transaction.annotation.Transactional)34 Test (org.testng.annotations.Test)33 Address (org.broadleafcommerce.profile.core.domain.Address)14 Rollback (org.springframework.test.annotation.Rollback)11 HashMap (java.util.HashMap)9 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)9 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)6 ArrayList (java.util.ArrayList)5 Money (org.broadleafcommerce.common.money.Money)5 Category (org.broadleafcommerce.core.catalog.domain.Category)5 Product (org.broadleafcommerce.core.catalog.domain.Product)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)5 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)3