Search in sources :

Example 16 with OrderPayment

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

the class OrderImpl method getTotalAfterAppliedPayments.

@Override
public Money getTotalAfterAppliedPayments() {
    Money myTotal = getTotal();
    if (myTotal == null) {
        return null;
    }
    Money totalPayments = BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, getCurrency());
    for (OrderPayment payment : getPayments()) {
        // add up all active payments that are not UNCONFIRMED Final Payments
        if (payment.isActive() && payment.getAmount() != null && (!payment.isFinalPayment() || payment.isConfirmed())) {
            totalPayments = totalPayments.add(payment.getAmount());
        }
    }
    return myTotal.subtract(totalPayments);
}
Also used : Money(org.broadleafcommerce.common.money.Money) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) AdminPresentationMergeOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationMergeOverride)

Example 17 with OrderPayment

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

the class OrderDaoImpl method delete.

@Override
public void delete(Order salesOrder) {
    if (!em.contains(salesOrder)) {
        salesOrder = readOrderById(salesOrder.getId());
    }
    // as they are not deleted but Archived.
    for (OrderPayment payment : salesOrder.getPayments()) {
        payment.setOrder(null);
        payment.setArchived('Y');
        for (PaymentTransaction transaction : payment.getTransactions()) {
            transaction.setArchived('Y');
        }
    }
    em.remove(salesOrder);
}
Also used : PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 18 with OrderPayment

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

the class AdjustOrderPaymentsActivity method execute.

@Override
public ProcessContext<Order> execute(ProcessContext<Order> context) throws Exception {
    Order order = context.getSeedData();
    OrderPayment unconfirmedThirdPartyOrCreditCard = null;
    Money appliedPaymentsWithoutThirdPartyOrCC = Money.ZERO;
    for (OrderPayment payment : order.getPayments()) {
        if (payment.isActive()) {
            if (!payment.isConfirmed() && payment.isFinalPayment()) {
                unconfirmedThirdPartyOrCreditCard = payment;
            } else if (payment.getAmount() != null) {
                appliedPaymentsWithoutThirdPartyOrCC = appliedPaymentsWithoutThirdPartyOrCC.add(payment.getAmount());
            }
        }
    }
    if (unconfirmedThirdPartyOrCreditCard != null) {
        Money difference = order.getTotal().subtract(appliedPaymentsWithoutThirdPartyOrCC);
        unconfirmedThirdPartyOrCreditCard.setAmount(difference);
    }
    context.setSeedData(order);
    return context;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 19 with OrderPayment

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

the class OrderToPaymentRequestDTOServiceImpl method populateBillTo.

@Override
public void populateBillTo(Order order, PaymentRequestDTO requestDTO) {
    for (OrderPayment payment : order.getPayments()) {
        if (payment.isActive()) {
            Address billAddress = payment.getBillingAddress();
            if (billAddress != null) {
                String stateAbbr = null;
                String countryAbbr = null;
                String phone = null;
                if (StringUtils.isNotBlank(billAddress.getStateProvinceRegion())) {
                    stateAbbr = billAddress.getStateProvinceRegion();
                } else if (billAddress.getState() != null) {
                    // support legacy
                    stateAbbr = billAddress.getState().getAbbreviation();
                }
                if (billAddress.getIsoCountryAlpha2() != null) {
                    countryAbbr = billAddress.getIsoCountryAlpha2().getAlpha2();
                } else if (billAddress.getCountry() != null) {
                    // support legacy
                    countryAbbr = billAddress.getCountry().getAbbreviation();
                }
                if (billAddress.getPhonePrimary() != null) {
                    phone = billAddress.getPhonePrimary().getPhoneNumber();
                }
                NameResponse name = getName(billAddress);
                requestDTO.billTo().addressFirstName(name.firstName).addressLastName(name.lastName).addressCompanyName(billAddress.getCompanyName()).addressLine1(billAddress.getAddressLine1()).addressLine2(billAddress.getAddressLine2()).addressCityLocality(billAddress.getCity()).addressStateRegion(stateAbbr).addressPostalCode(billAddress.getPostalCode()).addressCountryCode(countryAbbr).addressPhone(phone).addressEmail(billAddress.getEmailAddress());
            }
        }
    }
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 20 with OrderPayment

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

the class PaymentInfoServiceTest method createTestPayment.

@Test(groups = { "testCreatePaymentInfo" }, dependsOnGroups = { "createPaymentInfo" })
@Transactional
public void createTestPayment() {
    userName = "customer1";
    OrderPayment paymentInfo = paymentInfoService.create();
    Customer customer = customerService.readCustomerByUsername(userName);
    List<CustomerAddress> addresses = customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId());
    Address address = null;
    if (!addresses.isEmpty())
        address = addresses.get(0).getAddress();
    Order salesOrder = orderService.findCartForCustomer(customer);
    paymentInfo.setBillingAddress(address);
    paymentInfo.setOrder(salesOrder);
    paymentInfo.setType(PaymentType.CREDIT_CARD);
    assert paymentInfo != null;
    paymentInfo = paymentInfoService.save(paymentInfo);
    assert paymentInfo.getId() != null;
    Long paymentInfoId = paymentInfo.getId();
    paymentInfoService.delete(paymentInfo);
    paymentInfo = paymentInfoService.readPaymentById(paymentInfoId);
    assert paymentInfo == null;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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