/** * Concatenates firstName and lastName. * * @param user The consumer. * @return The customers firstName and lastName. */ @NonNull private String getCustomerName(final User user) { final StringBuilder customerName = new StringBuilder(); if (!TextUtils.isEmpty(user.getFirstName())) { customerName.append(user.getFirstName()); } if (!TextUtils.isEmpty(user.getLastName())) { customerName.append(" ").append(user.getLastName()); } return customerName.toString(); }
/** Fills payment address view. */ private void displayShippingAddress() { final StringBuilder descriptionTextBuilder = new StringBuilder(); final PaymentAuth paymentAuth = mTransaction.getPaymentAuth(); final PaymentRequest paymentRequest = mTransaction.getPaymentRequest(); final DeliveryType deliveryType = paymentRequest.getDeliveryType(); final DeliveryAddress deliveryAddress = paymentAuth == null ? null : paymentAuth.getDeliveryAddress(); switch (deliveryType) { case ADDRESS: case COLLECT_IN_STORE: case SERVICE: if (paymentRequest.getRtpType() == RTPType.DEFERRED) { if (deliveryAddress != null) { final User user = deliveryAddress.getAddressee(); if (user != null) { final String[] addressArray = { getCustomerName(user), user.getEmail(), user.getPhone(), deliveryAddress.getLine1(), deliveryAddress.getLine2(), deliveryAddress.getLine3(), deliveryAddress.getLine4(), deliveryAddress.getLine5(), deliveryAddress.getLine6(), deliveryAddress.getPostCode(), deliveryAddress.getCountryCode() }; displayAddresseeInfo(descriptionTextBuilder, addressArray); } } } else { // TODO as PaymentAuth does not contain the SettlementStatus, it cannot be used for // payment authorisation for immediate payments, // TODO retrieve the shipping address from PaymentRequest. final User user = paymentRequest.getUser(); final Address address = paymentRequest.getAddress(); if (user != null) { final String[] addressArray = { getCustomerName(user), user.getEmail(), user.getPhone(), address.getLine1(), address.getLine2(), address.getLine3(), address.getLine4(), address.getLine5(), address.getLine6(), address.getPostCode(), address.getCountryCode() }; displayAddresseeInfo(descriptionTextBuilder, addressArray); } } break; case DIGITAL: final User user = paymentAuth != null ? paymentAuth.getUser() : paymentRequest.getUser(); if (user != null) { final String[] addressArray = {getCustomerName(user), user.getEmail(), user.getPhone()}; displayAddresseeInfo(descriptionTextBuilder, addressArray); } break; default: break; } if (descriptionTextBuilder.length() > 0) { mPaymentAddressTextView.setText(Html.fromHtml(descriptionTextBuilder.toString())); mPaymentAddressTextView.setVisibility(View.VISIBLE); } }