@Override public <G extends CustomerPayment> CreateResponse<G> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<G> createResponse = context.createOrRetrieveCopyInstance(this); if (createResponse.isAlreadyPopulated()) { return createResponse; } CustomerPayment cloned = createResponse.getClone(); // dont clone cloned.setCustomer(customer); cloned.setBillingAddress(billingAddress.createOrRetrieveCopyInstance(context).getClone()); cloned.setIsDefault(isDefault); cloned.setPaymentToken(paymentToken); for (Map.Entry<String, String> entry : additionalFields.entrySet()) { cloned.getAdditionalFields().put(entry.getKey(), entry.getValue()); } return createResponse; }
@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 @Transactional("blTransactionManager") public CustomerPayment setAsDefaultPayment(CustomerPayment payment) { CustomerPayment oldDefault = findDefaultPaymentForCustomer(payment.getCustomer()); if (oldDefault != null) { oldDefault.setIsDefault(false); saveCustomerPayment(oldDefault); } payment.setIsDefault(true); return saveCustomerPayment(payment); }
@Override @Transactional(value = TransactionUtils.DEFAULT_TRANSACTION_MANAGER) public CustomerPayment createCustomerPaymentFromPaymentTransaction(PaymentTransaction transaction) { CustomerPayment customerPayment = customerPaymentService.create(); customerPayment.setCustomer(transaction.getOrderPayment().getOrder().getCustomer()); customerPayment.setBillingAddress(addressService.copyAddress(transaction.getOrderPayment().getBillingAddress())); customerPayment.setPaymentType(transaction.getOrderPayment().getType()); customerPayment.setPaymentGatewayType(transaction.getOrderPayment().getGatewayType()); customerPayment.setAdditionalFields(transaction.getAdditionalFields()); populateCustomerPaymentToken(customerPayment, transaction); return customerPaymentService.saveCustomerPayment(customerPayment); }
protected void populateCustomerPayment(CustomerPayment customerPayment, PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) { Map<String, String> responseMap = responseDTO.getResponseMap(); customerPayment.setPaymentGatewayType(config.getGatewayType()); customerPayment.setPaymentType(responseDTO.getPaymentType()); customerPayment.setAdditionalFields(responseMap); dtoToEntityService.populateCustomerPaymentToken(responseDTO, customerPayment); Address billingAddress = addressService.create(); dtoToEntityService.populateAddressInfo(responseDTO.getBillTo(), billingAddress); customerPayment.setBillingAddress(billingAddress); customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.NAME_ON_CARD.getType(), responseDTO.getCreditCard().getCreditCardHolderName()); customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.LAST_FOUR.getType(), responseDTO.getCreditCard().getCreditCardLastFour()); customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.CARD_TYPE.getType(), responseDTO.getCreditCard().getCreditCardType()); customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_DATE.getType(), responseDTO.getCreditCard().getCreditCardExpDate()); customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_MONTH.getType(), responseDTO.getCreditCard().getCreditCardExpMonth()); customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_YEAR.getType(), responseDTO.getCreditCard().getCreditCardExpYear()); customerPayment.setIsDefault(Boolean.parseBoolean(isDefault));
OrderPayment orderPayment = create(); orderPayment.setOrder(order); orderPayment.setBillingAddress(addressService.copyAddress(customerPayment.getBillingAddress())); PaymentGatewayType gatewayType = customerPayment.getPaymentGatewayType(); PaymentType paymentType = customerPayment.getPaymentType(); Map<String, String> additionalFields = customerPayment.getAdditionalFields(); if (gatewayType == null || paymentType == null) { if (MapUtils.isEmpty(additionalFields)) { unconfirmedTransaction.setType(PaymentTransactionType.UNCONFIRMED); unconfirmedTransaction.setOrderPayment(orderPayment); unconfirmedTransaction.getAdditionalFields().put(PaymentAdditionalFieldType.TOKEN.getType(), customerPayment.getPaymentToken()); unconfirmedTransaction.getAdditionalFields().putAll(customerPayment.getAdditionalFields());
@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; }
protected String buildSavedPaymentDisplayValue(CustomerPayment customerPayment) { String displayValue = new String(); Map<String, String> fields = customerPayment.getAdditionalFields(); if (MapUtils.isNotEmpty(fields)) { displayValue += buildPropertyValueIfAvailable(displayValue, fields.get(PaymentAdditionalFieldType.NAME_ON_CARD.getType())); displayValue += buildPropertyValueIfAvailable(displayValue, fields.get(PaymentAdditionalFieldType.CARD_TYPE.getType())); displayValue += buildPropertyValueIfAvailable(displayValue, fields.get(PaymentAdditionalFieldType.EXP_DATE.getType())); displayValue += buildPropertyValueIfAvailable(displayValue, "****" + fields.get(PaymentAdditionalFieldType.LAST_FOUR.getType())); } return displayValue; }
cloned.setDeactivated(deactivated); for (CustomerPayment entry : customerPayments) { CustomerPayment clonedEntry = entry.createOrRetrieveCopyInstance(context).getClone(); clonedEntry.setCustomer(cloned); cloned.getCustomerPayments().add(clonedEntry);
protected CustomerPayment getCustomerPaymentUsedForOrder() { Customer customer = CustomerState.getCustomer(); List<CustomerPayment> customerPayments = customerPaymentService.readCustomerPaymentsByCustomerId(customer.getId()); for (CustomerPayment customerPayment : customerPayments) { if (cartStateService.cartHasCreditCardPaymentWithSameToken(customerPayment.getPaymentToken())) { return customerPayment; } } return null; }
@Override public void populateCustomerPaymentToken(PaymentResponseDTO responseDTO, CustomerPayment customerPayment) { if (responseDTO.getPaymentToken() != null) { customerPayment.setPaymentToken(responseDTO.getPaymentToken()); } else if (responseDTO.getResponseMap().containsKey(PaymentAdditionalFieldType.TOKEN.getType())) { //handle legacy additional fields map customerPayment.setPaymentToken(responseDTO.getResponseMap().get(PaymentAdditionalFieldType.TOKEN.getType())); } else if (responseDTO.getCreditCard() != null) { //handle higher PCI level compliance scenarios customerPayment.setPaymentToken(responseDTO.getCreditCard().getCreditCardNum()); } }
protected void copyCustomerPaymentAddressToBillingAddress(PaymentInfoForm paymentForm) { CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(paymentForm.getCustomerPaymentId()); if (customerPayment != null) { Address address = customerPayment.getBillingAddress(); if (address != null) { paymentForm.setAddress(addressService.copyAddress(address)); } } }
@Override @Transactional("blTransactionManager") public void clearDefaultPaymentStatus(Customer customer) { CustomerPayment oldDefault = findDefaultPaymentForCustomer(customer); if (oldDefault != null) { oldDefault.setIsDefault(false); saveCustomerPayment(oldDefault); } }
CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(paymentForm.getCustomerPaymentId()); if (!cartStateService.cartHasCreditCardPaymentWithSameToken(customerPayment.getPaymentToken())) { orderService.removePaymentsFromOrder(cart, PaymentType.CREDIT_CARD); orderPaymentService.createOrderPaymentFromCustomerPayment(cart, customerPayment, cart.getTotalAfterAppliedPayments());
@Override public void populateCustomerPaymentToken(CustomerPayment customerPayment, PaymentTransaction transaction) { if (transaction.getAdditionalFields().containsKey(PaymentAdditionalFieldType.TOKEN.getType())) { customerPayment.setPaymentToken(transaction.getAdditionalFields().get(PaymentAdditionalFieldType.TOKEN.getType())); } }
Address address = customerPayment.getBillingAddress(); if (address != null) { billingForm.setAddress(addressService.copyAddress(address));
@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; }
public CustomerPayment findDefaultPaymentForCustomer(Customer customer) { if (customer == null) { return null; } List<CustomerPayment> payments = readCustomerPaymentsByCustomerId(customer.getId()); for (CustomerPayment payment : payments) { if (payment.isDefault()) { return payment; } } 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; }