Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: chrome/test/data/android/payments/dynamic_shipping.js

Issue 2030193002: Add 'total' field to 'PaymentDetails'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, address comments, and add more tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/test/data/android/payments/free_shipping.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /**
11 * Launches the PaymentRequest UI that offers free shipping in California and 11 * Launches the PaymentRequest UI that offers free shipping in California and
12 * $5.00 shipping in US. Does not allow shipping outside of US. 12 * $5.00 shipping in US. Does not allow shipping outside of US.
13 */ 13 */
14 function buy() { // eslint-disable-line no-unused-vars 14 function buy() { // eslint-disable-line no-unused-vars
15 try { 15 try {
16 var details = { 16 var details = {
17 displayItems: [ 17 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}},
18 { 18 displayItems:
19 id: 'sub', 19 [{label: 'Subtotal', amount: {currency: 'USD', value: '5.00'}}]
20 label: 'Subtotal',
21 amount: {currency: 'USD', value: '5.00'}
22 },
23 {
24 id: 'total',
25 label: 'Total',
26 amount: {currency: 'USD', value: '5.00'}
27 }
28 ]
29 }; 20 };
30 21
31 var request = 22 var request =
32 new PaymentRequest(['visa'], details, {requestShipping: true}); 23 new PaymentRequest(['visa'], details, {requestShipping: true});
33 24
34 request.addEventListener('shippingaddresschange', function(evt) { 25 request.addEventListener('shippingaddresschange', function(evt) {
35 evt.updateWith(new Promise(function(resolve) { 26 evt.updateWith(new Promise(function(resolve) {
36 resolve(updateDetails(details, request.shippingAddress)); 27 resolve(updateDetails(details, request.shippingAddress));
37 })); 28 }));
38 }); 29 });
(...skipping 30 matching lines...) Expand all
69 function updateDetails(details, addr) { 60 function updateDetails(details, addr) {
70 if (addr.regionCode === 'US') { 61 if (addr.regionCode === 'US') {
71 var shippingOption = { 62 var shippingOption = {
72 id: '', 63 id: '',
73 label: '', 64 label: '',
74 amount: {currency: 'USD', value: '0.00'} 65 amount: {currency: 'USD', value: '0.00'}
75 }; 66 };
76 if (addr.administrativeArea === 'CA') { 67 if (addr.administrativeArea === 'CA') {
77 shippingOption.id = 'ca'; 68 shippingOption.id = 'ca';
78 shippingOption.label = 'Free shipping in California'; 69 shippingOption.label = 'Free shipping in California';
79 details.displayItems[details.displayItems.length - 1].amount.value = 70 details.total.amount.value = '5.00';
80 '5.00';
81 } else { 71 } else {
82 shippingOption.id = 'us'; 72 shippingOption.id = 'us';
83 shippingOption.label = 'Standard shipping in US'; 73 shippingOption.label = 'Standard shipping in US';
84 shippingOption.amount.value = '5.00'; 74 shippingOption.amount.value = '5.00';
85 details.items[details.items.length - 1].amount.value = '10.00'; 75 details.total.amount.value = '10.00';
86 } 76 }
87 if (details.items.length === 3) { 77 if (details.displayItems.length === 1) {
88 details.items.splice(-1, 0, shippingOption); 78 details.displayItems.splice(0, 0, shippingOption);
89 } else { 79 } else {
90 details.items.splice(-2, 1, shippingOption); 80 details.displayItems.splice(0, 1, shippingOption);
91 } 81 }
92 details.shippingOptions = [shippingOption]; 82 details.shippingOptions = [shippingOption];
93 } else { 83 } else {
94 delete details.shippingOptions; 84 delete details.shippingOptions;
95 } 85 }
96 return details; 86 return details;
97 } 87 }
OLDNEW
« no previous file with comments | « chrome/android/java_sources.gni ('k') | chrome/test/data/android/payments/free_shipping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698