Created
August 6, 2015 14:18
-
-
Save matiasfha/b15e89825c5d0ed395bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tripOverviewController ($scope, pricingService) { | |
this.includeMeetAndGreet = function () { | |
if(this.checkoutData){ | |
return this.checkoutData.trip.includeMeetAndGreet === 1; | |
} | |
return false; | |
}; | |
this.showCouponField = function () { | |
if(this.checkoutData){ | |
return this.checkoutData.trip.voyages[0].provider.acceptCoupon; | |
} | |
return false; | |
}; | |
this.showGratuity = function() { | |
if (this.checkoutData) { | |
var type = this.checkoutData.trip.voyages[0].vehicle.type.toLowerCase().replace(/\s/g, ''); | |
if (type === 'bus' || type === 'expresstrain') { | |
return false; | |
} | |
var gratuityIncluded = this.checkoutData.trip.voyages[0].bookingDetails.gratuityIncluded !== 0; | |
var acceptsGratuity = this.checkoutData.trip.voyages[0].bookingDetails.acceptsGratuity !== 0; | |
return true && !gratuityIncluded && acceptsGratuity; | |
} | |
return false; | |
}; | |
this.updateGratuity = function (gratuityPercent) { | |
var price = this.checkoutData.trip.price; | |
var params = { | |
amount: price.raw, | |
gratuity: gratuityPercent, | |
meet_and_greet_amount: (this.checkoutData.includeMeetAndGreet === 0)? 0 : this.checkoutData.meetAndGreetPrice | |
}; | |
if('coupon_code' in this.checkoutData){ | |
params.coupon_code = this.checkoutData.coupon_code; | |
} | |
pricingService.getPrice(params).then(function(data) { | |
this.checkoutData.trip.price.total = data.final_price; | |
this.checkoutData.gratuity = this.gratuity; | |
this.checkoutData.gratuityPrice = data.gratuity; | |
}.bind(this)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment