Search in sources :

Example 1 with KeyValuePair

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair in project connect-sdk-client-android by Ingenico-ePayments.

the class RenderCurrency method renderField.

@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
    if (field == null) {
        throw new InvalidParameterException("Error rendering currency, field may not be null");
    }
    if (inputDataPersister == null) {
        throw new InvalidParameterException("Error rendering currency, inputDataPersister may not be null");
    }
    if (rowView == null) {
        throw new InvalidParameterException("Error rendering currency, rowView may not be null");
    }
    if (paymentContext == null) {
        throw new InvalidParameterException("Error rendering currency, paymentContext may not be null");
    }
    PaymentItem paymentItem = inputDataPersister.getPaymentItem();
    // Create new EditText and set its style, restrictions, mask and keyboardtype
    EditText integerPart = new EditText(rowView.getContext());
    // maxlength is 9 - 2 so no integer overflow
    integerPart.setFilters(new InputFilter[] { new InputFilter.LengthFilter(7) });
    Translator translator = Translator.getInstance(rowView.getContext());
    String label = translator.getPaymentProductFieldLabel(paymentItem.getId(), field.getId());
    integerPart.setHint(label);
    // Set correct inputType type
    switch(field.getDisplayHints().getPreferredInputType()) {
        case INTEGER_KEYBOARD:
            integerPart.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
            break;
        case STRING_KEYBOARD:
            integerPart.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
            break;
        case PHONE_NUMBER_KEYBOARD:
            integerPart.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
            break;
        case EMAIL_ADDRESS_KEYBOARD:
            integerPart.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            break;
        default:
            integerPart.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
            break;
    }
    // Check if this edittext should be obfuscated
    if (field.getDisplayHints().isObfuscate()) {
        integerPart.setTransformationMethod(PasswordTransformationMethod.getInstance());
    }
    // Set values from account on file
    if (inputDataPersister.getAccountOnFile() != null) {
        for (KeyValuePair attribute : inputDataPersister.getAccountOnFile().getAttributes()) {
            if (attribute.getKey().equals(field.getId())) {
                StringFormatter stringFormatter = new StringFormatter();
                String maskedValue = stringFormatter.applyMask(field.getDisplayHints().getMask().replace("9", "*"), attribute.getValue());
                integerPart.setText(maskedValue);
                if (!attribute.isEditingAllowed()) {
                    integerPart.setEnabled(false);
                }
            }
        }
    }
    LinearLayout linearLayout = new LinearLayout(rowView.getContext());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    TextView currencySymbol = new TextView(rowView.getContext());
    currencySymbol.setText(paymentContext.getAmountOfMoney().getCurrencyCode().toString());
    TextView separator = new TextView(rowView.getContext());
    String separatorLabel = translator.getPaymentProductFieldLabel(paymentItem.getId(), "separator");
    separator.setText(separatorLabel);
    EditText decimalPart = new EditText(rowView.getContext());
    decimalPart.setHint("00");
    decimalPart.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
    decimalPart.setFilters(new InputFilter[] { new InputFilter.LengthFilter(2) });
    integerPart.addTextChangedListener(new FieldInputTextWatcherCurrency(inputDataPersister, field.getId(), decimalPart, true));
    decimalPart.addTextChangedListener(new FieldInputTextWatcherCurrency(inputDataPersister, field.getId(), integerPart, false));
    // Restore data that has previously been entered in this field
    if (inputDataPersister.getValue(field.getId()) != null) {
        String value = inputDataPersister.getValue(field.getId());
        if (value.length() > 2) {
            integerPart.setText(value.substring(0, value.length() - 2));
        }
        if (!value.endsWith("00")) {
            decimalPart.setText(value.substring(value.length() - 2));
        }
    }
    LinearLayout.LayoutParams params0 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
    linearLayout.addView(currencySymbol, params0);
    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f);
    linearLayout.addView(integerPart, params1);
    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
    linearLayout.addView(separator, params2);
    LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
    linearLayout.addView(decimalPart, params3);
    // Add it to parentView
    rowView.addView(linearLayout);
    return linearLayout;
}
Also used : EditText(android.widget.EditText) InputFilter(android.text.InputFilter) LayoutParams(android.view.ViewGroup.LayoutParams) 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) Translator(com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 2 with KeyValuePair

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair in project connect-sdk-client-android by Ingenico-ePayments.

the class RenderList method renderField.

@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
    if (field == null) {
        throw new InvalidParameterException("Error rendering list, field may not be null");
    }
    if (inputDataPersister == null) {
        throw new InvalidParameterException("Error rendering list, inputDataPersister may not be null");
    }
    if (rowView == null) {
        throw new InvalidParameterException("Error rendering list, rowView may not be null");
    }
    this.field = field;
    this.inputDataPersister = inputDataPersister;
    // Create new spinner and fill its values
    Spinner spinner = new Spinner(rowView.getContext());
    // Parse the loaded values to array and set as ArrayAdapter
    values = new ArrayList<>();
    // Fill values
    for (ValueMap valueMap : field.getDisplayHints().getFormElement().getValueMapping()) {
        values.add(getDisplayNameFromDisplayElements(valueMap.getDisplayElements()));
    }
    // Make and set adapter to spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(rowView.getContext(), android.R.layout.simple_spinner_item, values);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);
    // Set the spinner to the stored value in the account
    if (inputDataPersister.getAccountOnFile() != null) {
        for (KeyValuePair attribute : inputDataPersister.getAccountOnFile().getAttributes()) {
            if (attribute.getKey().equals(field.getId())) {
                int spinnerPosition = dataAdapter.getPosition(attribute.getValue());
                spinner.setSelection(spinnerPosition);
                if (!attribute.isEditingAllowed()) {
                    spinner.setEnabled(false);
                }
            }
        }
    }
    // is redrawn (i.e. when the user turns the phone)
    if (inputDataPersister.getValue(field.getId()) != null) {
        int spinnerPosition = dataAdapter.getPosition(inputDataPersister.getValue(field.getId()));
        spinner.setSelection(spinnerPosition);
    }
    // Add this as listener for this inputfield
    spinner.setOnItemSelectedListener(this);
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    rowView.addView(spinner, params);
    return spinner;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) LayoutParams(android.widget.LinearLayout.LayoutParams) KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) Spinner(android.widget.Spinner) ValueMap(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.ValueMap) ArrayAdapter(android.widget.ArrayAdapter)

Example 3 with KeyValuePair

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair 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 4 with KeyValuePair

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair in project connect-sdk-client-android by Ingenico-ePayments.

the class CustomerDetailsAsyncTaskTest method testCustomerDetailsAsyncTaskWithValidRequest.

@Test
public void testCustomerDetailsAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    final CountDownLatch waitForAsyncTaskCallBack = new CountDownLatch(1);
    Listener listener = new Listener(waitForAsyncTaskCallBack);
    KeyValuePair keyValuePair = new KeyValuePair();
    keyValuePair.setKey("fiscalNumber");
    keyValuePair.setValue("4605092222");
    List<KeyValuePair> values = new ArrayList<>();
    values.add(keyValuePair);
    // Create the CustomerDetailsAsyncTask and start the test by running execute
    CustomerDetailsAsyncTask customerDetailsAsyncTask = new CustomerDetailsAsyncTask(getContext(), "9000", CountryCode.SE, values, getCommunicator(), listener);
    customerDetailsAsyncTask.execute();
    // Test that the getCustomerDetails call returns within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
    assertTrue(waitForAsyncTaskCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
    // Retrieve the customer details response from the listener
    CustomerDetailsResponse customerDetailsResponse = listener.getCustomerDetailsResponse();
    assertNotNull(customerDetailsResponse);
    assertEquals(customerDetailsResponse.getCountry(), "Sweden");
}
Also used : KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) ArrayList(java.util.ArrayList) CustomerDetailsAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.CustomerDetailsAsyncTask) CountDownLatch(java.util.concurrent.CountDownLatch) CustomerDetailsResponse(com.globalcollect.gateway.sdk.client.android.sdk.model.CustomerDetailsResponse) Test(org.junit.Test)

Example 5 with KeyValuePair

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair 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)

Aggregations

KeyValuePair (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair)7 InvalidParameterException (java.security.InvalidParameterException)5 StringFormatter (com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter)3 InputFilter (android.text.InputFilter)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Translator (com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator)2 AccountOnFile (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile)2 PaymentItem (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem)2 ArrayList (java.util.ArrayList)2 Drawable (android.graphics.drawable.Drawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 ArrayAdapter (android.widget.ArrayAdapter)1 DatePicker (android.widget.DatePicker)1 OnDateChangedListener (android.widget.DatePicker.OnDateChangedListener)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1