Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "components/payments/content/payment_response_helper.h" | 5 #include "components/payments/content/payment_response_helper.h" |
| 6 | 6 |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/autofill/core/browser/autofill_type.h" | 10 #include "components/autofill/core/browser/autofill_type.h" |
| 11 #include "components/payments/content/payment_request_spec.h" | |
| 11 | 12 |
| 12 namespace payments { | 13 namespace payments { |
| 13 | 14 |
| 14 PaymentResponseHelper::PaymentResponseHelper(){}; | 15 PaymentResponseHelper::PaymentResponseHelper( |
| 16 const std::string& app_locale, | |
| 17 PaymentRequestSpec* spec, | |
| 18 autofill::AutofillProfile* selected_shipping_profile, | |
| 19 autofill::AutofillProfile* selected_contact_profile, | |
| 20 Delegate* delegate) | |
| 21 : app_locale_(app_locale), | |
| 22 spec_(spec), | |
| 23 selected_shipping_profile_(selected_shipping_profile), | |
| 24 selected_contact_profile_(selected_contact_profile), | |
| 25 delegate_(delegate){}; | |
| 15 PaymentResponseHelper::~PaymentResponseHelper(){}; | 26 PaymentResponseHelper::~PaymentResponseHelper(){}; |
| 16 | 27 |
| 17 // static | 28 // static |
| 18 mojom::PaymentAddressPtr | 29 mojom::PaymentAddressPtr |
| 19 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( | 30 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( |
| 20 const autofill::AutofillProfile* const profile, | 31 const autofill::AutofillProfile* const profile, |
| 21 const std::string& app_locale) { | 32 const std::string& app_locale) { |
| 22 mojom::PaymentAddressPtr payment_address = mojom::PaymentAddress::New(); | 33 mojom::PaymentAddressPtr payment_address = mojom::PaymentAddress::New(); |
| 23 | 34 |
| 24 payment_address->country = | 35 payment_address->country = |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 44 payment_address->recipient = base::UTF16ToUTF8(profile->GetInfo( | 55 payment_address->recipient = base::UTF16ToUTF8(profile->GetInfo( |
| 45 autofill::AutofillType(autofill::NAME_FULL), app_locale)); | 56 autofill::AutofillType(autofill::NAME_FULL), app_locale)); |
| 46 | 57 |
| 47 // TODO(crbug.com/705945): Format phone number according to spec. | 58 // TODO(crbug.com/705945): Format phone number according to spec. |
| 48 payment_address->phone = | 59 payment_address->phone = |
| 49 base::UTF16ToUTF8(profile->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); | 60 base::UTF16ToUTF8(profile->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); |
| 50 | 61 |
| 51 return payment_address; | 62 return payment_address; |
| 52 } | 63 } |
| 53 | 64 |
| 65 void PaymentResponseHelper::OnInstrumentDetailsReady( | |
| 66 const std::string& method_name, | |
| 67 const std::string& stringified_details) { | |
| 68 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New(); | |
| 69 | |
| 70 // Make sure that we return the method name that the merchant specified for | |
| 71 // this instrument: cards can be either specified through their name (e.g., | |
| 72 // "visa") or through basic-card's supportedNetworks. | |
| 73 payment_response->method_name = | |
| 74 spec_->IsMethodSupportedThroughBasicCard(method_name) | |
| 75 ? kBasicCardMethodName | |
| 76 : method_name; | |
| 77 payment_response->stringified_details = stringified_details; | |
| 78 | |
| 79 // Shipping Address section | |
| 80 if (spec_->request_shipping()) { | |
| 81 DCHECK(selected_shipping_profile_); | |
| 82 payment_response->shipping_address = | |
| 83 GetMojomPaymentAddressFromAutofillProfile(selected_shipping_profile_, | |
| 84 app_locale_); | |
| 85 | |
| 86 DCHECK(spec_->selected_shipping_option()); | |
| 87 payment_response->shipping_option = spec_->selected_shipping_option()->id; | |
| 88 } | |
| 89 | |
| 90 // Contact Details section. | |
| 91 if (spec_->request_payer_name()) { | |
| 92 DCHECK(selected_contact_profile_); | |
| 93 payment_response->payer_name = | |
| 94 base::UTF16ToUTF8(selected_contact_profile_->GetInfo( | |
| 95 autofill::AutofillType(autofill::NAME_FULL), app_locale_)); | |
| 96 } | |
| 97 if (spec_->request_payer_email()) { | |
| 98 DCHECK(selected_contact_profile_); | |
| 99 payment_response->payer_email = base::UTF16ToUTF8( | |
| 100 selected_contact_profile_->GetRawInfo(autofill::EMAIL_ADDRESS)); | |
| 101 } | |
| 102 if (spec_->request_payer_phone()) { | |
| 103 DCHECK(selected_contact_profile_); | |
| 104 // TODO(crbug.com/705945): Format phone number according to spec. | |
| 105 payment_response->payer_phone = | |
| 106 base::UTF16ToUTF8(selected_contact_profile_->GetRawInfo( | |
| 107 autofill::PHONE_HOME_WHOLE_NUMBER)); | |
| 108 } | |
| 109 | |
| 110 delegate_->OnPaymentResponseReady(std::move(payment_response)); | |
|
Mathieu
2017/04/10 00:03:22
I'm curious why you are not getting an error here,
sebsg
2017/04/10 20:48:24
I applied when I returned the PaymentAddress above
Mathieu
2017/04/10 20:55:58
Ah yes ok
| |
| 111 } | |
| 112 | |
| 54 } // namespace payments | 113 } // namespace payments |
| OLD | NEW |