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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations