@Override
  @Transactional("blTransactionManager")
  public PaymentInfo addPaymentToOrder(
      Order order, PaymentInfo payment, Referenced securePaymentInfo) {
    payment.setOrder(order);
    order.getPaymentInfos().add(payment);
    order = persist(order);
    int paymentIndex = order.getPaymentInfos().size() - 1;

    if (securePaymentInfo != null) {
      securePaymentInfoService.save(securePaymentInfo);
    }

    return order.getPaymentInfos().get(paymentIndex);
  }
 @Override
 @Transactional("blTransactionManager")
 public void removePaymentFromOrder(Order order, PaymentInfo paymentInfo) {
   PaymentInfo paymentInfoToRemove = null;
   for (PaymentInfo info : order.getPaymentInfos()) {
     if (info.equals(paymentInfo)) {
       paymentInfoToRemove = info;
     }
   }
   if (paymentInfoToRemove != null) {
     try {
       securePaymentInfoService.findAndRemoveSecurePaymentInfo(
           paymentInfoToRemove.getReferenceNumber(), paymentInfo.getType());
     } catch (WorkflowException e) {
       // do nothing--this is an acceptable condition
       LOG.debug("No secure payment is associated with the PaymentInfo", e);
     }
     order.getPaymentInfos().remove(paymentInfoToRemove);
     paymentInfo = paymentInfoDao.readPaymentInfoById(paymentInfoToRemove.getId());
     paymentInfoDao.delete(paymentInfo);
   }
 }
 @Override
 @Transactional("blTransactionManager")
 public void removePaymentsFromOrder(Order order, PaymentInfoType paymentInfoType) {
   List<PaymentInfo> infos = new ArrayList<PaymentInfo>();
   for (PaymentInfo paymentInfo : order.getPaymentInfos()) {
     if (paymentInfoType == null || paymentInfoType.equals(paymentInfo.getType())) {
       infos.add(paymentInfo);
     }
   }
   order.getPaymentInfos().removeAll(infos);
   for (PaymentInfo paymentInfo : infos) {
     try {
       securePaymentInfoService.findAndRemoveSecurePaymentInfo(
           paymentInfo.getReferenceNumber(), paymentInfo.getType());
     } catch (WorkflowException e) {
       // do nothing--this is an acceptable condition
       LOG.debug("No secure payment is associated with the PaymentInfo", e);
     }
     order.getPaymentInfos().remove(paymentInfo);
     paymentInfo = paymentInfoDao.readPaymentInfoById(paymentInfo.getId());
     paymentInfoDao.delete(paymentInfo);
   }
 }