use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.
the class AddressEditor method commitChanges.
/**
* Saves the edited profile on disk.
*/
private void commitChanges(AutofillProfile profile) {
// Country code and phone number are always required and are always collected from the
// editor model.
profile.setCountryCode(mCountryField.getValue().toString());
profile.setPhoneNumber(mPhoneField.getValue().toString());
// Autofill profile bridge normalizes the language code for the autofill profile.
profile.setLanguageCode(mAutofillProfileBridge.getCurrentBestLanguageCode());
// Collect data from all visible fields and store it in the autofill profile.
Set<Integer> visibleFields = new HashSet<>();
for (int i = 0; i < mAddressUiComponents.size(); i++) {
AddressUiComponent component = mAddressUiComponents.get(i);
visibleFields.add(component.id);
if (component.id != AddressField.COUNTRY) {
setProfileField(profile, component.id, mAddressFields.get(component.id).getValue());
}
}
// AutofillAddress.toPaymentAddress() will send them to the renderer as empty strings.
for (Map.Entry<Integer, EditorFieldModel> entry : mAddressFields.entrySet()) {
if (!visibleFields.contains(entry.getKey())) {
setProfileField(profile, entry.getKey(), "");
}
}
// Calculate the label for this profile. The label's format depends on the country and
// language code for the profile.
PersonalDataManager pdm = PersonalDataManager.getInstance();
// TODO(crbug.com/666048): New billing address label is wrong.
profile.setLabel(pdm.getAddressLabelForPaymentRequest(profile));
// Save the edited autofill profile locally.
profile.setGUID(pdm.setProfileToLocal(profile));
profile.setIsLocal(true);
}
use of org.chromium.chrome.browser.autofill.PersonalDataManager 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));
}
}
use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.
the class AutofillLocalCardEditor method saveEntry.
@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))) {
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 */
"");
personalDataManager.setCreditCard(card);
return true;
}
use of org.chromium.chrome.browser.autofill.PersonalDataManager 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);
}
});
}
use of org.chromium.chrome.browser.autofill.PersonalDataManager in project AndroidChromium by JackyAndroid.
the class AutofillPaymentApp method getInstruments.
@Override
public void getInstruments(Map<String, PaymentMethodData> unusedMethodData, 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());
if (billingAddress != null && AutofillAddress.checkAddressCompletionStatus(billingAddress) != AutofillAddress.COMPLETE) {
billingAddress = null;
}
instruments.add(new AutofillPaymentInstrument(mContext, mWebContents, card, billingAddress));
}
new Handler().post(new Runnable() {
@Override
public void run() {
callback.onInstrumentsReady(AutofillPaymentApp.this, instruments);
}
});
}
Aggregations