* VRFS-3670 - affiliate rate usage

This commit is contained in:
Seth Call 2015-10-20 21:09:58 -05:00
parent 9dbcdb2436
commit 27328a7c65
5 changed files with 16 additions and 3 deletions

View File

@ -2,6 +2,8 @@
<%= f.semantic_errors *f.object.errors.keys %>
<%= f.inputs do %>
<%= f.input(:partner_name, :input_html => {:maxlength => 128}) %>
<%= f.input(:entity_type, :as => :select, :collection => AffiliatePartner::ENTITY_TYPES) %>
<%= f.input(:rate) %>
<% end %>
<%= f.actions %>
<% end %>

View File

@ -306,4 +306,5 @@ jam_track_slug.sql
mixdown.sql
aac_master.sql
video_recording.sql
web_playable_jamtracks.sql
web_playable_jamtracks.sql
affiliate_partner_rate.sql

View File

@ -0,0 +1 @@
ALTER TABLE affiliate_partners ADD COLUMN rate NUMERIC(8,2) DEFAULT 0.10;

View File

@ -9,7 +9,7 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
has_many :months, :class_name => 'JamRuby::AffiliateMonthlyPayment', foreign_key: :affiliate_partner_id, inverse_of: :affiliate_partner
has_many :traffic_totals, :class_name => 'JamRuby::AffiliateTrafficTotal', foreign_key: :affiliate_partner_id, inverse_of: :affiliate_partner
has_many :visits, :class_name => 'JamRuby::AffiliateReferralVisit', foreign_key: :affiliate_partner_id, inverse_of: :affiliate_partner
attr_accessible :partner_name, :partner_code, :partner_user_id
attr_accessible :partner_name, :partner_code, :partner_user_id, :entity_type, :rate, as: :admin
ENTITY_TYPES = %w{ Individual Sole\ Proprietor Limited\ Liability\ Company\ (LLC) Partnership Trust/Estate S\ Corporation C\ Corporation Other }
@ -124,7 +124,7 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
product_info = shopping_cart.product_info
# subtract the total quantity from the freebie quantity, to see how much we should attribute to them
real_quantity = product_info[:quantity].to_i - product_info[:marked_for_redeem].to_i
{fee_in_cents: real_quantity * 20}
{fee_in_cents: (1.99 * 100 * real_quantity * rate).round}
else
false
end

View File

@ -110,6 +110,15 @@ describe AffiliatePartner do
user.should_attribute_sale?(shopping_cart).should eq({fee_in_cents:20})
end
it "user with an affiliate relationship (with a custom rate) buying a jamtrack" do
user.affiliate_referral = partner
user.save!
partner.rate = 0.25
partner.save!
shopping_cart = ShoppingCart.create user, jam_track, 1, false
user.should_attribute_sale?(shopping_cart).should eq({fee_in_cents:50})
end
it "user with an affiliate relationship redeeming a jamtrack" do
user.affiliate_referral = partner
user.save!