org.chromium.chrome.browser.payments.ui.PaymentRequestUI Java Examples

The following examples show how to use org.chromium.chrome.browser.payments.ui.PaymentRequestUI. 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: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void editContact(final AutofillContact toEdit) {
    if (toEdit != null) {
        // Log the edit of a contact info.
        mJourneyLogger.incrementSelectionEdits(
                PaymentRequestJourneyLogger.SECTION_CONTACT_INFO);
    }
    mContactEditor.edit(toEdit, new Callback<AutofillContact>() {
        @Override
        public void onResult(AutofillContact completeContact) {
            if (mUI == null) return;

            if (completeContact == null) {
                mContactSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
            } else if (toEdit == null) {
                mContactSection.addAndSelectItem(completeContact);
            }

            mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mContactSection);
        }
    });
}
 
Example #2
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onFocusChanged(@PaymentRequestUI.DataType int dataType, boolean willFocus) {
    assert dataType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES;

    if (mShippingAddressesSection.getSelectedItem() == null) return;

    assert mShippingAddressesSection.getSelectedItem() instanceof AutofillAddress;
    AutofillAddress selectedAddress = (AutofillAddress) mShippingAddressesSection
            .getSelectedItem();

    // The label should only include the country if the view is focused.
    if (willFocus) {
        selectedAddress.setShippingAddressLabelWithCountry();
    } else {
        selectedAddress.setShippingAddressLabelWithoutCountry();
    }

    mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, mShippingAddressesSection);
}
 
Example #3
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
@PaymentRequestUI.SelectionResult
public int onSectionAddOption(
        @PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        editAddress(null);
        mPaymentInformationCallback = callback;
        // Log the add of shipping address.
        mJourneyLogger.incrementSelectionAdds(Section.SHIPPING_ADDRESS);
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        editContact(null);
        // Log the add of contact info.
        mJourneyLogger.incrementSelectionAdds(Section.CONTACT_INFO);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        editCard(null);
        // Log the add of credit card.
        mJourneyLogger.incrementSelectionAdds(Section.CREDIT_CARDS);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    }

    return PaymentRequestUI.SELECTION_RESULT_NONE;
}
 
Example #4
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
@PaymentRequestUI.SelectionResult
public int onSectionEditOption(@PaymentRequestUI.DataType int optionType, PaymentOption option,
        Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        assert option instanceof AutofillAddress;
        editAddress((AutofillAddress) option);
        mPaymentInformationCallback = callback;
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    }

    if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        assert option instanceof AutofillContact;
        editContact((AutofillContact) option);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    }

    if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        assert option instanceof AutofillPaymentInstrument;
        editCard((AutofillPaymentInstrument) option);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    }

    assert false;
    return PaymentRequestUI.SELECTION_RESULT_NONE;
}
 
Example #5
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void getSectionInformation(@PaymentRequestUI.DataType final int optionType,
        final Callback<SectionInformation> callback) {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
                callback.onResult(mShippingAddressesSection);
            } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
                callback.onResult(mUiShippingOptions);
            } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
                callback.onResult(mContactSection);
            } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
                assert mPaymentMethodsSection != null;
                callback.onResult(mPaymentMethodsSection);
            }
        }
    });
}
 
Example #6
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a list of shipping options and returns their parsed representation.
 *
 * @param options   The raw shipping options to parse. Can be null.
 * @return The UI representation of the shipping options.
 */
private SectionInformation getShippingOptions(@Nullable PaymentShippingOption[] options) {
    // Shipping options are optional.
    if (options == null || options.length == 0) {
        return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS);
    }

    List<PaymentOption> result = new ArrayList<>();
    int selectedItemIndex = SectionInformation.NO_SELECTION;
    for (int i = 0; i < options.length; i++) {
        PaymentShippingOption option = options[i];
        CurrencyFormatter formatter = getOrCreateCurrencyFormatter(option.amount);
        String currencyPrefix = isMixedOrChangedCurrency()
                ? formatter.getFormattedCurrencyCode() + "\u0020"
                : "";
        result.add(new PaymentOption(option.id, option.label,
                currencyPrefix + formatter.format(option.amount.value), null));
        if (option.selected) selectedItemIndex = i;
    }

    return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, selectedItemIndex,
            Collections.unmodifiableList(result));
}
 
Example #7
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void editCard(final AutofillPaymentInstrument toEdit) {
    if (toEdit != null) {
        // Log the edit of a credit card.
        mJourneyLogger.incrementSelectionEdits(
                PaymentRequestJourneyLogger.SECTION_CREDIT_CARDS);
    }
    mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() {
        @Override
        public void onResult(AutofillPaymentInstrument completeCard) {
            if (mUI == null) return;

            if (completeCard == null) {
                mPaymentMethodsSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
            } else if (toEdit == null) {
                mPaymentMethodsSection.addAndSelectItem(completeCard);
            }

            mUI.updateSection(PaymentRequestUI.TYPE_PAYMENT_METHODS, mPaymentMethodsSection);
        }
    });
}
 
Example #8
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
@PaymentRequestUI.SelectionResult
public int onSectionAddOption(
        @PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        editAddress(null);
        mPaymentInformationCallback = callback;
        // Log the add of shipping address.
        mJourneyLogger.incrementSelectionAdds(
                PaymentRequestJourneyLogger.SECTION_SHIPPING_ADDRESS);
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        editContact(null);
        // Log the add of contact info.
        mJourneyLogger.incrementSelectionAdds(PaymentRequestJourneyLogger.SECTION_CONTACT_INFO);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        editCard(null);
        // Log the add of credit card.
        mJourneyLogger.incrementSelectionAdds(PaymentRequestJourneyLogger.SECTION_CREDIT_CARDS);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    }

    return PaymentRequestUI.SELECTION_RESULT_NONE;
}
 
Example #9
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
@PaymentRequestUI.SelectionResult
public int onSectionEditOption(@PaymentRequestUI.DataType int optionType, PaymentOption option,
        Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        assert option instanceof AutofillAddress;
        editAddress((AutofillAddress) option);
        mPaymentInformationCallback = callback;
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    }

    if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        assert option instanceof AutofillContact;
        editContact((AutofillContact) option);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    }

    if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        assert option instanceof AutofillPaymentInstrument;
        editCard((AutofillPaymentInstrument) option);
        return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
    }

    assert false;
    return PaymentRequestUI.SELECTION_RESULT_NONE;
}
 
Example #10
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void getSectionInformation(@PaymentRequestUI.DataType final int optionType,
        final Callback<SectionInformation> callback) {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
                callback.onResult(mShippingAddressesSection);
            } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
                callback.onResult(mUiShippingOptions);
            } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
                callback.onResult(mContactSection);
            } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
                assert mPaymentMethodsSection != null;
                callback.onResult(mPaymentMethodsSection);
            }
        }
    });
}
 
Example #11
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a list of shipping options and returns their parsed representation.
 *
 * @param options The raw shipping options to parse and validate.
 * @param totalCurrency The currency code for the total amount of payment.
 * @param formatter A formatter and validator for the currency amount value.
 * @return The UI representation of the shipping options.
 */
private static SectionInformation getShippingOptions(PaymentShippingOption[] options,
        String totalCurrency, CurrencyStringFormatter formatter) {
    // Shipping options are optional.
    if (options == null || options.length == 0) {
        return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS);
    }

    List<PaymentOption> result = new ArrayList<>();
    int selectedItemIndex = SectionInformation.NO_SELECTION;
    for (int i = 0; i < options.length; i++) {
        PaymentShippingOption option = options[i];
        result.add(new PaymentOption(option.id, option.label,
                formatter.format(option.amount.value), null));
        if (option.selected) selectedItemIndex = i;
    }

    return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, selectedItemIndex,
            result);
}
 
Example #12
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Called after retrieving the list of payment instruments in an app.
 */
@Override
public void onInstrumentsReady(PaymentApp app, List<PaymentInstrument> instruments) {
    mPendingApps.remove(app);

    if (instruments != null) {
        for (int i = 0; i < instruments.size(); i++) {
            PaymentInstrument instrument = instruments.get(i);
            if (mMethodData.containsKey(instrument.getMethodName())) {
                mPendingInstruments.add(instrument);
            } else {
                instrument.dismiss();
            }
        }
    }

    if (mPendingApps.isEmpty()) {
        mPaymentMethodsSection = new SectionInformation(
                PaymentRequestUI.TYPE_PAYMENT_METHODS, 0, mPendingInstruments);
        mPendingInstruments.clear();

        if (mPaymentInformationCallback != null) providePaymentInformation();
    }
}
 
Example #13
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onSectionAddOption(
        @PaymentRequestUI.DataType int optionType, Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        editAddress(null);

        if (mMerchantNeedsShippingAddress) {
            mPaymentInformationCallback = callback;
            return true;
        }
    } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        editContact(null);
    } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        PreferencesLauncher.launchSettingsPage(
                mContext, AutofillLocalCardEditor.class.getName());
    }

    return false;
}
 
Example #14
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 6 votes vote down vote up
private void editAddress(final AutofillAddress toEdit) {
    mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() {
        @Override
        public void onResult(AutofillAddress completeAddress) {
            if (completeAddress == null) {
                mShippingAddressesSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
            } else if (toEdit == null) {
                mShippingAddressesSection.addAndSelectItem(completeAddress);
            }

            if (mMerchantNeedsShippingAddress) {
                if (completeAddress == null) {
                    providePaymentInformation();
                } else {
                    mClient.onShippingAddressChange(completeAddress.toPaymentAddress());
                }
                return;
            }

            mUI.updateSection(
                    PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, mShippingAddressesSection);
        }
    });
}
 
Example #15
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void getSectionInformation(@PaymentRequestUI.DataType final int optionType,
        final Callback<SectionInformation> callback) {
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
                callback.onResult(mShippingAddressesSection);
            } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
                callback.onResult(mUiShippingOptions);
            } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
                callback.onResult(mContactSection);
            } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
                assert mPaymentMethodsSection != null;
                callback.onResult(mPaymentMethodsSection);
            }
        }
    });
}
 
Example #16
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
private void editContact(final AutofillContact toEdit) {
    mContactEditor.edit(toEdit, new Callback<AutofillContact>() {
        @Override
        public void onResult(AutofillContact completeContact) {
            if (completeContact == null) {
                mContactSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
            } else if (toEdit == null) {
                mContactSection.addAndSelectItem(completeContact);
            }

            mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mContactSection);
        }
    });
}
 
Example #17
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void editCard(final AutofillPaymentInstrument toEdit) {
    if (toEdit != null) {
        // Log the edit of a credit card.
        mJourneyLogger.incrementSelectionEdits(Section.CREDIT_CARDS);
    }
    mCardEditor.edit(toEdit, new Callback<AutofillPaymentInstrument>() {
        @Override
        public void onResult(AutofillPaymentInstrument editedCard) {
            if (mUI == null) return;

            if (editedCard != null) {
                // A partial or complete card came back from the editor (could have been from
                // adding/editing or cancelling out of the edit flow).
                if (!editedCard.isComplete()) {
                    // If the card is not complete, unselect it (editor can return incomplete
                    // information when cancelled).
                    mPaymentMethodsSection.setSelectedItemIndex(
                            SectionInformation.NO_SELECTION);
                } else if (toEdit == null) {
                    // Card is complete and we were in the "Add flow": add an item to the list.
                    mPaymentMethodsSection.addAndSelectItem(editedCard);
                }
                // If card is complete and (toEdit != null), no action needed: the card was
                // already selected in the UI.
            }
            // If |editedCard| is null, the user has cancelled out of the "Add flow". No action
            // to take (if another card was selected prior to the add flow, it will stay
            // selected).

            updateInstrumentModifiedTotals();
            mUI.updateSection(PaymentRequestUI.TYPE_PAYMENT_METHODS, mPaymentMethodsSection);
        }
    });
}
 
Example #18
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void editContact(final AutofillContact toEdit) {
    if (toEdit != null) {
        // Log the edit of a contact info.
        mJourneyLogger.incrementSelectionEdits(Section.CONTACT_INFO);
    }
    mContactEditor.edit(toEdit, new Callback<AutofillContact>() {
        @Override
        public void onResult(AutofillContact editedContact) {
            if (mUI == null) return;

            if (editedContact != null) {
                // A partial or complete contact came back from the editor (could have been from
                // adding/editing or cancelling out of the edit flow).
                if (!editedContact.isComplete()) {
                    // If the contact is not complete according to the requirements of the flow,
                    // unselect it (editor can return incomplete information when cancelled).
                    mContactSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
                } else if (toEdit == null) {
                    // Contact is complete and we were in the "Add flow": add an item to the
                    // list.
                    mContactSection.addAndSelectItem(editedContact);
                }
                // If contact is complete and (toEdit != null), no action needed: the contact
                // was already selected in the UI.
            }
            // If |editedContact| is null, the user has cancelled out of the "Add flow". No
            // action to take (if a contact was selected in the UI, it will stay selected).

            mUI.updateSection(PaymentRequestUI.TYPE_CONTACT_DETAILS, mContactSection);
        }
    });
}
 
Example #19
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called by merchant to update the shipping options and line items after the user has selected
 * their shipping address or shipping option.
 */
@Override
public void updateWith(PaymentDetails details) {
    if (mClient == null) return;

    if (mUI == null) {
        mJourneyLogger.setAborted(AbortReason.INVALID_DATA_FROM_RENDERER);
        disconnectFromClientWithDebugMessage(
                "PaymentRequestUpdateEvent.updateWith() called without PaymentRequest.show()");
        return;
    }

    if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;

    if (mUiShippingOptions.isEmpty() && mShippingAddressesSection.getSelectedItem() != null) {
        mShippingAddressesSection.getSelectedItem().setInvalid();
        mShippingAddressesSection.setSelectedItemIndex(SectionInformation.INVALID_SELECTION);
        mShippingAddressesSection.setErrorMessage(details.error);
    }

    if (mPaymentInformationCallback != null) {
        providePaymentInformation();
    } else {
        mUI.updateOrderSummarySection(mUiShoppingCart);
        mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mUiShippingOptions);
    }
}
 
Example #20
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called by merchant to update the shipping options and line items after the user has selected
 * their shipping address or shipping option.
 */
@Override
public void updateWith(PaymentDetails details) {
    if (mClient == null) return;

    if (mUI == null) {
        disconnectFromClientWithDebugMessage(
                "PaymentRequestUpdateEvent.updateWith() called without PaymentRequest.show()");
        return;
    }

    if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;

    // Empty shipping options means the merchant cannot ship to the user's selected shipping
    // address.
    if (mUiShippingOptions.isEmpty() && !mMerchantNeedsShippingAddress) {
        disconnectFromClientWithDebugMessage("Merchant indicates inability to ship although "
                + "originally indicated that can ship anywhere");
        return;
    }

    if (mUiShippingOptions.isEmpty() && mShippingAddressesSection.getSelectedItem() != null) {
        mShippingAddressesSection.getSelectedItem().setInvalid();
        mShippingAddressesSection.setSelectedItemIndex(SectionInformation.INVALID_SELECTION);
    }

    if (mPaymentInformationCallback != null) {
        providePaymentInformation();
    } else {
        mUI.updateOrderSummarySection(mUiShoppingCart);
        mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mUiShippingOptions);
    }
}
 
Example #21
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called by merchant to update the shipping options and line items after the user has selected
 * their shipping address or shipping option.
 */
@Override
public void updateWith(PaymentDetails details) {
    if (mClient == null) return;

    if (mUI == null) {
        disconnectFromClientWithDebugMessage(
                "PaymentRequestUpdateEvent.updateWith() called without PaymentRequest.show()");
        recordAbortReasonHistogram(
                PaymentRequestMetrics.ABORT_REASON_INVALID_DATA_FROM_RENDERER);
        return;
    }

    if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return;

    if (mUiShippingOptions.isEmpty() && mShippingAddressesSection.getSelectedItem() != null) {
        mShippingAddressesSection.getSelectedItem().setInvalid();
        mShippingAddressesSection.setSelectedItemIndex(SectionInformation.INVALID_SELECTION);
    }

    if (mPaymentInformationCallback != null) {
        providePaymentInformation();
    } else {
        mUI.updateOrderSummarySection(mUiShoppingCart);
        mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mUiShippingOptions);
    }
}
 
Example #22
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
@PaymentRequestUI.SelectionResult
public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType,
        PaymentOption option, Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        assert option instanceof AutofillAddress;
        // Log the change of shipping address.
        mJourneyLogger.incrementSelectionChanges(Section.SHIPPING_ADDRESS);
        AutofillAddress address = (AutofillAddress) option;
        if (address.isComplete()) {
            mShippingAddressesSection.setSelectedItem(option);
            startShippingAddressChangeNormalization(address);
        } else {
            editAddress(address);
        }
        mPaymentInformationCallback = callback;
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
        // This may update the line items.
        mUiShippingOptions.setSelectedItem(option);
        mClient.onShippingOptionChange(option.getIdentifier());
        mPaymentInformationCallback = callback;
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        assert option instanceof AutofillContact;
        // Log the change of contact info.
        mJourneyLogger.incrementSelectionChanges(Section.CONTACT_INFO);
        AutofillContact contact = (AutofillContact) option;

        if (contact.isComplete()) {
            mContactSection.setSelectedItem(option);
        } else {
            editContact(contact);
            return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
        }
    } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        assert option instanceof PaymentInstrument;
        if (option instanceof AutofillPaymentInstrument) {
            // Log the change of credit card.
            mJourneyLogger.incrementSelectionChanges(Section.CREDIT_CARDS);
            AutofillPaymentInstrument card = (AutofillPaymentInstrument) option;

            if (!card.isComplete()) {
                editCard(card);
                return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
            }
        }

        updateOrderSummary((PaymentInstrument) option);
        mPaymentMethodsSection.setSelectedItem(option);
    }

    return PaymentRequestUI.SELECTION_RESULT_NONE;
}
 
Example #23
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void createShippingSection(
        Context context, List<AutofillProfile> unmodifiableProfiles) {
    List<AutofillAddress> addresses = new ArrayList<>();

    for (int i = 0; i < unmodifiableProfiles.size(); i++) {
        AutofillProfile profile = unmodifiableProfiles.get(i);
        mAddressEditor.addPhoneNumberIfValid(profile.getPhoneNumber());

        // Only suggest addresses that have a street address.
        if (!TextUtils.isEmpty(profile.getStreetAddress())) {
            addresses.add(new AutofillAddress(context, profile));
        }
    }

    // Suggest complete addresses first.
    Collections.sort(addresses, COMPLETENESS_COMPARATOR);

    // Limit the number of suggestions.
    addresses = addresses.subList(0, Math.min(addresses.size(), SUGGESTIONS_LIMIT));

    // Load the validation rules for each unique region code.
    Set<String> uniqueCountryCodes = new HashSet<>();
    for (int i = 0; i < addresses.size(); ++i) {
        String countryCode = AutofillAddress.getCountryCode(addresses.get(i).getProfile());
        if (!uniqueCountryCodes.contains(countryCode)) {
            uniqueCountryCodes.add(countryCode);
            PersonalDataManager.getInstance().loadRulesForAddressNormalization(countryCode);
        }
    }

    // Log the number of suggested shipping addresses.
    mJourneyLogger.setNumberOfSuggestionsShown(Section.SHIPPING_ADDRESS, addresses.size());

    // Automatically select the first address if one is complete and if the merchant does
    // not require a shipping address to calculate shipping costs.
    int firstCompleteAddressIndex = SectionInformation.NO_SELECTION;
    if (mUiShippingOptions.getSelectedItem() != null && !addresses.isEmpty()
            && addresses.get(0).isComplete()) {
        firstCompleteAddressIndex = 0;

        // The initial label for the selected shipping address should not include the
        // country.
        addresses.get(firstCompleteAddressIndex).setShippingAddressLabelWithoutCountry();
    }

    mShippingAddressesSection = new SectionInformation(
            PaymentRequestUI.TYPE_SHIPPING_ADDRESSES, firstCompleteAddressIndex, addresses);
}
 
Example #24
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onSectionOptionSelected(@PaymentRequestUI.DataType int optionType,
        PaymentOption option, Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        assert option instanceof AutofillAddress;
        AutofillAddress address = (AutofillAddress) option;

        if (address.isComplete()) {
            mShippingAddressesSection.setSelectedItem(option);

            // This updates the line items and the shipping options asynchronously.
            if (mMerchantNeedsShippingAddress) {
                mClient.onShippingAddressChange(address.toPaymentAddress());
            }
        } else {
            editAddress(address);
        }

        if (mMerchantNeedsShippingAddress) {
            mPaymentInformationCallback = callback;
            return true;
        }
    } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
        // This may update the line items.
        mUiShippingOptions.setSelectedItem(option);
        mClient.onShippingOptionChange(option.getIdentifier());
    } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        assert option instanceof AutofillContact;
        AutofillContact contact = (AutofillContact) option;

        if (contact.isComplete()) {
            mContactSection.setSelectedItem(option);
        } else {
            editContact(contact);
        }
    } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        assert option instanceof PaymentInstrument;
        mPaymentMethodsSection.setSelectedItem(option);
    }

    return false;
}
 
Example #25
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void editAddress(final AutofillAddress toEdit) {
    if (toEdit != null) {
        // Log the edit of a shipping address.
        mJourneyLogger.incrementSelectionEdits(Section.SHIPPING_ADDRESS);
    }
    mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() {
        @Override
        public void onResult(AutofillAddress editedAddress) {
            if (mUI == null) return;

            if (editedAddress != null) {
                // Sets or updates the shipping address label.
                editedAddress.setShippingAddressLabelWithCountry();

                mCardEditor.updateBillingAddressIfComplete(editedAddress);

                // A partial or complete address came back from the editor (could have been from
                // adding/editing or cancelling out of the edit flow).
                if (!editedAddress.isComplete()) {
                    // If the address is not complete, unselect it (editor can return incomplete
                    // information when cancelled).
                    mShippingAddressesSection.setSelectedItemIndex(
                            SectionInformation.NO_SELECTION);
                    providePaymentInformation();
                } else {
                    if (toEdit == null) {
                        // Address is complete and user was in the "Add flow": add an item to
                        // the list.
                        mShippingAddressesSection.addAndSelectItem(editedAddress);
                    }

                    if (mContactSection != null) {
                        // Update |mContactSection| with the new/edited address, which will
                        // update an existing item or add a new one to the end of the list.
                        mContactSection.addOrUpdateWithAutofillAddress(editedAddress);
                        mUI.updateSection(
                                PaymentRequestUI.TYPE_CONTACT_DETAILS, mContactSection);
                    }

                    startShippingAddressChangeNormalization(editedAddress);
                }
            } else {
                providePaymentInformation();
            }
        }
    });
}
 
Example #26
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
@PaymentRequestUI.SelectionResult
public int onSectionOptionSelected(@PaymentRequestUI.DataType int optionType,
        PaymentOption option, Callback<PaymentInformation> callback) {
    if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) {
        assert option instanceof AutofillAddress;
        // Log the change of shipping address.
        mJourneyLogger.incrementSelectionChanges(
                PaymentRequestJourneyLogger.SECTION_SHIPPING_ADDRESS);
        AutofillAddress address = (AutofillAddress) option;
        if (address.isComplete()) {
            mShippingAddressesSection.setSelectedItem(option);
            // This updates the line items and the shipping options asynchronously.
            mClient.onShippingAddressChange(address.toPaymentAddress());
        } else {
            editAddress(address);
        }
        mPaymentInformationCallback = callback;
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) {
        // This may update the line items.
        mUiShippingOptions.setSelectedItem(option);
        mClient.onShippingOptionChange(option.getIdentifier());
        mPaymentInformationCallback = callback;
        return PaymentRequestUI.SELECTION_RESULT_ASYNCHRONOUS_VALIDATION;
    } else if (optionType == PaymentRequestUI.TYPE_CONTACT_DETAILS) {
        assert option instanceof AutofillContact;
        // Log the change of contact info.
        mJourneyLogger.incrementSelectionChanges(
                PaymentRequestJourneyLogger.SECTION_CONTACT_INFO);
        AutofillContact contact = (AutofillContact) option;

        if (contact.isComplete()) {
            mContactSection.setSelectedItem(option);
        } else {
            editContact(contact);
            return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
        }
    } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) {
        assert option instanceof PaymentInstrument;
        if (option instanceof AutofillPaymentInstrument) {
            // Log the change of credit card.
            mJourneyLogger.incrementSelectionChanges(
                    PaymentRequestJourneyLogger.SECTION_CREDIT_CARDS);
            AutofillPaymentInstrument card = (AutofillPaymentInstrument) option;

            if (!card.isComplete()) {
                editCard(card);
                return PaymentRequestUI.SELECTION_RESULT_EDITOR_LAUNCH;
            }
        }

        mPaymentMethodsSection.setSelectedItem(option);
    }

    return PaymentRequestUI.SELECTION_RESULT_NONE;
}