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