Search in sources :

Example 6 with OrderPayment

use of org.broadleafcommerce.core.payment.domain.OrderPayment in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafCheckoutController method processPassthroughCheckout.

/**
 * Creates a pass-through payment of the PaymentType passed in with
 * an amount equal to the order total after any non-final applied payments.
 * (for example gift cards, customer credit, or third party accounts)
 *
 * This intended to be used in cases like COD and other Payment Types where implementations wish
 * to just checkout without having to do any payment processing.
 *
 * This default implementations assumes that the pass-through payment is the only
 * "final" payment, as this will remove any payments that are not PaymentTransactionType.UNCONFIRMED
 * That means that it will look at all transactions on the order payment and see if it has unconfirmed transactions.
 * If it does, it will not remove it.
 *
 * Make sure not to expose this method in your extended Controller if you do not wish to
 * have this feature enabled.
 *
 * @param redirectAttributes
 * @param paymentType
 * @return
 * @throws PaymentException
 * @throws PricingException
 */
public String processPassthroughCheckout(final RedirectAttributes redirectAttributes, PaymentType paymentType) throws PaymentException, PricingException {
    Order cart = CartState.getCart();
    // Invalidate any payments already on the order that do not have transactions on them that are UNCONFIRMED
    List<OrderPayment> paymentsToInvalidate = new ArrayList<OrderPayment>();
    for (OrderPayment payment : cart.getPayments()) {
        if (payment.isActive()) {
            if (payment.getTransactions() == null || payment.getTransactions().isEmpty()) {
                paymentsToInvalidate.add(payment);
            } else {
                for (PaymentTransaction transaction : payment.getTransactions()) {
                    if (!PaymentTransactionType.UNCONFIRMED.equals(transaction.getType())) {
                        paymentsToInvalidate.add(payment);
                    }
                }
            }
        }
    }
    for (OrderPayment payment : paymentsToInvalidate) {
        cart.getPayments().remove(payment);
        if (paymentGatewayCheckoutService != null) {
            paymentGatewayCheckoutService.markPaymentAsInvalid(payment.getId());
        }
    }
    // Create a new Order Payment of the passed in type
    OrderPayment passthroughPayment = orderPaymentService.create();
    passthroughPayment.setType(paymentType);
    passthroughPayment.setPaymentGatewayType(PaymentGatewayType.PASSTHROUGH);
    passthroughPayment.setAmount(cart.getTotalAfterAppliedPayments());
    passthroughPayment.setOrder(cart);
    // Create the transaction for the payment
    PaymentTransaction transaction = orderPaymentService.createTransaction();
    transaction.setAmount(cart.getTotalAfterAppliedPayments());
    transaction.setRawResponse("Passthrough Payment");
    transaction.setSuccess(true);
    transaction.setType(PaymentTransactionType.AUTHORIZE_AND_CAPTURE);
    transaction.getAdditionalFields().put(PassthroughPaymentConstants.PASSTHROUGH_PAYMENT_TYPE, paymentType.getType());
    transaction.setOrderPayment(passthroughPayment);
    passthroughPayment.addTransaction(transaction);
    orderService.addPaymentToOrder(cart, passthroughPayment, null);
    orderService.save(cart, true);
    return processCompleteCheckoutOrderFinalized(redirectAttributes);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) ArrayList(java.util.ArrayList) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 7 with OrderPayment

use of org.broadleafcommerce.core.payment.domain.OrderPayment in project BroadleafCommerce by BroadleafCommerce.

the class PaymentMethodVariableExpression method getCartOrderPaymentProperty.

protected String getCartOrderPaymentProperty(String propertyName) {
    Order cart = CartState.getCart();
    List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
    for (OrderPayment orderPayment : orderPayments) {
        if (orderPayment.isActive() && PaymentType.CREDIT_CARD.equals(orderPayment.getType())) {
            List<PaymentTransaction> transactions = orderPayment.getTransactions();
            for (PaymentTransaction transaction : transactions) {
                return transaction.getAdditionalFields().get(propertyName);
            }
        }
    }
    return null;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 8 with OrderPayment

use of org.broadleafcommerce.core.payment.domain.OrderPayment in project BroadleafCommerce by BroadleafCommerce.

the class CartStateServiceImpl method cartHasPopulatedBillingAddress.

@Override
public boolean cartHasPopulatedBillingAddress() {
    Order cart = CartState.getCart();
    List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
    for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
        boolean isCreditCardPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
        boolean paymentHasBillingAddress = (payment.getBillingAddress() != null);
        if (payment.isActive() && isCreditCardPayment && paymentHasBillingAddress) {
            return true;
        }
    }
    return false;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 9 with OrderPayment

use of org.broadleafcommerce.core.payment.domain.OrderPayment in project BroadleafCommerce by BroadleafCommerce.

the class CartStateServiceImpl method cartHasCreditCardPayment.

@Override
public boolean cartHasCreditCardPayment() {
    Order cart = CartState.getCart();
    List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
    for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
        boolean isCreditCartPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
        if (payment.isActive() && isCreditCartPayment) {
            return true;
        }
    }
    return false;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 10 with OrderPayment

use of org.broadleafcommerce.core.payment.domain.OrderPayment in project BroadleafCommerce by BroadleafCommerce.

the class CartStateServiceImpl method getUnconfirmedCCFromCart.

protected OrderPayment getUnconfirmedCCFromCart() {
    OrderPayment unconfirmedCC = null;
    Order cart = CartState.getCart();
    List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
    for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
        boolean isCreditCartPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
        boolean isTemporaryPaymentGateway = PaymentGatewayType.TEMPORARY.equals(payment.getGatewayType());
        if (payment.isActive() && isCreditCartPayment && !isTemporaryPaymentGateway) {
            unconfirmedCC = payment;
        }
    }
    return unconfirmedCC;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Aggregations

OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)33 Order (org.broadleafcommerce.core.order.domain.Order)16 PaymentTransaction (org.broadleafcommerce.core.payment.domain.PaymentTransaction)11 Money (org.broadleafcommerce.common.money.Money)7 ArrayList (java.util.ArrayList)6 Transactional (org.springframework.transaction.annotation.Transactional)6 PaymentResponseDTO (org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)5 Address (org.broadleafcommerce.profile.core.domain.Address)5 HashMap (java.util.HashMap)4 CheckoutException (org.broadleafcommerce.core.checkout.service.exception.CheckoutException)3 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 Test (org.testng.annotations.Test)3 PaymentGatewayType (org.broadleafcommerce.common.payment.PaymentGatewayType)2 PaymentRequestDTO (org.broadleafcommerce.common.payment.dto.PaymentRequestDTO)2 PaymentGatewayConfigurationService (org.broadleafcommerce.common.payment.service.PaymentGatewayConfigurationService)2 AdminPresentationMergeOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)2 OrderPaymentImpl (org.broadleafcommerce.core.payment.domain.OrderPaymentImpl)2 WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)2 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)2 Collection (java.util.Collection)1