@Override @Transactional("blTransactionManager") public Customer deleteCustomerPaymentFromCustomer(Customer customer, CustomerPayment payment) { List<CustomerPayment> payments = customer.getCustomerPayments(); for (CustomerPayment customerPayment : payments) { if (customerPayment.getId().equals(payment.getId())) { customer.getCustomerPayments().remove(customerPayment); break; } } return customerService.saveCustomer(customer); }
/** * A temporary credit card {@link OrderPayment} will only be added to the cart if the customer has opted out * of saving their credit card for future payments. * @param customerPaymentUsedForOrder */ protected boolean getShouldUseCustomerPaymentDefaultValue(CustomerPayment customerPaymentUsedForOrder) { boolean customerSavedPaymentsAreEnabled = areCustomerSavedPaymentsEnabled(); boolean customerHasSavedPayments = CollectionUtils.isNotEmpty(CustomerState.getCustomer().getCustomerPayments()); boolean orderUsingCustomerPayment = (customerPaymentUsedForOrder != null); boolean cartHasTemporaryCreditCard = cartStateService.cartHasTemporaryCreditCard(); return customerSavedPaymentsAreEnabled && (orderUsingCustomerPayment || (!cartHasTemporaryCreditCard && customerHasSavedPayments)); }
@Override public Long createCustomerPaymentFromResponseDTO(PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) throws IllegalArgumentException { validateResponseAndConfig(responseDTO, config); Long customerId = Long.parseLong(responseDTO.getCustomer().getCustomerId()); Customer customer = customerService.readCustomerById(customerId); if (customer != null) { if (isNewDefaultPaymentMethod(responseDTO)) { customerPaymentService.clearDefaultPaymentStatus(customer); } CustomerPayment customerPayment = customerPaymentService.create(); populateCustomerPayment(customerPayment, responseDTO, config); customerPayment.setCustomer(customer); customerPayment = customerPaymentService.saveCustomerPayment(customerPayment); customer.getCustomerPayments().add(customerPayment); return customerPayment.getId(); } return null; }
CustomerPayment clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone(); clonedEntry.setCustomer(cloned); cloned.getCustomerPayments().add(clonedEntry);