Java Code Examples for org.chromium.chrome.browser.autofill.PersonalDataManager#setCreditCard()

The following examples show how to use org.chromium.chrome.browser.autofill.PersonalDataManager#setCreditCard() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutofillLocalCardEditor.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Card Payment Type will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardPaymentType(cardNumber,
            true /* emptyIfInvalid */))) {
        mNumberLabel.setError(mContext.getString(
                R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */,
            "" /* serverId */);
    personalDataManager.setCreditCard(card);
    return true;
}
 
Example 2
Source File: AutofillLocalCardEditor.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    PersonalDataManager personalDataManager = PersonalDataManager.getInstance();
    // Issuer network will be empty if credit card number is not valid.
    if (TextUtils.isEmpty(personalDataManager.getBasicCardIssuerNetwork(
                cardNumber, true /* emptyIfInvalid */))) {
        mNumberLabel.setError(mContext.getString(
                R.string.payments_card_number_invalid_validation_message));
        return false;
    }
    CreditCard card = new CreditCard(mGUID, AutofillAndPaymentsPreferences.SETTINGS_ORIGIN,
            true /* isLocal */, false /* isCached */, mNameText.getText().toString().trim(),
            cardNumber, "" /* obfuscatedNumber */,
            String.valueOf(mExpirationMonth.getSelectedItemPosition() + 1),
            (String) mExpirationYear.getSelectedItem(), "" /* basicCardPaymentType */,
            0 /* issuerIconDrawableId */,
            ((AutofillProfile) mBillingAddress.getSelectedItem()).getGUID() /* billing */,
            "" /* serverId */);
    personalDataManager.setCreditCard(card);
    return true;
}
 
Example 3
Source File: CardEditor.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Saves the edited credit card.
 *
 * If this is a server card, then only its billing address identifier is updated.
 *
 * If this is a new local card, then it's saved on this device only if the user has checked the
 * "save this card" checkbox.
 */
private void commitChanges(CreditCard card, boolean isNewCard) {
    card.setBillingAddressId(mBillingAddressField.getValue().toString());

    PersonalDataManager pdm = PersonalDataManager.getInstance();
    if (!card.getIsLocal()) {
        pdm.updateServerCardBillingAddress(card.getServerId(), card.getBillingAddressId());
        return;
    }

    card.setNumber(mNumberField.getValue().toString().replace(" ", "").replace("-", ""));
    card.setName(mNameField.getValue().toString());
    card.setMonth(mMonthField.getValue().toString());
    card.setYear(mYearField.getValue().toString());

    // Calculate the basic card payment type, obfuscated number, and the icon for this card.
    // All of these depend on the card number. The type is sent to the merchant website. The
    // obfuscated number and the icon are displayed in the user interface.
    CreditCard displayableCard = pdm.getCreditCardForNumber(card.getNumber());
    card.setBasicCardPaymentType(displayableCard.getBasicCardPaymentType());
    card.setObfuscatedNumber(displayableCard.getObfuscatedNumber());
    card.setIssuerIconDrawableId(displayableCard.getIssuerIconDrawableId());

    if (!isNewCard) {
        pdm.setCreditCard(card);
        return;
    }

    if (mSaveCardCheckbox != null && mSaveCardCheckbox.isChecked()) {
        card.setGUID(pdm.setCreditCard(card));
    }
}
 
Example 4
Source File: CardEditor.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Saves the edited credit card.
 *
 * If this is a server card, then only its billing address identifier is updated.
 *
 * If this is a new local card, then it's saved on this device only if the user has checked the
 * "save this card" checkbox.
 */
private void commitChanges(CreditCard card, boolean isNewCard) {
    card.setBillingAddressId(mBillingAddressField.getValue().toString());

    PersonalDataManager pdm = PersonalDataManager.getInstance();
    if (!card.getIsLocal()) {
        pdm.updateServerCardBillingAddress(card);
        return;
    }

    card.setNumber(removeSpaceAndBar(mNumberField.getValue()));
    card.setName(mNameField.getValue().toString());
    card.setMonth(mMonthField.getValue().toString());
    card.setYear(mYearField.getValue().toString());

    // Calculate the basic card issuer network, obfuscated number, and the icon for this card.
    // All of these depend on the card number. The issuer network is sent to the merchant
    // website. The obfuscated number and the icon are displayed in the user interface.
    CreditCard displayableCard = pdm.getCreditCardForNumber(card.getNumber());
    card.setBasicCardIssuerNetwork(displayableCard.getBasicCardIssuerNetwork());
    card.setObfuscatedNumber(displayableCard.getObfuscatedNumber());
    card.setIssuerIconDrawableId(displayableCard.getIssuerIconDrawableId());

    if (!isNewCard) {
        pdm.setCreditCard(card);
        return;
    }

    if (mSaveCardCheckbox != null && mSaveCardCheckbox.isChecked()) {
        card.setGUID(pdm.setCreditCard(card));
    }
}