@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); }
@Override public Long updateCustomerPaymentFromResponseDTO(PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) throws IllegalArgumentException { validateResponseAndConfig(responseDTO, config); String paymentToken = responseDTO.getPaymentToken(); CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentByToken(paymentToken); if (customerPayment != null) { populateCustomerPayment(customerPayment, responseDTO, config); customerPayment = customerPaymentService.saveCustomerPayment(customerPayment); return customerPayment.getId(); } return null; }
@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; }
@Override public PaymentInfoForm prePopulatePaymentInfoForm(PaymentInfoForm paymentInfoForm, ShippingInfoForm shippingInfoForm, Order cart) { Customer customer = CustomerState.getCustomer(); String emailAddress = getKnownEmailAddress(cart, customer); paymentInfoForm.setEmailAddress(emailAddress); Address billingAddress = getBillingAddress(cart); if (billingAddress != null) { paymentInfoForm.setAddress(billingAddress); } CustomerPayment customerPaymentUsedForOrder = getCustomerPaymentUsedForOrder(); Long customerPaymentId = (customerPaymentUsedForOrder == null) ? null : customerPaymentUsedForOrder.getId(); paymentInfoForm.setCustomerPaymentId(customerPaymentId); boolean shouldUseCustomerPaymentDefaultValue = getShouldUseCustomerPaymentDefaultValue(customerPaymentUsedForOrder); paymentInfoForm.setShouldUseCustomerPayment(shouldUseCustomerPaymentDefaultValue); boolean shouldUseShippingAddressDefaultValue = getShouldUseShippingAddressDefaultValue(customerPaymentUsedForOrder, paymentInfoForm, shippingInfoForm); paymentInfoForm.setShouldUseShippingAddress(shouldUseShippingAddressDefaultValue); boolean shouldSaveNewPaymentDefaultValue = getShouldSaveNewPaymentDefaultValue(); paymentInfoForm.setShouldSaveNewPayment(shouldSaveNewPaymentDefaultValue); return paymentInfoForm; }