use of org.chromium.chrome.browser.payments.ui.PaymentOption 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");
}
use of org.chromium.chrome.browser.payments.ui.PaymentOption in project AndroidChromium by JackyAndroid.
the class PaymentRequestImpl method closeUI.
/**
* Closes the UI. If the client is still connected, then it's notified of UI hiding.
*
* @param immediateClose If true, then UI immediately closes. If false, the UI shows the error
* message "There was an error processing your order." This message
* implies that the merchant attempted to process the order, failed, and
* called complete("fail") to notify the user. Therefore, this parameter
* may be "false" only when called from
* {@link PaymentRequestImpl#complete(int)}. All other callers should
* always pass "true."
*/
private void closeUI(boolean immediateClose) {
if (mUI != null) {
mUI.close(immediateClose, new Runnable() {
@Override
public void run() {
if (mClient != null)
mClient.onComplete();
closeClient();
}
});
mUI = null;
}
if (mPaymentMethodsSection != null) {
for (int i = 0; i < mPaymentMethodsSection.getSize(); i++) {
PaymentOption option = mPaymentMethodsSection.getItem(i);
assert option instanceof PaymentInstrument;
((PaymentInstrument) option).dismiss();
}
mPaymentMethodsSection = null;
}
mContext.getTabModelSelector().removeObserver(mSelectorObserver);
mContext.getCurrentTabModel().removeObserver(mTabModelObserver);
}
use of org.chromium.chrome.browser.payments.ui.PaymentOption in project AndroidChromium by JackyAndroid.
the class PaymentRequestImpl method getValidatedShippingOptions.
/**
* Validates a list of shipping options and returns their parsed representation or null if
* invalid.
*
* @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 or null if invalid.
*/
private static SectionInformation getValidatedShippingOptions(PaymentShippingOption[] options, String totalCurrency, CurrencyStringFormatter formatter) {
// Shipping options are optional.
if (options == null || options.length == 0) {
return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS);
}
for (int i = 0; i < options.length; i++) {
PaymentShippingOption option = options[i];
// Each "currency" should match the total currency.
if (option == null || TextUtils.isEmpty(option.id) || TextUtils.isEmpty(option.label) || option.amount == null || TextUtils.isEmpty(option.amount.currency) || TextUtils.isEmpty(option.amount.value) || !totalCurrency.equals(option.amount.currency) || !formatter.isValidAmountValue(option.amount.value)) {
return null;
}
}
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), PaymentOption.NO_ICON));
if (option.selected)
selectedItemIndex = i;
}
return new SectionInformation(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, selectedItemIndex, result);
}
Aggregations