Search in sources :

Example 1 with PaymentResponse

use of org.chromium.payments.mojom.PaymentResponse in project AndroidChromium by JackyAndroid.

the class PaymentRequestImpl method onInstrumentDetailsReady.

/**
     * Called after retrieving instrument details.
     */
@Override
public void onInstrumentDetailsReady(String methodName, String stringifiedDetails) {
    if (mClient == null)
        return;
    PaymentResponse response = new PaymentResponse();
    response.methodName = methodName;
    response.stringifiedDetails = stringifiedDetails;
    if (mContactSection != null) {
        PaymentOption selectedContact = mContactSection.getSelectedItem();
        if (selectedContact != null) {
            // Contacts are created in show(). These should all be instances of AutofillContact.
            assert selectedContact instanceof AutofillContact;
            response.payerPhone = ((AutofillContact) selectedContact).getPayerPhone();
            response.payerEmail = ((AutofillContact) selectedContact).getPayerEmail();
        }
    }
    if (mUiShippingOptions != null) {
        PaymentOption selectedShippingOption = mUiShippingOptions.getSelectedItem();
        if (selectedShippingOption != null && selectedShippingOption.getIdentifier() != null) {
            response.shippingOption = selectedShippingOption.getIdentifier();
        }
    }
    // 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);
    }
    mUI.showProcessingMessage();
    if (mShippingAddressesSection != null) {
        PaymentOption selectedShippingAddress = mShippingAddressesSection.getSelectedItem();
        if (selectedShippingAddress != null) {
            // AutofillAddress.
            assert selectedShippingAddress instanceof AutofillAddress;
            AutofillAddress selectedAutofillAddress = (AutofillAddress) selectedShippingAddress;
            // Addresses to be sent to the merchant should always be complete.
            assert selectedAutofillAddress.isComplete();
            // Record the use of the profile.
            PersonalDataManager.getInstance().recordAndLogProfileUse(selectedAutofillAddress.getProfile().getGUID());
            response.shippingAddress = selectedAutofillAddress.toPaymentAddress();
            // Create the normalization task.
            mPendingPaymentResponse = response;
            mIsWaitingForNormalization = true;
            boolean willNormalizeAsync = PersonalDataManager.getInstance().normalizeAddress(selectedAutofillAddress.getProfile().getGUID(), AutofillAddress.getCountryCode(selectedAutofillAddress.getProfile()), this);
            if (willNormalizeAsync) {
                // If the normalization was not done synchronously, start a timer to cancel the
                // asynchronous normalization if it takes too long.
                mHandler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        onAddressNormalized(null);
                    }
                }, PersonalDataManager.getInstance().getNormalizationTimeoutMS());
            }
            // The payment response will be sent to the merchant in onAddressNormalized instead.
            return;
        }
    }
    mClient.onPaymentResponse(response);
    recordSuccessFunnelHistograms("ReceivedInstrumentDetails");
}
Also used : PaymentOption(org.chromium.chrome.browser.payments.ui.PaymentOption) PaymentResponse(org.chromium.payments.mojom.PaymentResponse)

Aggregations

PaymentOption (org.chromium.chrome.browser.payments.ui.PaymentOption)1 PaymentResponse (org.chromium.payments.mojom.PaymentResponse)1