use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderDate method renderField.
@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
if (field == null) {
throw new InvalidParameterException("Error rendering datefield, field may not be null");
}
if (rowView == null) {
throw new InvalidParameterException("Error rendering datefield, rowView may not be null");
}
if (inputDataPersister == null) {
throw new InvalidParameterException("Error rendering datefield, inputDataPersister may not be null");
}
AccountOnFile accountOnFile = inputDataPersister.getAccountOnFile();
DatePicker datePicker = new DatePicker(rowView.getContext());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
datePicker.setCalendarViewShown(false);
datePicker.setSpinnersShown(true);
}
// Create a listener here, which we can use to provide to all init calls
OnDateChangedListener listener = createOnDateChangedListener(inputDataPersister, field.getId());
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
datePicker.init(year, month, day, listener);
// Set values from account on file
if (accountOnFile != null) {
for (KeyValuePair attribute : accountOnFile.getAttributes()) {
if (attribute.getKey().equals(field.getId())) {
String date = attribute.getValue();
setDateFromString(datePicker, date, listener);
}
if (!attribute.isEditingAllowed()) {
datePicker.setEnabled(false);
}
}
}
// get input information from inputDataPersister
String setDate = inputDataPersister.getValue(field.getId());
if (setDate != null && accountOnFile == null) {
setDateFromString(datePicker, setDate, listener);
}
rowView.addView(datePicker);
return datePicker;
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile in project connect-sdk-client-android by Ingenico-ePayments.
the class BasicPaymentItemsAsyncTask method createBasicPaymentItems.
private BasicPaymentItems createBasicPaymentItems(BasicPaymentProducts basicPaymentProducts, BasicPaymentProductGroups basicPaymentProductGroups) {
// Validate the results of the calls
if (basicPaymentProducts == null && basicPaymentProductGroups == null) {
// If both basicPaymentProducts and basicPaymentProductGroups are null, return nul
return null;
} else if (basicPaymentProductGroups == null) {
// If basicPaymentProductGroups == null, return just the basicPaymentProducts
return new BasicPaymentItems(basicPaymentProducts.getPaymentProductsAsItems(), basicPaymentProducts.getAccountsOnFile());
} else if (basicPaymentProducts == null) {
// If basicPaymentProducts == null, return just the basicPaymentProductGroups
return new BasicPaymentItems(basicPaymentProductGroups.getPaymentProductGroupsAsItems(), basicPaymentProductGroups.getAccountsOnFile());
}
// Else: Merge the paymentItems together.
// Create a list of PaymentProductSelectables that will be filled and stored in the basicPaymentItems object that is returned
List<BasicPaymentItem> basicPaymentItems = new ArrayList<>();
// Create a list of AccountOnFiles that will be filled and stored in the basicPaymentItems object that is returned
List<AccountOnFile> accountsOnFile = new LinkedList<>();
// list of basicPaymentItems that will be returned.
for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
// Add the accountsOnFile of the current paymentProduct to the collection of accountOnFiles.
accountsOnFile.addAll(paymentProduct.getAccountsOnFile());
// becomes true if the paymentProduct has been matched with a group.
boolean groupMatch = false;
for (BasicPaymentProductGroup paymentProductGroup : basicPaymentProductGroups.getBasicPaymentProductGroups()) {
// Does the current paymentProduct belong to the current paymentProductGroup
if (paymentProduct.getPaymentProductGroup() != null && paymentProduct.getPaymentProductGroup().equals(paymentProductGroup.getId())) {
// Add the paymentProductGroup to the basicPaymentItems that will be returned if it is not already in the list
if (!basicPaymentItems.contains(paymentProductGroup)) {
// Set the displayOrder of the group to the displayOrder of the first paymentProduct match
paymentProductGroup.getDisplayHints().setDisplayOrder(paymentProduct.getDisplayHints().getDisplayOrder());
basicPaymentItems.add(paymentProductGroup);
}
// Product has been matched to a group
groupMatch = true;
// Products can not match with more then one group
break;
}
}
if (!groupMatch) {
// If the paymentProduct does not belong to a paymentProductGroup, add the paymentProduct to the
// basicPaymentItems that will be returned
basicPaymentItems.add(paymentProduct);
}
}
// Return a new BasicPaymentItems object that contains the paymentItems and the accountsOnFile
return new BasicPaymentItems(basicPaymentItems, accountsOnFile);
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderTextField method renderField.
@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
if (field == null) {
throw new InvalidParameterException("Error rendering textfield, field may not be null");
}
if (rowView == null) {
throw new InvalidParameterException("Error rendering textfield, rowView may not be null");
}
if (inputDataPersister == null) {
throw new InvalidParameterException("Error rendering textfield, inputDataPersister may not be null");
}
PaymentItem paymentItem = inputDataPersister.getPaymentItem();
AccountOnFile accountOnFile = inputDataPersister.getAccountOnFile();
// Create new EditText and set its style, restrictions, mask and keyboardtype
EditText editText = new EditText(rowView.getContext());
editText.setTextAppearance(rowView.getContext(), R.style.TextField);
if (field.getDataRestrictions().getValidator().getLength() != null) {
// Set maxLength for field
Integer maxLength = field.getDataRestrictions().getValidator().getLength().getMaxLength();
if (maxLength > 0) {
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });
editText.setEms(maxLength);
}
}
Translator translator = Translator.getInstance(rowView.getContext());
String label = translator.getPaymentProductFieldPlaceholderText(paymentItem.getId(), field.getId());
editText.setHint(label);
// Set correct inputType type
switch(field.getDisplayHints().getPreferredInputType()) {
case INTEGER_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
break;
case STRING_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
break;
case PHONE_NUMBER_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
break;
case EMAIL_ADDRESS_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
break;
case DATE_PICKER:
editText.setInputType(InputType.TYPE_DATETIME_VARIATION_DATE);
default:
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
break;
}
// Check if this edittext should be obfuscated
if (field.getDisplayHints().isObfuscate()) {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
// Add mask functionality when a mask is set
Boolean addMasking = field.getDisplayHints().getMask() != null;
Integer maskLength = 0;
if (field.getDisplayHints().getMask() != null) {
maskLength = field.getDisplayHints().getMask().replace("{", "").replace("}", "").length();
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maskLength) });
} else if (field.getDataRestrictions().getValidator().getLength() != null) {
maskLength = field.getDataRestrictions().getValidator().getLength().getMaxLength();
}
// Set values from account on file
if (accountOnFile != null) {
for (KeyValuePair attribute : accountOnFile.getAttributes()) {
if (attribute.getKey().equals(field.getId())) {
if (field.getDisplayHints().getMask() != null) {
StringFormatter stringFormatter = new StringFormatter();
String maskedValue = stringFormatter.applyMask(field.getDisplayHints().getMask().replace("9", "*"), attribute.getValue());
editText.setText(maskedValue);
} else {
editText.setText(attribute.getValue());
}
if (!attribute.isEditingAllowed()) {
editText.setEnabled(false);
}
}
}
}
// Add OnTextChanged watcher for this inputfield
editText.addTextChangedListener(new FieldInputTextWatcher(inputDataPersister, field.getId(), editText, addMasking));
// get input information from inputDataPersister
String paymentProductValue = inputDataPersister.getValue(field.getId());
if (paymentProductValue != null && accountOnFile == null) {
editText.setText(paymentProductValue);
}
// Add it to parentView
rowView.addView(editText);
return editText;
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile in project connect-sdk-client-android by Ingenico-ePayments.
the class ProductSelectionViewImpl method renderDynamicContent.
@Override
public void renderDynamicContent(BasicPaymentItems paymentItems) {
// Render all basic paymentitems and accounts on file
for (BasicPaymentItem basicPaymentItem : paymentItems.getBasicPaymentItems()) {
paymentItemRenderer.renderPaymentItem(basicPaymentItem, renderProductsLayout);
}
// Check if there are accountsOnFile, then set their container and header to visible
if (!paymentItems.getAccountsOnFile().isEmpty()) {
rootView.findViewById(R.id.listAccountsOnFileHeader).setVisibility(View.VISIBLE);
rootView.findViewById(R.id.listAccountsOnFile).setVisibility(View.VISIBLE);
rootView.findViewById(R.id.listAccountsOnFileDivider).setVisibility(View.VISIBLE);
// Render all accountsOnFile
for (AccountOnFile accountOnFile : paymentItems.getAccountsOnFile()) {
accountOnFileRenderer.renderAccountOnFile(accountOnFile, accountOnFile.getPaymentProductId(), renderAccountOnFilesLayout);
}
}
}
Aggregations