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.text.TextUtils; | 7 import android.text.TextUtils; |
8 | 8 |
9 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 9 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
10 import org.chromium.chrome.browser.payments.ui.PaymentOption; | 10 import org.chromium.chrome.browser.payments.ui.PaymentOption; |
11 | 11 |
12 import javax.annotation.Nullable; | 12 import javax.annotation.Nullable; |
13 | 13 |
14 /** | 14 /** |
15 * The locally stored contact details. | 15 * The locally stored payer info details. |
16 */ | 16 */ |
17 public class AutofillContact extends PaymentOption { | 17 public class AutofillPayerInfo extends PaymentOption { |
18 private final AutofillProfile mProfile; | 18 private final AutofillProfile mProfile; |
19 @Nullable private String mPayerPhone; | 19 @Nullable private String mPayerPhone; |
20 @Nullable private String mPayerEmail; | 20 @Nullable private String mPayerEmail; |
21 | 21 |
22 /** | 22 /** |
23 * Builds contact details. | 23 * Builds payer info details. |
24 * | 24 * |
25 * @param profile The autofill profile where this contact data lives. | 25 * @param profile The autofill profile where this payer info data lives. |
26 * @param phone The phone number. If not empty, this will be the primar
y label. | 26 * @param phone The phone number. If not empty, this will be the primar
y label. |
27 * @param email The email address. If phone is empty, this will be the
primary label. | 27 * @param email The email address. If phone is empty, this will be the
primary label. |
28 * @param isComplete Whether the data in this contact can be sent to the mer
chant as-is. If | 28 * @param isComplete Whether the data in this payer info can be sent to the
merchant as-is. If |
29 * false, user needs to add more information here. | 29 * false, user needs to add more information here. |
30 */ | 30 */ |
31 public AutofillContact(AutofillProfile profile, @Nullable String phone, @Nul
lable String email, | 31 public AutofillPayerInfo(AutofillProfile profile, @Nullable String phone, |
32 boolean isComplete) { | 32 @Nullable String email, boolean isComplete) { |
33 super(profile.getGUID(), null, null, PaymentOption.NO_ICON); | 33 super(profile.getGUID(), null, null, PaymentOption.NO_ICON); |
34 mProfile = profile; | 34 mProfile = profile; |
35 mIsComplete = isComplete; | 35 mIsComplete = isComplete; |
36 setGuidPhoneEmail(profile.getGUID(), phone, email); | 36 setPayerInfo(profile.getGUID(), phone, email); |
37 } | 37 } |
38 | 38 |
39 /** @return Email address. Null if the merchant did not request it or data i
s incomplete. */ | 39 /** @return Email address. Null if the merchant did not request it or data i
s incomplete. */ |
40 @Nullable public String getPayerEmail() { | 40 @Nullable public String getPayerEmail() { |
41 return mPayerEmail; | 41 return mPayerEmail; |
42 } | 42 } |
43 | 43 |
44 /** @return Phone number. Null if the merchant did not request it or data is
incomplete. */ | 44 /** @return Phone number. Null if the merchant did not request it or data is
incomplete. */ |
45 @Nullable public String getPayerPhone() { | 45 @Nullable public String getPayerPhone() { |
46 return mPayerPhone; | 46 return mPayerPhone; |
47 } | 47 } |
48 | 48 |
49 /** @return The autofill profile where this contact data lives. */ | 49 /** @return The autofill profile where this payer info data lives. */ |
50 public AutofillProfile getProfile() { | 50 public AutofillProfile getProfile() { |
51 return mProfile; | 51 return mProfile; |
52 } | 52 } |
53 | 53 |
54 /** | 54 /** |
55 * Updates the profile guid, email address, and phone number and marks this
information | 55 * Updates the profile guid, email address, and phone number and marks this
information |
56 * "complete." Called after the user has edited this contact information. Up
dates the | 56 * "complete." Called after the user has edited this payer info information.
Updates the |
57 * identifier, label, and sublabel. | 57 * identifier, label, and sublabel. |
58 * | 58 * |
59 * @param guid The new identifier to use. Should not be null or empty. | 59 * @param guid The new identifier to use. Should not be null or empty. |
60 * @param phone The new phone number to use. If not empty, this will be the
primary label. | 60 * @param phone The new phone number to use. If not empty, this will be the
primary label. |
61 * @param email The new email address to use. If phone is empty, this will b
e the primary label. | 61 * @param email The new email address to use. If phone is empty, this will b
e the primary label. |
62 */ | 62 */ |
63 public void completeContact(String guid, @Nullable String phone, @Nullable S
tring email) { | 63 public void completePayerInfo(String guid, @Nullable String phone, @Nullable
String email) { |
64 mIsComplete = true; | 64 mIsComplete = true; |
65 setGuidPhoneEmail(guid, phone, email); | 65 setPayerInfo(guid, phone, email); |
66 } | 66 } |
67 | 67 |
68 private void setGuidPhoneEmail(String guid, @Nullable String phone, @Nullabl
e String email) { | 68 private void setPayerInfo(String guid, @Nullable String phone, @Nullable Str
ing email) { |
69 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone; | 69 mPayerPhone = TextUtils.isEmpty(phone) ? null : phone; |
70 mPayerEmail = TextUtils.isEmpty(email) ? null : email; | 70 mPayerEmail = TextUtils.isEmpty(email) ? null : email; |
71 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail : mPay
erPhone, | 71 updateIdentifierAndLabels(guid, mPayerPhone == null ? mPayerEmail : mPay
erPhone, |
72 mPayerPhone == null ? null : mPayerEmail); | 72 mPayerPhone == null ? null : mPayerEmail); |
73 } | 73 } |
74 } | 74 } |
OLD | NEW |