Search in sources :

Example 6 with CustomerPayment

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

the class CustomerPaymentServiceImpl method clearDefaultPaymentStatus.

@Override
@Transactional("blTransactionManager")
public void clearDefaultPaymentStatus(Customer customer) {
    CustomerPayment oldDefault = findDefaultPaymentForCustomer(customer);
    if (oldDefault != null) {
        oldDefault.setIsDefault(false);
        saveCustomerPayment(oldDefault);
    }
}
Also used : CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with CustomerPayment

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

the class BroadleafBillingInfoController method saveBillingAddress.

/**
 * Processes the request to save a billing address.
 *
 * Note: this default Broadleaf implementation will create an OrderPayment of
 * type CREDIT_CARD if it doesn't exist and save the passed in billing address
 *
 * @param request
 * @param response
 * @param model
 * @param billingForm
 * @return the return path
 * @throws org.broadleafcommerce.common.exception.ServiceException
 */
public String saveBillingAddress(HttpServletRequest request, HttpServletResponse response, Model model, BillingInfoForm billingForm, BindingResult result) throws PricingException, ServiceException {
    Order cart = CartState.getCart();
    CustomerPayment customerPayment = null;
    if (billingForm.isUseShippingAddress()) {
        copyShippingAddressToBillingAddress(cart, billingForm);
    }
    Boolean useCustomerPayment = billingForm.getUseCustomerPayment();
    if (useCustomerPayment && billingForm.getCustomerPaymentId() != null) {
        customerPayment = customerPaymentService.readCustomerPaymentById(billingForm.getCustomerPaymentId());
        if (customerPayment != null) {
            Address address = customerPayment.getBillingAddress();
            if (address != null) {
                billingForm.setAddress(addressService.copyAddress(address));
            }
        }
    }
    addressService.populateAddressISOCountrySub(billingForm.getAddress());
    billingInfoFormValidator.validate(billingForm, result);
    if (result.hasErrors()) {
        return getCheckoutView();
    }
    if ((billingForm.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(billingForm.getAddress().getPhonePrimary().getPhoneNumber()))) {
        billingForm.getAddress().setPhonePrimary(null);
    }
    if ((billingForm.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(billingForm.getAddress().getPhoneSecondary().getPhoneNumber()))) {
        billingForm.getAddress().setPhoneSecondary(null);
    }
    if ((billingForm.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(billingForm.getAddress().getPhoneFax().getPhoneNumber()))) {
        billingForm.getAddress().setPhoneFax(null);
    }
    boolean found = false;
    String paymentName = billingForm.getPaymentName();
    Boolean saveNewPayment = billingForm.getSaveNewPayment();
    for (OrderPayment p : cart.getPayments()) {
        if (PaymentType.CREDIT_CARD.equals(p.getType()) && p.isActive()) {
            if (p.getBillingAddress() == null) {
                p.setBillingAddress(billingForm.getAddress());
            } else {
                Address updatedAddress = addressService.copyAddress(p.getBillingAddress(), billingForm.getAddress());
                p.setBillingAddress(updatedAddress);
            }
            found = true;
        }
    }
    if (!found) {
        // A Temporary Order Payment will be created to hold the billing address.
        // The Payment Gateway will send back any validated address and
        // the PaymentGatewayCheckoutService will persist a new payment of type CREDIT_CARD when it applies it to the Order
        OrderPayment tempOrderPayment = orderPaymentService.create();
        tempOrderPayment.setType(PaymentType.CREDIT_CARD);
        tempOrderPayment.setPaymentGatewayType(PaymentGatewayType.TEMPORARY);
        tempOrderPayment.setBillingAddress(billingForm.getAddress());
        tempOrderPayment.setOrder(cart);
        cart.getPayments().add(tempOrderPayment);
    }
    orderService.save(cart, true);
    if (isAjaxRequest(request)) {
        // Add module specific model variables
        checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
        return getCheckoutView();
    } else {
        return getCheckoutPageRedirect();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 8 with CustomerPayment

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

the class BroadleafPaymentInfoController method savePaymentInfo.

/**
 * Processes the request to save an {@link OrderPayment} based on an existing or new {@link CustomerPayment}.
 *
 * Note: this default Broadleaf implementation will create a CustomerPayment if one does not exist,
 *  and copy it's data to a new OrderPayment.
 *
 * @param request
 * @param response
 * @param model
 * @param paymentForm
 * @return the return path
 * @throws ServiceException
 */
public String savePaymentInfo(HttpServletRequest request, HttpServletResponse response, Model model, PaymentInfoForm paymentForm, BindingResult result) throws PricingException, ServiceException {
    Order cart = CartState.getCart();
    Customer customer = CustomerState.getCustomer();
    preProcessBillingAddress(paymentForm, cart);
    paymentInfoFormValidator.validate(paymentForm, result);
    if (!result.hasErrors()) {
        if (paymentForm.getShouldSaveNewPayment() && !paymentForm.getShouldUseCustomerPayment()) {
            if (paymentForm.getCustomerPaymentId() != null) {
                savedPaymentService.updateSavedPayment(customer, paymentForm);
            } else if (paymentForm.getCustomerPaymentId() == null) {
                Long customerPaymentId = savedPaymentService.addSavedPayment(customer, paymentForm);
                paymentForm.setCustomerPaymentId(customerPaymentId);
                paymentForm.setShouldUseCustomerPayment(true);
            }
        }
        if (paymentForm.getShouldUseCustomerPayment()) {
            CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(paymentForm.getCustomerPaymentId());
            if (!cartStateService.cartHasCreditCardPaymentWithSameToken(customerPayment.getPaymentToken())) {
                orderService.removePaymentsFromOrder(cart, PaymentType.CREDIT_CARD);
                orderPaymentService.createOrderPaymentFromCustomerPayment(cart, customerPayment, cart.getTotalAfterAppliedPayments());
            }
        }
    }
    if (isAjaxRequest(request)) {
        // Add module specific model variables
        checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
        return getCheckoutView();
    } else {
        return getCheckoutPageRedirect();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment)

Example 9 with CustomerPayment

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

the class CustomerPaymentServiceImpl method setAsDefaultPayment.

@Override
@Transactional("blTransactionManager")
public CustomerPayment setAsDefaultPayment(CustomerPayment payment) {
    CustomerPayment oldDefault = findDefaultPaymentForCustomer(payment.getCustomer());
    if (oldDefault != null) {
        oldDefault.setIsDefault(false);
        saveCustomerPayment(oldDefault);
    }
    payment.setIsDefault(true);
    return saveCustomerPayment(payment);
}
Also used : CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with CustomerPayment

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

the class CustomerPaymentCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    OperationType fetchType = persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType();
    PersistenceModule persistenceModule = helper.getCompatibleModule(fetchType);
    DynamicResultSet drs = persistenceModule.fetch(persistencePackage, cto);
    for (Entity entity : drs.getRecords()) {
        Property customerPaymentId = entity.findProperty("id");
        if (customerPaymentId != null) {
            CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(Long.parseLong(customerPaymentId.getValue()));
            if (customerPayment != null) {
                String savedPaymentDisplayValue = buildSavedPaymentDisplayValue(customerPayment);
                Property derivedLabel = new Property();
                derivedLabel.setName(SAVED_PAYMENT_INFO);
                derivedLabel.setValue(savedPaymentDisplayValue);
                entity.addProperty(derivedLabel);
            }
        }
    }
    return drs;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) OperationType(org.broadleafcommerce.common.presentation.client.OperationType) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

CustomerPayment (org.broadleafcommerce.profile.core.domain.CustomerPayment)13 Customer (org.broadleafcommerce.profile.core.domain.Customer)5 Transactional (org.springframework.transaction.annotation.Transactional)3 Order (org.broadleafcommerce.core.order.domain.Order)2 Address (org.broadleafcommerce.profile.core.domain.Address)2 ArrayList (java.util.ArrayList)1 NoResultException (javax.persistence.NoResultException)1 Query (javax.persistence.Query)1 OperationType (org.broadleafcommerce.common.presentation.client.OperationType)1 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)1 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 PersistenceModule (org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule)1 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)1