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

The following examples show how to use org.chromium.chrome.browser.payments.ui.PaymentOption. 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
/**
 * 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 #2
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the merchant website has processed the payment.
 */
@Override
public void complete(int result) {
    if (mClient == null) return;
    mJourneyLogger.setCompleted();
    if (!PaymentPreferencesUtil.isPaymentCompleteOnce()) {
        PaymentPreferencesUtil.setPaymentCompleteOnce();
    }

    /**
     * Update records of the used payment instrument for sorting payment apps and instruments
     * next time.
     */
    PaymentOption selectedPaymentMethod = mPaymentMethodsSection.getSelectedItem();
    PaymentPreferencesUtil.increasePaymentInstrumentUseCount(
            selectedPaymentMethod.getIdentifier());
    PaymentPreferencesUtil.setPaymentInstrumentLastUseDate(
            selectedPaymentMethod.getIdentifier(), System.currentTimeMillis());

    closeUI(PaymentComplete.FAIL != result);
}
 
Example #3
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 #4
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPayClicked(PaymentOption selectedShippingAddress,
        PaymentOption selectedShippingOption, PaymentOption selectedPaymentMethod) {
    assert selectedPaymentMethod instanceof PaymentInstrument;
    PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
    mPaymentAppRunning = true;

    PaymentOption selectedContact =
            mContactSection != null ? mContactSection.getSelectedItem() : null;
    mPaymentResponseHelper = new PaymentResponseHelper(
            selectedShippingAddress, selectedShippingOption, selectedContact, this);

    instrument.getInstrumentDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
            mMethodData.get(instrument.getInstrumentMethodName()), this);
    recordSuccessFunnelHistograms("PayClicked");
    return !(instrument instanceof AutofillPaymentInstrument);
}
 
Example #5
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 #6
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 #7
Source File: PaymentRequestImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onPayClicked(PaymentOption selectedShippingAddress,
        PaymentOption selectedShippingOption, PaymentOption selectedPaymentMethod) {
    assert selectedPaymentMethod instanceof PaymentInstrument;
    PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
    mPaymentAppRunning = true;
    instrument.getDetails(mMerchantName, mOrigin, mRawTotal, mRawLineItems,
            mMethodData.get(instrument.getMethodName()), this);
}
 
Example #8
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called after retrieving instrument details.
 */
@Override
public void onInstrumentDetailsReady(String methodName, String stringifiedDetails) {
    if (mClient == null || mPaymentResponseHelper == null) return;

    // Record the payment method used to complete the transaction. If the payment method was an
    // Autofill credit card with an identifier, record its use.
    PaymentOption selectedPaymentMethod = mPaymentMethodsSection.getSelectedItem();
    if (selectedPaymentMethod instanceof AutofillPaymentInstrument) {
        if (!selectedPaymentMethod.getIdentifier().isEmpty()) {
            PersonalDataManager.getInstance().recordAndLogCreditCardUse(
                    selectedPaymentMethod.getIdentifier());
        }
        mJourneyLogger.setSelectedPaymentMethod(SelectedPaymentMethod.CREDIT_CARD);
    } else if (methodName.equals(ANDROID_PAY_METHOD_NAME)
            || methodName.equals(PAY_WITH_GOOGLE_METHOD_NAME)) {
        mJourneyLogger.setSelectedPaymentMethod(SelectedPaymentMethod.ANDROID_PAY);
    } else {
        mJourneyLogger.setSelectedPaymentMethod(SelectedPaymentMethod.OTHER_PAYMENT_APP);
    }

    // Showing the payment request UI if we were previously skipping it so the loading
    // spinner shows up until the merchant notifies that payment was completed.
    if (mShouldSkipShowingPaymentRequestUi) mUI.showProcessingMessageAfterUiSkip();

    mJourneyLogger.setEventOccurred(Event.RECEIVED_INSTRUMENT_DETAILS);

    mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifiedDetails);
}
 
Example #9
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called after retrieving instrument details.
 */
@Override
public void onInstrumentDetailsReady(String methodName, String stringifiedDetails) {
    if (mClient == null || mPaymentResponseHelper == null) return;

    // Record the payment method used to complete the transaction. If the payment method was an
    // Autofill credit card with an identifier, record its use.
    PaymentOption selectedPaymentMethod = mPaymentMethodsSection.getSelectedItem();
    if (selectedPaymentMethod instanceof AutofillPaymentInstrument) {
        if (!selectedPaymentMethod.getIdentifier().isEmpty()) {
            PersonalDataManager.getInstance().recordAndLogCreditCardUse(
                    selectedPaymentMethod.getIdentifier());
        }
        PaymentRequestMetrics.recordSelectedPaymentMethodHistogram(
                PaymentRequestMetrics.SELECTED_METHOD_CREDIT_CARD);
    } else if (methodName.equals(ANDROID_PAY_METHOD_NAME)) {
        PaymentRequestMetrics.recordSelectedPaymentMethodHistogram(
                PaymentRequestMetrics.SELECTED_METHOD_ANDROID_PAY);
    } else {
        PaymentRequestMetrics.recordSelectedPaymentMethodHistogram(
                PaymentRequestMetrics.SELECTED_METHOD_OTHER_PAYMENT_APP);
    }

    recordSuccessFunnelHistograms("ReceivedInstrumentDetails");

    mPaymentResponseHelper.onInstrumentDetailsReceived(methodName, stringifiedDetails);
}
 
Example #10
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPayClicked(PaymentOption selectedShippingAddress,
        PaymentOption selectedShippingOption, PaymentOption selectedPaymentMethod) {
    assert selectedPaymentMethod instanceof PaymentInstrument;
    PaymentInstrument instrument = (PaymentInstrument) selectedPaymentMethod;
    mPaymentAppRunning = true;

    PaymentOption selectedContact = mContactSection != null ? mContactSection.getSelectedItem()
            : null;
    mPaymentResponseHelper = new PaymentResponseHelper(
            selectedShippingAddress, selectedShippingOption, selectedContact, this);

    // Create maps that are subsets of mMethodData and mModifiers, that contain
    // the payment methods supported by the selected payment instrument. If the
    // intersection of method data contains more than one payment method, the
    // payment app is at liberty to choose (or have the user choose) one of the
    // methods.
    Map<String, PaymentMethodData> methodData = new HashMap<>();
    Map<String, PaymentDetailsModifier> modifiers = new HashMap<>();
    for (String instrumentMethodName : instrument.getInstrumentMethodNames()) {
        if (mMethodData.containsKey(instrumentMethodName)) {
            methodData.put(instrumentMethodName, mMethodData.get(instrumentMethodName));
        }
        if (mModifiers != null && mModifiers.containsKey(instrumentMethodName)) {
            modifiers.put(instrumentMethodName, mModifiers.get(instrumentMethodName));
        }
    }

    instrument.invokePaymentApp(mId, mMerchantName, mTopLevelOrigin, mPaymentRequestOrigin,
            mCertificateChain, Collections.unmodifiableMap(methodData), mRawTotal,
            mRawLineItems, Collections.unmodifiableMap(modifiers), this);

    mJourneyLogger.setEventOccurred(Event.PAY_CLICKED);
    return !(instrument instanceof AutofillPaymentInstrument);
}
 
Example #11
Source File: PaymentResponseHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a helper to contruct and fill a PaymentResponse.
 *
 * @param selectedShippingAddress The shipping address picked by the user.
 * @param selectedShippingOption  The shipping option picked by the user.
 * @param selectedContact         The contact info picked by the user.
 * @param delegate                The object that will recieve the completed PaymentResponse.
 */
public PaymentResponseHelper(PaymentOption selectedShippingAddress,
        PaymentOption selectedShippingOption, PaymentOption selectedContact,
        PaymentResponseRequesterDelegate delegate) {
    mPaymentResponse = new PaymentResponse();

    mDelegate = delegate;

    // Set up the contact section of the response.
    if (selectedContact != null) {
        // Contacts are created in PaymentRequestImpl.init(). These should all be instances of
        // AutofillContact.
        assert selectedContact instanceof AutofillContact;
        mPaymentResponse.payerName = ((AutofillContact) selectedContact).getPayerName();
        mPaymentResponse.payerPhone = ((AutofillContact) selectedContact).getPayerPhone();
        mPaymentResponse.payerEmail = ((AutofillContact) selectedContact).getPayerEmail();

        // Normalize the phone number only if it's not null since this calls native code.
        if (mPaymentResponse.payerPhone != null) {
            mPaymentResponse.payerPhone =
                    PhoneNumberUtil.formatForResponse(mPaymentResponse.payerPhone);
        }
    }

    // Set up the shipping section of the response.
    if (selectedShippingOption != null && selectedShippingOption.getIdentifier() != null) {
        mPaymentResponse.shippingOption = selectedShippingOption.getIdentifier();
    }

    // Set up the shipping address section of the response.
    if (selectedShippingAddress != null) {
        // Shipping addresses are created in PaymentRequestImpl.init(). These should all be
        // instances of AutofillAddress.
        assert selectedShippingAddress instanceof AutofillAddress;
        mSelectedShippingAddress = (AutofillAddress) selectedShippingAddress;

        // Addresses to be sent to the merchant should always be complete.
        assert mSelectedShippingAddress.isComplete();

        // Record the use of the profile.
        PersonalDataManager.getInstance().recordAndLogProfileUse(
                mSelectedShippingAddress.getProfile().getGUID());

        mPaymentResponse.shippingAddress = mSelectedShippingAddress.toPaymentAddress();

        // The shipping address needs to be normalized before sending the response to the
        // merchant.
        mIsWaitingForShippingNormalization = true;
        PersonalDataManager.getInstance().normalizeAddress(
                mSelectedShippingAddress.getProfile(),
                AutofillAddress.getCountryCode(mSelectedShippingAddress.getProfile()), this);
    }
}
 
Example #12
Source File: AutofillAddress.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the autofill address.
 *
 * @param profile The autofill profile containing the address information.
 */
public AutofillAddress(AutofillProfile profile, boolean isComplete) {
    super(profile.getGUID(), profile.getFullName(), profile.getLabel(), PaymentOption.NO_ICON);
    mProfile = profile;
    mIsComplete = isComplete;
}
 
Example #13
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 #14
Source File: PaymentResponseHelper.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a helper to contruct and fill a PaymentResponse.
 *
 * @param selectedShippingAddress The shipping address picked by the user.
 * @param selectedShippingOption  The shipping option picked by the user.
 * @param selectedContact         The contact info picked by the user.
 * @param delegate                The object that will recieve the completed PaymentResponse.
 */
public PaymentResponseHelper(PaymentOption selectedShippingAddress,
        PaymentOption selectedShippingOption, PaymentOption selectedContact,
        PaymentResponseRequesterDelegate delegate) {
    mPaymentResponse = new PaymentResponse();

    mDelegate = delegate;

    // Set up the contact section of the response.
    if (selectedContact != null) {
        // Contacts are created in PaymentRequestImpl.init(). These should all be instances of
        // AutofillContact.
        assert selectedContact instanceof AutofillContact;
        mPaymentResponse.payerName = ((AutofillContact) selectedContact).getPayerName();
        mPaymentResponse.payerPhone = ((AutofillContact) selectedContact).getPayerPhone();
        mPaymentResponse.payerEmail = ((AutofillContact) selectedContact).getPayerEmail();
    }

    // Set up the shipping section of the response.
    if (selectedShippingOption != null && selectedShippingOption.getIdentifier() != null) {
        mPaymentResponse.shippingOption = selectedShippingOption.getIdentifier();
    }

    // Set up the shipping address section of the response.
    if (selectedShippingAddress != null) {
        // Shipping addresses are created in PaymentRequestImpl.init(). These should all be
        // instances of AutofillAddress.
        assert selectedShippingAddress instanceof AutofillAddress;
        mSelectedShippingAddress = (AutofillAddress) selectedShippingAddress;

        // Addresses to be sent to the merchant should always be complete.
        assert mSelectedShippingAddress.isComplete();

        // Record the use of the profile.
        PersonalDataManager.getInstance().recordAndLogProfileUse(
                mSelectedShippingAddress.getProfile().getGUID());

        mPaymentResponse.shippingAddress = mSelectedShippingAddress.toPaymentAddress();

        // The shipping address needs to be normalized before sending the response to the
        // merchant.
        mIsWaitingForShippingNormalization = true;
        PersonalDataManager.getInstance().normalizeAddress(
                mSelectedShippingAddress.getProfile().getGUID(),
                AutofillAddress.getCountryCode(mSelectedShippingAddress.getProfile()), this);
    }
}
 
Example #15
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;
}
 
Example #16
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 #17
Source File: AutofillContact.java    From delion with Apache License 2.0 3 votes vote down vote up
/**
 * Builds contact details.
 *
 * @param profile    The autofill profile where this contact data lives.
 * @param phone      The phone number. If not empty, this will be the primary label.
 * @param email      The email address. If phone is empty, this will be the primary label.
 * @param isComplete Whether the data in this contact can be sent to the merchant as-is. If
 *                   false, user needs to add more information here.
 */
public AutofillContact(AutofillProfile profile, @Nullable String phone, @Nullable String email,
        boolean isComplete) {
    super(profile.getGUID(), null, null, PaymentOption.NO_ICON);
    mProfile = profile;
    mIsComplete = isComplete;
    setPhoneEmail(phone, email);
}