* VRFS-3220 - estimate taxes manually

This commit is contained in:
Seth Call 2015-05-09 08:30:12 -05:00
parent 35057a4da0
commit 62b6820e90
5 changed files with 164 additions and 33 deletions

View File

@ -153,25 +153,60 @@
else {
$placeOrder.addClass('disabled').unbind('click').on('click', false)
}
estimateTaxes(carts, recurlyAccountInfo.billing_info);
}
}
var planPricing = {}
function displayTax(effectiveQuantity, item_tax, total_with_tax) {
var totalTax = 0;
var totalPrice = 0;
var unitTax = item_tax * effectiveQuantity;
totalTax += unitTax;
var priceElement = $screen.find('.order-right-page .plan.jamtrack')
var totalUnitPrice = total_with_tax * effectiveQuantity;
totalPrice += totalUnitPrice;
if(priceElement.length == 0) {
logger.error("unable to find price element for jamtrack");
app.notify({title: "Error Encountered", text: "Unable to find plan info for jam track"})
return false;
$screen.find('.order-right-page .order-items-value.taxes').text('$' + totalTax.toFixed(2))
$screen.find('.order-right-page .order-items-value.grand-total').text('$' + totalPrice.toFixed(2))
}
function estimateTaxes(carts, billing_info) {
var planPricing = {}
var priceElement = $screen.find('.order-right-page .plan.jamtrack')
if(priceElement.length == 0) {
logger.error("unable to find price element for jamtrack");
app.notify({title: "Error Encountered", text: "Unable to find plan info for jam track"})
return false;
}
logger.debug("creating recurly pricing element for plan: " + gon.recurly_tax_estimate_jam_track_plan)
var effectiveQuantity = 0
context._.each(carts, function(cart) {
effectiveQuantity += cart.product_info.quantity - cart.product_info.marked_for_redeem
})
if (gon.global.estimate_taxes) {
var state = billing_info.state;
var country = billing_info.country;
if (state) {
state = state.toLowerCase();
}
if (country) {
country = country.toLowerCase();
}
var taxRate = 0;
if (state && country && (state == 'tx' || state == 'texas') && country == 'us') {
taxRate = 0.0825;
}
logger.debug("creating recurly pricing element for plan: " + gon.recurly_tax_estimate_jam_track_plan)
var effectiveQuantity = 0
context._.each(carts, function(cart) {
effectiveQuantity += cart.product_info.quantity - cart.product_info.marked_for_redeem
})
var unitTax = 1.99 * taxRate;
displayTax(effectiveQuantity, unitTax, 1.99 + unitTax)
}
else {
var pricing = context.recurly.Pricing();
pricing.plan_code = gon.recurly_tax_estimate_jam_track_plan;
@ -180,19 +215,9 @@
// this is called when the plan is resolved against Recurly. It will have tax info, which is the only way we can get it.
pricing.on('change', function(price) {
var totalTax = 0;
var totalPrice = 0;
logger.debug("pricing", pricing)
displayTax(effectiveQuantity, Number(pricing.price.now.tax), Number(pricing.price.now.total));
var unitTax = Number(pricing.price.now.tax) * effectiveQuantity;
totalTax += unitTax;
var totalUnitPrice = Number(pricing.price.now.total) * effectiveQuantity;
totalPrice += totalUnitPrice;
$screen.find('.order-right-page .order-items-value.taxes').text('$' + totalTax.toFixed(2))
$screen.find('.order-right-page .order-items-value.grand-total').text('$' + totalPrice.toFixed(2))
})
pricing.attach(priceElement.eq(0))

View File

@ -334,6 +334,6 @@ if defined?(Bundler)
config.gear_check_ignore_high_latency = false
config.remove_whitespace_credit_card = false
config.estimate_texas_taxes = false
config.estimate_taxes = true
end
end

View File

@ -15,4 +15,5 @@ Gon.global.one_free_jamtrack_per_user = Rails.application.config.one_free_jamtra
Gon.global.video_available = Rails.application.config.video_available
Gon.global.gear_check_ignore_high_latency = Rails.application.config.gear_check_ignore_high_latency
Gon.global.purchases_enabled = Rails.application.config.purchases_enabled
Gon.global.estimate_taxes = Rails.application.config.estimate_taxes
Gon.global.env = Rails.env

15
web/lib/tasks/urls.rake Normal file
View File

@ -0,0 +1,15 @@
namespace :urls do
task jam_tracks: :environment do |task, args|
File.open('urls.csv', 'w') { |f|
JamTrack.all.each do |jam_track|
prefix = "jamtrack-"
plan_code = jam_track.plan_code["jamtrack-".length..-1]
f.puts('http://www.jamkazam.com/landing/jamtracks/' + plan_code)
#f.puts('http://www.jamkazam.com/landing/jamtracks/bands/' + plan_code)
end
}
end
end

View File

@ -458,7 +458,7 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
find('.order-panel .action-bar .place-order.disabled')
end
it "shows one free item correctly" do
it "shows one free item correctly (not-Texas)" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
@ -478,7 +478,49 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
find('.order-items-value.grand-total', text:'$0.00')
end
it "shows one free, one not free item correctly" do
it "shows one free item correctly (Texas)" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$0.00')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$0.00')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$0.00')
end
it "shows one free, one not free item correctly (not-Texas)" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reload
ShoppingCart.add_jam_track_to_cart(user, jamtrack_pearljam_evenflow)
billing_info[:state] = 'AR'
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$1.99')
end
it "shows one free, one not free item correctly (Texas)" do
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reload
ShoppingCart.add_jam_track_to_cart(user, jamtrack_pearljam_evenflow)
@ -491,6 +533,29 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.16')
find('.order-items-value.grand-total', text:'$2.15')
end
it "shows one non-free item correctly (not Texas)" do
user.has_redeemable_jamtrack = false
user.save!
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
billing_info[:state] = 'MA'
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
@ -499,7 +564,7 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
find('.order-items-value.grand-total', text:'$1.99')
end
it "shows one non-free item correctly" do
it "shows one non-free item correctly (Texas)" do
user.has_redeemable_jamtrack = false
user.save!
@ -517,11 +582,36 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
find('.order-items-value.order-total', text:'$1.99')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$1.99')
find('.order-items-value.taxes', text:'$0.16')
find('.order-items-value.grand-total', text:'$2.15')
end
it "shows two non-free items correctly" do
it "shows two non-free items correctly (non-Texas)" do
user.has_redeemable_jamtrack = false
user.save!
ShoppingCart.add_jam_track_to_cart(user, jamtrack_acdc_backinblack)
user.reload
ShoppingCart.add_jam_track_to_cart(user, jamtrack_pearljam_evenflow)
billing_info[:state] = 'MA'
@recurlyClient.create_account(user, billing_info)
user.reuse_card = true
user.has_redeemable_jamtrack = true
user.save!
fast_signin(user, '/client#/checkoutOrder')
find('p.order-prompt')
find('.order-items-value.order-total', text:'$3.98')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$3.98')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$3.98')
end
it "shows two non-free items correctly (Texas)" do
user.has_redeemable_jamtrack = false
user.save!
@ -541,8 +631,8 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
find('.order-items-value.order-total', text:'$3.98')
find('.order-items-value.shipping-handling', text:'$0.00')
find('.order-items-value.sub-total', text:'$3.98')
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$3.98')
find('.order-items-value.taxes', text:'$0.33')
find('.order-items-value.grand-total', text:'$4.31')
find('.place-order-center a.button-orange.place-order').trigger(:click)