Search in sources :

Example 1 with CreditCard

use of org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard in project AndroidChromium by JackyAndroid.

the class CardEditor method commitChanges.

/**
     * 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));
    }
}
Also used : PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 2 with CreditCard

use of org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard in project AndroidChromium by JackyAndroid.

the class AutofillLocalCardEditor method saveEntry.

@Override
protected void saveEntry() {
    // Remove all spaces in editText.
    String cardNumber = mNumberText.getText().toString().replaceAll("\\s+", "");
    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 */
    "");
    PersonalDataManager.getInstance().setCreditCard(card);
}
Also used : CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 3 with CreditCard

use of org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard in project AndroidChromium by JackyAndroid.

the class AutofillPreferences method rebuildCreditCardList.

private void rebuildCreditCardList() {
    PreferenceGroup profileCategory = (PreferenceGroup) findPreference(PREF_AUTOFILL_CREDIT_CARDS);
    profileCategory.removeAll();
    for (CreditCard card : PersonalDataManager.getInstance().getCreditCardsForSettings()) {
        // Add an item on the current page...
        Preference pref = new Preference(getActivity());
        pref.setTitle(card.getObfuscatedNumber());
        pref.setSummary(card.getFormattedExpirationDate(getActivity()));
        if (card.getIsLocal()) {
            pref.setFragment(AutofillLocalCardEditor.class.getName());
        } else {
            pref.setFragment(AutofillServerCardEditor.class.getName());
            pref.setWidgetLayoutResource(R.layout.autofill_server_data_label);
        }
        Bundle args = pref.getExtras();
        args.putString(AUTOFILL_GUID, card.getGUID());
        profileCategory.addPreference(pref);
    }
}
Also used : ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) Preference(android.preference.Preference) Bundle(android.os.Bundle) PreferenceGroup(android.preference.PreferenceGroup) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 4 with CreditCard

use of org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard in project AndroidChromium by JackyAndroid.

the class CardEditor method edit.

/**
     * Builds and shows an editor model with the following fields for local cards.
     *
     * [ accepted card types hint images     ]
     * [ card number                         ]
     * [ name on card                        ]
     * [ expiration month ][ expiration year ]
     * [ billing address dropdown            ]
     * [ save this card checkbox             ] <-- Shown only for new cards.
     *
     * Server cards have the following fields instead.
     *
     * [ card's obfuscated number            ]
     * [ billing address dropdown            ]
     */
@Override
public void edit(@Nullable final AutofillPaymentInstrument toEdit, final Callback<AutofillPaymentInstrument> callback) {
    super.edit(toEdit, callback);
    // If |toEdit| is null, we're creating a new credit card.
    final boolean isNewCard = toEdit == null;
    // Ensure that |instrument| and |card| are never null.
    final AutofillPaymentInstrument instrument = isNewCard ? new AutofillPaymentInstrument(mWebContents, new CreditCard(), null) : toEdit;
    final CreditCard card = instrument.getCard();
    // The title of the editor depends on whether we're adding a new card or editing an existing
    // card.
    final EditorModel editor = new EditorModel(mContext.getString(isNewCard ? R.string.payments_create_card : R.string.payments_edit_card));
    if (card.getIsLocal()) {
        Calendar calendar = null;
        try {
            calendar = mCalendar.get();
        } catch (InterruptedException | ExecutionException e) {
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    callback.onResult(null);
                }
            });
            return;
        }
        assert calendar != null;
        // Let user edit any part of the local card.
        addLocalCardInputs(editor, card, calendar);
    } else {
        // Display some information about the server card.
        editor.addField(EditorFieldModel.createLabel(card.getObfuscatedNumber(), card.getName(), card.getFormattedExpirationDate(mContext), card.getIssuerIconDrawableId()));
    }
    // Always show the billing address dropdown.
    addBillingAddressDropdown(editor, card);
    // Allow saving new cards on disk.
    if (isNewCard)
        addSaveCardCheckbox(editor);
    // If the user clicks [Cancel], send a null card back to the caller.
    editor.setCancelCallback(new Runnable() {

        @Override
        public void run() {
            callback.onResult(null);
        }
    });
    // If the user clicks [Done], save changes on disk, mark the card "complete," and send it
    // back to the caller.
    editor.setDoneCallback(new Runnable() {

        @Override
        public void run() {
            commitChanges(card, isNewCard);
            instrument.completeInstrument(card, mProfilesForBillingAddress.get(card.getBillingAddressId()));
            callback.onResult(instrument);
        }
    });
    mEditorView.show(editor);
}
Also used : EditorModel(org.chromium.chrome.browser.payments.ui.EditorModel) Calendar(java.util.Calendar) ExecutionException(java.util.concurrent.ExecutionException) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Example 5 with CreditCard

use of org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard in project AndroidChromium by JackyAndroid.

the class AutofillPaymentApp method getInstruments.

@Override
public void getInstruments(JSONObject unusedDetails, final InstrumentsCallback callback) {
    PersonalDataManager pdm = PersonalDataManager.getInstance();
    List<CreditCard> cards = pdm.getCreditCardsToSuggest();
    final List<PaymentInstrument> instruments = new ArrayList<>(cards.size());
    for (int i = 0; i < cards.size(); i++) {
        CreditCard card = cards.get(i);
        AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId()) ? null : pdm.getProfile(card.getBillingAddressId());
        instruments.add(new AutofillPaymentInstrument(mWebContents, card, billingAddress));
    }
    new Handler().post(new Runnable() {

        @Override
        public void run() {
            callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Handler(android.os.Handler) PersonalDataManager(org.chromium.chrome.browser.autofill.PersonalDataManager) AutofillProfile(org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile) CreditCard(org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)

Aggregations

CreditCard (org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard)5 PersonalDataManager (org.chromium.chrome.browser.autofill.PersonalDataManager)2 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Preference (android.preference.Preference)1 PreferenceGroup (android.preference.PreferenceGroup)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 ExecutionException (java.util.concurrent.ExecutionException)1 AutofillProfile (org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile)1 EditorModel (org.chromium.chrome.browser.payments.ui.EditorModel)1 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)1