Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
coupon.validate(code, $.proxy(function(valid) {
var discount;
this.updateTaxes();
this.updateTotal();
// TODO: Move coupon live validation to form
form._setCouponValidationClass(valid);
if (!valid || code === '') {
$(groupSelector).hide();
return;
}
// TODO: Discount logic instead of assuming single flat amount
discount = formatMoney(this._getDiscount());
$(priceSelector).text(discount);
$(groupSelector).show();
}, this));
},
updateTaxes: function() {
var countryCode = this._getCountry();
var zip = this._getZip();
// Cache hit
if (this._taxes[countryCode + zip] !== undefined) {
var taxRate = this._taxes[countryCode + zip];
var tax = taxRate * this._getSubtotal();
tax = formatMoney(tax);
this.$form.find('.Celery-OrderSummary-price--taxes').text(tax);
this.updateTotal();
return;
}
celeryClient.fetchTaxes({
shipping_country: countryCode,
shipping_zip: zip
}, $.proxy(function(err, data) {
if (err || !data || !data.data || data.data.base === undefined) {
return;
}
this._taxes[countryCode + zip] = data.data.base;
updateOrderSummary: function() {
var shopData = shop.data;
if (!shopData) return;
var quantity = this._getQuantity();
var price = formatMoney(this._getPrice());
var shipping = formatMoney(this._getShipping());
var $form = this.$form;
if (config.features.taxes && celeryClient.config.userId) {
this.updateTaxes();
}
if (config.features.coupons && celeryClient.config.userId) {
this.updateDiscount();
}
this.updateTotal();
$form.find('.Celery-OrderSummary-price--price').text(price);
$form.find('.Celery-OrderSummary-price--shipping').text(shipping);
updateTotal: function() {
var total = formatMoney(this._getTotal());
this.$form.find('.Celery-OrderSummary-price--total').text(total);
},
updateOrderSummary: function() {
var shopData = shop.data;
if (!shopData) return;
var quantity = this._getQuantity();
var price = formatMoney(this._getPrice());
var shipping = formatMoney(this._getShipping());
var $form = this.$form;
if (config.features.taxes && celeryClient.config.userId) {
this.updateTaxes();
}
if (config.features.coupons && celeryClient.config.userId) {
this.updateDiscount();
}
this.updateTotal();
$form.find('.Celery-OrderSummary-price--price').text(price);
$form.find('.Celery-OrderSummary-price--shipping').text(shipping);
$form.find('.Celery-OrderSummary-number--quantity').text(quantity);