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

The following examples show how to use org.chromium.chrome.browser.payments.ui.SectionInformation. 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 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 #2
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 #3
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 #4
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 #5
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 #6
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void editAddress(final AutofillAddress toEdit) {
    if (toEdit != null) {
        // Log the edit of a shipping address.
        mJourneyLogger.incrementSelectionEdits(
                PaymentRequestJourneyLogger.SECTION_SHIPPING_ADDRESS);
    }
    mAddressEditor.edit(toEdit, new Callback<AutofillAddress>() {
        @Override
        public void onResult(AutofillAddress completeAddress) {
            if (mUI == null) return;

            if (completeAddress == null) {
                mShippingAddressesSection.setSelectedItemIndex(SectionInformation.NO_SELECTION);
                providePaymentInformation();
            } else {
                if (toEdit == null) mShippingAddressesSection.addAndSelectItem(completeAddress);
                mCardEditor.updateBillingAddressIfComplete(completeAddress);
                mClient.onShippingAddressChange(completeAddress.toPaymentAddress());
            }
        }
    });
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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();
            }
        }
    });
}