OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The Chromium Authors. All rights reserved. | 2 * Copyright 2016 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* global PaymentRequest:false */ | 7 /* global PaymentRequest:false */ |
8 /* global toDictionary:false */ | 8 /* global toDictionary:false */ |
9 | 9 |
10 /** | 10 /** |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 | 52 |
53 /** | 53 /** |
54 * Updates the shopping cart with the appropriate shipping prices according to | 54 * Updates the shopping cart with the appropriate shipping prices according to |
55 * the shipping address. | 55 * the shipping address. |
56 * @param {object} details - The shopping cart. | 56 * @param {object} details - The shopping cart. |
57 * @param {ShippingAddress} addr - The shipping address. | 57 * @param {ShippingAddress} addr - The shipping address. |
58 * @return {object} The updated shopping cart. | 58 * @return {object} The updated shopping cart. |
59 */ | 59 */ |
60 function updateDetails(details, addr) { | 60 function updateDetails(details, addr) { |
61 if (addr.regionCode === 'US') { | 61 if (addr.country === 'US') { |
62 var shippingOption = { | 62 var shippingOption = { |
63 id: '', | 63 id: '', |
64 label: '', | 64 label: '', |
65 amount: {currency: 'USD', value: '0.00'} | 65 amount: {currency: 'USD', value: '0.00'} |
66 }; | 66 }; |
67 if (addr.administrativeArea === 'CA') { | 67 if (addr.region === 'CA') { |
68 shippingOption.id = 'ca'; | 68 shippingOption.id = 'ca'; |
69 shippingOption.label = 'Free shipping in California'; | 69 shippingOption.label = 'Free shipping in California'; |
70 details.total.amount.value = '5.00'; | 70 details.total.amount.value = '5.00'; |
71 } else { | 71 } else { |
72 shippingOption.id = 'us'; | 72 shippingOption.id = 'us'; |
73 shippingOption.label = 'Standard shipping in US'; | 73 shippingOption.label = 'Standard shipping in US'; |
74 shippingOption.amount.value = '5.00'; | 74 shippingOption.amount.value = '5.00'; |
75 details.total.amount.value = '10.00'; | 75 details.total.amount.value = '10.00'; |
76 } | 76 } |
77 if (details.displayItems.length === 1) { | 77 if (details.displayItems.length === 1) { |
78 details.displayItems.splice(0, 0, shippingOption); | 78 details.displayItems.splice(0, 0, shippingOption); |
79 } else { | 79 } else { |
80 details.displayItems.splice(0, 1, shippingOption); | 80 details.displayItems.splice(0, 1, shippingOption); |
81 } | 81 } |
82 details.shippingOptions = [shippingOption]; | 82 details.shippingOptions = [shippingOption]; |
83 } else { | 83 } else { |
84 delete details.shippingOptions; | 84 delete details.shippingOptions; |
85 } | 85 } |
86 return details; | 86 return details; |
87 } | 87 } |
OLD | NEW |