Skip to content

Commit 67d5876

Browse files
committed
refactor total management and errors
1 parent aee697c commit 67d5876

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

payment-request.html

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@
7272
this.listen(buyButton, 'tap', 'processPurchase');
7373
} else {
7474
buyButton.disabled = true;
75-
console.warn('This browser does not support web payments');
75+
this.dispatchEvent(
76+
new CustomEvent('not-supported')
77+
);
7678
}
7779
},
7880

@@ -87,7 +89,11 @@
8789
.then(function(payment) {
8890
this.fire('payment', payment);
8991
})
90-
.catch(console.error.bind(console));
92+
.catch(function(error) {
93+
this.dispatchEvent(
94+
new CustomEvent('error', error)
95+
);
96+
});
9197
},
9298

9399
_updateItems: function() {
@@ -123,28 +129,22 @@
123129

124130
_updateTotal: function() {
125131
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) {
128133
var total = this.create('payment-item', {
129134
label: this.label,
130135
value: this.value,
131136
currency: this.currency,
132137
});
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-
});
143138
} 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+
});
148148
}
149149
this._setTotal(total.data);
150150
},

0 commit comments

Comments
 (0)