Search in sources :

Example 1 with AccountOnFile

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;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) OnDateChangedListener(android.widget.DatePicker.OnDateChangedListener) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker)

Example 2 with AccountOnFile

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);
}
Also used : BasicPaymentItems(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) BasicPaymentProductGroup(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup) ArrayList(java.util.ArrayList) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) LinkedList(java.util.LinkedList) BasicPaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)

Example 3 with AccountOnFile

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;
}
Also used : EditText(android.widget.EditText) InputFilter(android.text.InputFilter) KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) PaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem) StringFormatter(com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter) InvalidParameterException(java.security.InvalidParameterException) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) Translator(com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator)

Example 4 with AccountOnFile

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);
        }
    }
}
Also used : RenderAccountOnFile(com.globalcollect.gateway.sdk.client.android.exampleapp.render.accountonfile.RenderAccountOnFile) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) BasicPaymentItem(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)

Aggregations

AccountOnFile (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile)4 BasicPaymentItem (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItem)2 KeyValuePair (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair)2 InvalidParameterException (java.security.InvalidParameterException)2 InputFilter (android.text.InputFilter)1 DatePicker (android.widget.DatePicker)1 OnDateChangedListener (android.widget.DatePicker.OnDateChangedListener)1 EditText (android.widget.EditText)1 RenderAccountOnFile (com.globalcollect.gateway.sdk.client.android.exampleapp.render.accountonfile.RenderAccountOnFile)1 Translator (com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator)1 StringFormatter (com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter)1 BasicPaymentItems (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentItems)1 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)1 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)1 PaymentItem (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 LinkedList (java.util.LinkedList)1