| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.payments; | 5 package org.chromium.chrome.browser.payments; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.os.Handler; | 9 import android.os.Handler; |
| 10 import android.text.TextUtils; | 10 import android.text.TextUtils; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; | 297 if (!parseAndValidateDetailsOrDisconnectFromClient(details)) return; |
| 298 | 298 |
| 299 // Empty shipping options means the merchant cannot ship to the user's s
elected shipping | 299 // Empty shipping options means the merchant cannot ship to the user's s
elected shipping |
| 300 // address. | 300 // address. |
| 301 if (mUiShippingOptions.isEmpty() && !mMerchantNeedsShippingAddress) { | 301 if (mUiShippingOptions.isEmpty() && !mMerchantNeedsShippingAddress) { |
| 302 disconnectFromClientWithDebugMessage("Merchant indicates inability t
o ship although " | 302 disconnectFromClientWithDebugMessage("Merchant indicates inability t
o ship although " |
| 303 + "originally indicated that can ship anywhere"); | 303 + "originally indicated that can ship anywhere"); |
| 304 return; | 304 return; |
| 305 } | 305 } |
| 306 | 306 |
| 307 mUI.updateOrderSummarySection(mUiShoppingCart); | 307 if (mUiShippingOptions.isEmpty() && mShippingAddressesSection.getSelecte
dItem() != null) { |
| 308 mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mUiShippingOpt
ions); | 308 mShippingAddressesSection.getSelectedItem().setInvalid(); |
| 309 mShippingAddressesSection.setSelectedItemIndex(SectionInformation.IN
VALID_SELECTION); |
| 310 } |
| 311 |
| 312 if (mPaymentInformationCallback != null) { |
| 313 providePaymentInformation(); |
| 314 } else { |
| 315 mUI.updateOrderSummarySection(mUiShoppingCart); |
| 316 mUI.updateSection(PaymentRequestUI.TYPE_SHIPPING_OPTIONS, mUiShippin
gOptions); |
| 317 } |
| 309 } | 318 } |
| 310 | 319 |
| 311 /** | 320 /** |
| 312 * Sets the total, display line items, and shipping options based on input a
nd returns the | 321 * Sets the total, display line items, and shipping options based on input a
nd returns the |
| 313 * status boolean. That status is true for valid data, false for invalid dat
a. If the input is | 322 * status boolean. That status is true for valid data, false for invalid dat
a. If the input is |
| 314 * invalid, disconnects from the client. Both raw and UI versions of data ar
e updated. | 323 * invalid, disconnects from the client. Both raw and UI versions of data ar
e updated. |
| 315 * | 324 * |
| 316 * @param details The total, line items, and shipping options to parse, vali
date, and save in | 325 * @param details The total, line items, and shipping options to parse, vali
date, and save in |
| 317 * member variables. | 326 * member variables. |
| 318 * @return True if the data is valid. False if the data is invalid. | 327 * @return True if the data is valid. False if the data is invalid. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 */ | 471 */ |
| 463 @Override | 472 @Override |
| 464 public void getDefaultPaymentInformation(Callback<PaymentInformation> callba
ck) { | 473 public void getDefaultPaymentInformation(Callback<PaymentInformation> callba
ck) { |
| 465 mPaymentInformationCallback = callback; | 474 mPaymentInformationCallback = callback; |
| 466 | 475 |
| 467 if (mPaymentMethodsSection == null) return; | 476 if (mPaymentMethodsSection == null) return; |
| 468 | 477 |
| 469 mHandler.post(new Runnable() { | 478 mHandler.post(new Runnable() { |
| 470 @Override | 479 @Override |
| 471 public void run() { | 480 public void run() { |
| 472 provideDefaultPaymentInformation(); | 481 providePaymentInformation(); |
| 473 } | 482 } |
| 474 }); | 483 }); |
| 475 } | 484 } |
| 476 | 485 |
| 477 private void provideDefaultPaymentInformation() { | 486 private void providePaymentInformation() { |
| 478 mPaymentInformationCallback.onResult(new PaymentInformation( | 487 mPaymentInformationCallback.onResult(new PaymentInformation(mUiShoppingC
art, |
| 479 mUiShoppingCart.getTotal(), mShippingAddressesSection.getSelecte
dItem(), | 488 mShippingAddressesSection, mUiShippingOptions, mPaymentMethodsSe
ction)); |
| 480 mUiShippingOptions.getSelectedItem(), mPaymentMethodsSection.get
SelectedItem())); | |
| 481 mPaymentInformationCallback = null; | 489 mPaymentInformationCallback = null; |
| 482 } | 490 } |
| 483 | 491 |
| 484 @Override | 492 @Override |
| 485 public void getShoppingCart(final Callback<ShoppingCart> callback) { | 493 public void getShoppingCart(final Callback<ShoppingCart> callback) { |
| 486 mHandler.post(new Runnable() { | 494 mHandler.post(new Runnable() { |
| 487 @Override | 495 @Override |
| 488 public void run() { | 496 public void run() { |
| 489 callback.onResult(mUiShoppingCart); | 497 callback.onResult(mUiShoppingCart); |
| 490 } | 498 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 503 callback.onResult(mUiShippingOptions); | 511 callback.onResult(mUiShippingOptions); |
| 504 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS)
{ | 512 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS)
{ |
| 505 assert mPaymentMethodsSection != null; | 513 assert mPaymentMethodsSection != null; |
| 506 callback.onResult(mPaymentMethodsSection); | 514 callback.onResult(mPaymentMethodsSection); |
| 507 } | 515 } |
| 508 } | 516 } |
| 509 }); | 517 }); |
| 510 } | 518 } |
| 511 | 519 |
| 512 @Override | 520 @Override |
| 513 public void onSectionOptionChanged( | 521 public boolean onSectionOptionChanged(@PaymentRequestUI.DataType int optionT
ype, |
| 514 @PaymentRequestUI.DataType int optionType, PaymentOption option) { | 522 PaymentOption option, Callback<PaymentInformation> callback) { |
| 515 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { | 523 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { |
| 516 // This may update the line items and/or the shipping options. | |
| 517 assert option instanceof AutofillAddress; | 524 assert option instanceof AutofillAddress; |
| 518 mShippingAddressesSection.setSelectedItem(option); | 525 mShippingAddressesSection.setSelectedItem(option); |
| 519 if (mMerchantNeedsShippingAddress) { | 526 if (mMerchantNeedsShippingAddress) { |
| 527 mPaymentInformationCallback = callback; |
| 528 // This updates the line items and the shipping options asynchro
nously. |
| 520 mClient.onShippingAddressChange(((AutofillAddress) option).toPay
mentAddress()); | 529 mClient.onShippingAddressChange(((AutofillAddress) option).toPay
mentAddress()); |
| 530 return true; |
| 521 } | 531 } |
| 522 } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) { | 532 } else if (optionType == PaymentRequestUI.TYPE_SHIPPING_OPTIONS) { |
| 523 // This may update the line items. | 533 // This may update the line items. |
| 524 mUiShippingOptions.setSelectedItem(option); | 534 mUiShippingOptions.setSelectedItem(option); |
| 525 mClient.onShippingOptionChange(option.getIdentifier()); | 535 mClient.onShippingOptionChange(option.getIdentifier()); |
| 526 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { | 536 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { |
| 527 assert option instanceof PaymentInstrument; | 537 assert option instanceof PaymentInstrument; |
| 528 mPaymentMethodsSection.setSelectedItem(option); | 538 mPaymentMethodsSection.setSelectedItem(option); |
| 529 } | 539 } |
| 540 return false; |
| 530 } | 541 } |
| 531 | 542 |
| 532 | 543 |
| 533 @Override | 544 @Override |
| 534 public void onSectionAddOption(@PaymentRequestUI.DataType int optionType) { | 545 public void onSectionAddOption(@PaymentRequestUI.DataType int optionType) { |
| 535 // TODO(rouslan, dfalcantara): Make this code do something more useful. | 546 // TODO(rouslan, dfalcantara): Make this code do something more useful. |
| 536 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { | 547 if (optionType == PaymentRequestUI.TYPE_SHIPPING_ADDRESSES) { |
| 537 PreferencesLauncher.launchSettingsPage(mContext, AutofillProfileEdit
or.class.getName()); | 548 PreferencesLauncher.launchSettingsPage(mContext, AutofillProfileEdit
or.class.getName()); |
| 538 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { | 549 } else if (optionType == PaymentRequestUI.TYPE_PAYMENT_METHODS) { |
| 539 PreferencesLauncher.launchSettingsPage( | 550 PreferencesLauncher.launchSettingsPage( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 instrument.dismiss(); | 623 instrument.dismiss(); |
| 613 } | 624 } |
| 614 } | 625 } |
| 615 } | 626 } |
| 616 | 627 |
| 617 if (mPendingApps.isEmpty()) { | 628 if (mPendingApps.isEmpty()) { |
| 618 mPaymentMethodsSection = new SectionInformation( | 629 mPaymentMethodsSection = new SectionInformation( |
| 619 PaymentRequestUI.TYPE_PAYMENT_METHODS, 0, mPendingInstrument
s); | 630 PaymentRequestUI.TYPE_PAYMENT_METHODS, 0, mPendingInstrument
s); |
| 620 mPendingInstruments.clear(); | 631 mPendingInstruments.clear(); |
| 621 | 632 |
| 622 if (mPaymentInformationCallback != null) provideDefaultPaymentInform
ation(); | 633 if (mPaymentInformationCallback != null) providePaymentInformation()
; |
| 623 } | 634 } |
| 624 } | 635 } |
| 625 | 636 |
| 626 /** | 637 /** |
| 627 * Called after retrieving instrument details. | 638 * Called after retrieving instrument details. |
| 628 */ | 639 */ |
| 629 @Override | 640 @Override |
| 630 public void onInstrumentDetailsReady(String methodName, String stringifiedDe
tails) { | 641 public void onInstrumentDetailsReady(String methodName, String stringifiedDe
tails) { |
| 631 PaymentResponse response = new PaymentResponse(); | 642 PaymentResponse response = new PaymentResponse(); |
| 632 response.methodName = methodName; | 643 response.methodName = methodName; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 } | 698 } |
| 688 mPaymentMethodsSection = null; | 699 mPaymentMethodsSection = null; |
| 689 } | 700 } |
| 690 } | 701 } |
| 691 | 702 |
| 692 private void closeClient() { | 703 private void closeClient() { |
| 693 if (mClient != null) mClient.close(); | 704 if (mClient != null) mClient.close(); |
| 694 mClient = null; | 705 mClient = null; |
| 695 } | 706 } |
| 696 } | 707 } |
| OLD | NEW |