|
72 | 72 | this.listen(buyButton, 'tap', 'processPurchase'); |
73 | 73 | } else { |
74 | 74 | buyButton.disabled = true; |
75 | | - console.warn('This browser does not support web payments'); |
| 75 | + this.dispatchEvent( |
| 76 | + new CustomEvent('not-supported') |
| 77 | + ); |
76 | 78 | } |
77 | 79 | }, |
78 | 80 |
|
|
87 | 89 | .then(function(payment) { |
88 | 90 | this.fire('payment', payment); |
89 | 91 | }) |
90 | | - .catch(console.error.bind(console)); |
| 92 | + .catch(function(error) { |
| 93 | + this.dispatchEvent( |
| 94 | + new CustomEvent('error', error) |
| 95 | + ); |
| 96 | + }); |
91 | 97 | }, |
92 | 98 |
|
93 | 99 | _updateItems: function() { |
|
123 | 129 |
|
124 | 130 | _updateTotal: function() { |
125 | 131 | var total = Polymer.dom(this.$.total).getDistributedNodes()[0]; |
126 | | - if (total) { |
127 | | - } else if (this.label && this.value && this.currency) { |
| 132 | + if (this.label && this.value && this.currency) { |
128 | 133 | var total = this.create('payment-item', { |
129 | 134 | label: this.label, |
130 | 135 | value: this.value, |
131 | 136 | currency: this.currency, |
132 | 137 | }); |
133 | | - } else if (this.items.length) { |
134 | | - var totalAmount = 0; |
135 | | - for (var i = 0; i < this.items.length; i++) { |
136 | | - totalAmount += this.items[i].amount.value; |
137 | | - } |
138 | | - var total = this.create('payment-item', { |
139 | | - label: this.label || 'Total', |
140 | | - value: totalAmount, |
141 | | - currency: this.currency || this.items[0].amount.currency || 'USD', |
142 | | - }); |
143 | 138 | } else { |
144 | | - total = { |
145 | | - data: null |
146 | | - }; |
147 | | - console.warn('Total couldn\'t be calculated'); |
| 139 | + var totalAmount = 0; |
| 140 | + for (var i = 0; i < this.items.length; i++) { |
| 141 | + totalAmount += this.items[i].amount.value; |
| 142 | + } |
| 143 | + var total = this.create('payment-item', { |
| 144 | + label: this.label || 'Total', |
| 145 | + value: totalAmount, |
| 146 | + currency: this.currency || (this.items.length && this.items[0].amount.currency) || 'USD' |
| 147 | + }); |
148 | 148 | } |
149 | 149 | this._setTotal(total.data); |
150 | 150 | }, |
|
0 commit comments