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

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

Issue 2449943002: Add pending line item support for web payments. (Closed)
Patch Set: Comments Created 4 years, 1 month 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
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 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}}, 17 total: {label: 'Total', amount: {currency: 'USD', value: '5.00'}},
18 displayItems: 18 displayItems: [
19 [{label: 'Subtotal', amount: {currency: 'USD', value: '5.00'}}] 19 {
20 label: 'Pending shipping price',
21 amount: {currency: 'USD', value: '0.00'},
22 pending: true
23 },
24 {
25 label: 'Subtotal',
26 amount: {currency: 'USD', value: '5.00'}
27 }
28 ]
20 }; 29 };
21 30
22 var request = new PaymentRequest( 31 var request = new PaymentRequest(
23 [{supportedMethods: ['visa']}], details, {requestShipping: true}); 32 [{supportedMethods: ['visa']}], details, {requestShipping: true});
24 33
25 request.addEventListener('shippingaddresschange', function(evt) { 34 request.addEventListener('shippingaddresschange', function(evt) {
26 evt.updateWith(new Promise(function(resolve) { 35 evt.updateWith(new Promise(function(resolve) {
27 resolve(updateDetails(details, request.shippingAddress)); 36 resolve(updateDetails(details, request.shippingAddress));
28 })); 37 }));
29 }); 38 });
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 if (addr.region === 'CA') { 78 if (addr.region === 'CA') {
70 shippingOption.id = 'californiaShippingOption'; 79 shippingOption.id = 'californiaShippingOption';
71 shippingOption.label = 'Free shipping in California'; 80 shippingOption.label = 'Free shipping in California';
72 details.total.amount.value = '5.00'; 81 details.total.amount.value = '5.00';
73 } else { 82 } else {
74 shippingOption.id = 'usShippingOption'; 83 shippingOption.id = 'usShippingOption';
75 shippingOption.label = 'Standard shipping in US'; 84 shippingOption.label = 'Standard shipping in US';
76 shippingOption.amount.value = '5.00'; 85 shippingOption.amount.value = '5.00';
77 details.total.amount.value = '10.00'; 86 details.total.amount.value = '10.00';
78 } 87 }
79 if (details.displayItems.length === 1) { 88 details.displayItems.splice(0, 1, shippingOption);
80 details.displayItems.splice(0, 0, shippingOption);
81 } else {
82 details.displayItems.splice(0, 1, shippingOption);
83 }
84 details.shippingOptions = [shippingOption]; 89 details.shippingOptions = [shippingOption];
85 } else { 90 } else {
86 delete details.shippingOptions; 91 delete details.shippingOptions;
87 } 92 }
88 return details; 93 return details;
89 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698