From fd4d21ae78cf2c214ff8aea9c05b356483bfabf2 Mon Sep 17 00:00:00 2001
From: Seth Call
+ Thank you for signing up to take online music lessons using the JamClass service by JamKazam. JamKazam technology was built from the ground up for playing music live in sync with studio quality audio from different locations over the Internet, and for delivering amazing online music lessons. +
++ To get ready to take JamClass lessons online, here are the things you'll want to do: +
+ +1. Set Up Your Gear
+ When you sign up, someone from JamKazam will get in touch with you via email within a couple of business days to help you get set up. If you don't hear from us within a couple of days, please email us at support@jamkazam.com or call us at 1-877-376-8742. To play in online lessons, you will need at a minimum: (1) a Windows or Mac computer; (2) normal home Internet service; and (3) a pair of headphones or earbuds you can plug into the headphone minijack on your computer. If you would like to benefit from studio quality audio (recommended) in your lessons, JamKazam offers an amazing audio package for just $49.99 (less than our cost) that includes an audio interface (a little box that connects to your computer via USB cable), a microphone, a mic cable, and a mic stand. We'll discuss these options with you, and we're happy to support you whichever path you choose. We'll help step you through the setup process, and we'll even get into an online session with you to make sure everything is working properly, and to show you some of the key features you can use during online lessons.
+
+
2. Book Lessons
+ Once your gear is set up, you are ready to take lessons. Go to this web page: <%= @user.school.teacher_list_url %>. If your school has preferred instructors, they will be listed on this page, and you can click a button to book a lesson with the teacher from whom you want to take lessons. If your school doesn't have preferred instructors, then there is a link on this page to use our teacher search feature to find a great instructor from our broader community of teachers. You'll need your parents to enter credit card information to pay for your lessons. We use one of the largest and most secure commerce platforms on the Internet called Stripe, so you can feel confident your financial information will be very secure.
+
3. Learn About JamClass Features
+ You can also review our JamClass user guide for students
+ to familiarize yourself with the features and resources available to you through our JamClass lesson service. This includes how to join your teacher in online lessons, features you can use while in lessons, and more.
+
+ Again, welcome to JamKazam and our JamClass online music lesson service, and we look forward to helping you learn and grow as a musician! +
+<% else %> +Thank you for signing up to take online music lessons using the JamClass service by JamKazam. JamKazam technology was @@ -47,6 +74,7 @@ Again, welcome to JamKazam and our JamClass online music lesson service, and we look forward to helping you learn and grow as a musician!
+<% end %>Best Regards,
Team JamKazam
2. Set Up Your Gear
- Click
- here for information on the gear requirements to effectively teach using the JamClass service. When you have
- everything you need,
- use
- this set of help articles as a good step-by-step guide to set up your gear for use with the
- JamKazam application. After you have signed up, someone from JamKazam will contact you to schedule a test online
- session, in which we will make sure your audio and video gear are working properly in an online session, and to make
- sure you feel comfortable with the key features you will be using in sessions with students.
+ <% if @education %>
+ Click
+ here for information on the gear requirements to effectively teach using the JamClass service. At a minimum, you'll need a Windows or Mac computer and home Internet service, but we also recommend using an audio interface for superior audio quality. If you already have an audio interface for home recording, you can very likely use the one you have. If not, JamKazam offers a high quality audio package of an audio interface (a small box you connect to your computer via USB cable), a microphone, a mic cable, and a mic stand for just $49.99 (less than our cost). After you have signed up, someone from JamKazam will contact you to schedule a 1:1 help session to help you get set up, to make sure your audio and video gear are working properly in an online session, and to make sure you feel comfortable with the key features you will be using in sessions with students.
+ <% else %>
+ Click
+ here for information on the gear requirements to effectively teach using the JamClass service. When you have
+ everything you need,
+ use
+ this set of help articles as a good step-by-step guide to set up your gear for use with the
+ JamKazam application. After you have signed up, someone from JamKazam will contact you to schedule a test online
+ session, in which we will make sure your audio and video gear are working properly in an online session, and to make
+ sure you feel comfortable with the key features you will be using in sessions with students.
+ <% end %>
3. Learn About JamClass Features uR(W
ziBh `7gZ6oQxY^;y?dZELF=KR3&
zA=NWJfGuBDlkOdW_sSHliVy849NiHKQ-%yH-!C2d9J{d6lJzS{Sw-gDV91mtSGaeF
zgspa|JYgCiGP3(UG$hri mA*W@^xv+6EXtl^Dz5&-
zv_GI#l$Ek)2c+-2RQ>4>>jO7Y0C>$o $NZqm7epIHFdL7l%>Wcy4bi~**SvT|-tvl98J4#BUuGV^jlO*YAnxQC
zF29~MIu$ec$v2V3qHpMPk>5SwB^^UNKYAJpb3Ge>8Rt)ew?rS0cb+ym;ErwN>oSyo
z+Kb-T)Z_o_n{D4r$ZBvXyoBl0e<-f{H1^$Q)duMMZW;4Fqt;cz>5 |K{u5OicAy!I0^skgw(10{@$eSYksYvEGOEb3uZl
zu(rcH_FQch7T6t{4HC`Lg=1~Kk(fuo@CpV|LBBIvR<(a7<;r_DRw7vZ6j(Z(8WfJ=
z*OT*a-Z_jRCjruWXTJ2u8)LSS2)sib2>Q)sLe(y8ctnUYZ{jng95P1%oLjwjngq8~ >B6nHNSQtdvSRy)|XYbDSo+vxEgLfj1vf&4~x6HrF0
zb%>&sgfAuez6`iIwAk hid
zPxiiu2N2tgRYCS;$)xElPQPC0j|;NWc)d!}(Xhu;T519TkQ-Ux?x}Yv_Lm!e<({&Q
zQkZa|mz^yY?7GCGv9!mFkv$Uj8NnOBid+}9e33A&8r*y9BwDkOT;G!s?d!2=sgkm2
z37k0o7~;Wo-j@TWq~Vf!IbPA1XTzL~`4Khehp1RboJrb3;vdr6J5LbHzNmmI1p5yd
zX#IzoL9RPmy0umAr+sR*CI1tTf~*E7SoIf~;}cD+&3C6#uw`0Qjt|l|AKph%=TkF_
zc`@bStwOVBas*i0XGQLouziou3#Zy2vjB4$nx!l@dY5SDemWaTr(Ng$Ts>*k(spiR
z?UAV9mMu7tG_iP5dQiYGK`cR_DzR$aDOLNrV1P)n<;_hL_1P1X6GB!(qv&Z-Z;wFW
z-UXK%LS81FNRyO30${_Covj9<>a@-Who*7ox+4pBl6OB`vnM(&qFC>P`Ad+EEbt>j
zEFS%`n>E4k(>?St1|qgW
diff --git a/ruby/lib/jam_ruby/models/charge.rb b/ruby/lib/jam_ruby/models/charge.rb
index 8ae916979..7854d712c 100644
--- a/ruby/lib/jam_ruby/models/charge.rb
+++ b/ruby/lib/jam_ruby/models/charge.rb
@@ -81,7 +81,7 @@ module JamRuby
subject = "Unable to charge user #{charged_user.email} for lesson #{self.id} (unhandled)"
body = "user=#{charged_user.email}\n\nbilling_error_reason=#{billing_error_reason}\n\nbilling_error_detail = #{billing_error_detail}"
- AdminMailer.alerts({subject: subject, body: body}).deliver
+ AdminMailer.alerts({subject: subject, body: body}).deliver_now
return false
end
diff --git a/ruby/lib/jam_ruby/models/lesson_booking.rb b/ruby/lib/jam_ruby/models/lesson_booking.rb
index 505257dc3..a4f1efb8d 100644
--- a/ruby/lib/jam_ruby/models/lesson_booking.rb
+++ b/ruby/lib/jam_ruby/models/lesson_booking.rb
@@ -95,7 +95,7 @@ module JamRuby
end
def after_create
- if (card_presumed_ok || school_on_school?) && !sent_notices
+ if (card_presumed_ok || !payment_if_school_on_school?) && !sent_notices
send_notices
end
end
@@ -393,8 +393,8 @@ module JamRuby
end
def requires_teacher_distribution?(target)
- if school_on_school?
- false
+ if no_school_on_school_payment?
+ return false
elsif target.is_a?(JamRuby::LessonSession)
is_test_drive? || (is_normal? && !is_monthly_payment?)
elsif target.is_a?(JamRuby::LessonPackagePurchase)
@@ -520,7 +520,17 @@ module JamRuby
end
end
- def distribution_price_in_cents(target)
+ def distribution_price_in_cents(target, education)
+ distribution = teacher_distribution_price_in_cents(target)
+
+ if education
+ (distribution * 0.0625).round
+ else
+ distribution
+ end
+ end
+
+ def teacher_distribution_price_in_cents(target)
if is_single_free?
0
elsif is_test_drive?
@@ -759,8 +769,10 @@ module JamRuby
if user
lesson_booking.same_school = !!(lesson_booking.school && user.school && (lesson_booking.school.id == user.school.id))
+ lesson_booking.same_school_free = lesson_booking.school_on_school_payment?
else
lesson_booking.same_school = false
+ lesson_booking.same_school_free = false
end
# two-way association slots, for before_validation loic in slot to work
@@ -779,7 +791,7 @@ module JamRuby
end
def self.unprocessed(current_user)
- LessonBooking.where(user_id: current_user.id).where(card_presumed_ok: false).where('school_id IS NULL')
+ LessonBooking.where(user_id: current_user.id).where(card_presumed_ok: false).where(same_school_free: false)
end
def self.requested(current_user)
@@ -790,6 +802,19 @@ module JamRuby
same_school
end
+ def school_on_school_payment?
+ !!(same_school && school.education)
+ end
+
+ def no_school_on_school_payment?
+ !!(school_on_school? && !school_on_school_payment?)
+ end
+
+ # if this is school-on-school, is payment required?
+ def payment_if_school_on_school?
+ !!(!school_on_school? || school_on_school_payment?)
+ end
+
def school_and_teacher
if school && school.scheduling_comm?
[school.communication_email, teacher.email]
@@ -862,7 +887,7 @@ module JamRuby
.joins("LEFT JOIN lesson_package_purchases ON (lesson_package_purchases.lesson_booking_id = lesson_bookings.id AND (lesson_package_purchases.year = #{current_month_first_day.year} AND lesson_package_purchases.month = #{current_month_first_day.month}))")
.where("lesson_package_purchases.id IS NULL OR (lesson_package_purchases.id IS NOT NULL AND lesson_package_purchases.post_processed = false)")
.where(payment_style: PAYMENT_STYLE_MONTHLY)
- .where(same_school: false)
+ .where(same_school_free: false)
.active
.where('music_sessions.scheduled_start >= ?', current_month_first_day)
.where('music_sessions.scheduled_start <= ?', current_month_last_day).uniq
@@ -932,8 +957,10 @@ module JamRuby
def bill_for_month(day_in_month)
# try to find lesson package purchase for this month, and last month, and see if they need processing
+ puts "bill_for_month"
current_month_purchase = lesson_package_purchases.where(lesson_booking_id: self.id, user_id: student.id, year: day_in_month.year, month: day_in_month.month).first
if current_month_purchase.nil?
+ puts "bill_for_month - day"
current_month_purchase = LessonPackagePurchase.create(user, self, lesson_package_type, day_in_month.year, day_in_month.month)
end
current_month_purchase.bill_monthly
diff --git a/ruby/lib/jam_ruby/models/lesson_package_purchase.rb b/ruby/lib/jam_ruby/models/lesson_package_purchase.rb
index 2f88af5c5..076d14338 100644
--- a/ruby/lib/jam_ruby/models/lesson_package_purchase.rb
+++ b/ruby/lib/jam_ruby/models/lesson_package_purchase.rb
@@ -4,7 +4,9 @@ module JamRuby
@@log = Logging.logger[LessonPackagePurchase]
- delegate :sent_billing_notices, :last_billing_attempt_at, :billing_attempts, :billing_should_retry, :billed, :billed_at, :billing_error_detail, :billing_error_reason, :is_card_declined?, :is_card_expired?, :last_billed_at_date, :sent_billing_notices, to: :lesson_payment_charge
+ delegate :sent_billing_notices, :last_billing_attempt_at, :billing_attempts, :billing_should_retry, :billed, :billed_at,
+ :billing_error_detail, :billing_error_reason, :is_card_declined?, :is_card_expired?,
+ :last_billed_at_date, :sent_billing_notices, to: :lesson_payment_charge
delegate :test_drive_count, to: :lesson_package_type
# who purchased the lesson package?
@@ -14,7 +16,7 @@ module JamRuby
belongs_to :lesson_booking, class_name: "JamRuby::LessonBooking"
belongs_to :lesson_payment_charge, class_name: "JamRuby::LessonPaymentCharge", foreign_key: :charge_id
has_one :lesson_session, class_name: "JamRuby::LessonSession", dependent: :destroy
- has_one :teacher_distribution, class_name: "JamRuby::TeacherDistribution"
+ has_many :teacher_distributions, class_name: "JamRuby::TeacherDistribution"
has_one :sale_line_item, class_name: "JamRuby::SaleLineItem", dependent: :destroy
@@ -35,7 +37,7 @@ module JamRuby
end
def create_charge
- if !school_on_school? && lesson_booking && lesson_booking.is_monthly_payment?
+ if payment_if_school_on_school? && lesson_booking && lesson_booking.is_monthly_payment?
self.lesson_payment_charge = LessonPaymentCharge.new
lesson_payment_charge.user = user
lesson_payment_charge.amount_in_cents = 0
@@ -45,16 +47,22 @@ module JamRuby
end
end
+ def teacher_distribution
+ teacher_distributions.where(education:false).first
+ end
+
+ def education_distribution
+ teacher_distributions.where(education:true).first
+ end
+
def add_test_drives
if self.lesson_package_type.is_test_drive?
new_test_drives = user.remaining_test_drives + lesson_package_type.test_drive_count
User.where(id: user.id).update_all(remaining_test_drives: new_test_drives)
user.remaining_test_drives = new_test_drives
end
-
end
-
def to_s
"#{name}"
end
@@ -79,9 +87,14 @@ module JamRuby
purchase.recurring = true
if lesson_booking && lesson_booking.requires_teacher_distribution?(purchase)
- purchase.teacher_distribution = TeacherDistribution.create_for_lesson_package_purchase(purchase)
+ teacher_dist = TeacherDistribution.create_for_lesson_package_purchase(purchase, false)
+ purchase.teacher_distributions << teacher_dist
# price should always match the teacher_distribution, if there is one
- purchase.price = purchase.teacher_distribution.amount_in_cents / 100
+ purchase.price = teacher_dist.amount_in_cents / 100
+
+ if lesson_booking.school_on_school_payment?
+ self.teacher_distributions << TeacherDistribution.create_for_lesson_package_purchase(purchase, true)
+ end
end
else
purchase.recurring = false
@@ -136,10 +149,23 @@ module JamRuby
end
end
+ def school_on_school_payment?
+ !!(school_on_school? && teacher.teacher.school.education)
+ end
+
+ def no_school_on_school_payment?
+ !!(school_on_school? && !school_on_school_payment?)
+ end
+
+ # if this is school-on-school, is payment required?
+ def payment_if_school_on_school?
+ !!(!school_on_school? || school_on_school_payment?)
+ end
def bill_monthly(force = false)
- if school_on_school?
+ if school_on_school_payment?
+ puts "SCHOOL ON SCHOOL PAYMENT OH NO"
raise "school-on-school: should not be here"
else
lesson_payment_charge.charge(force)
diff --git a/ruby/lib/jam_ruby/models/lesson_payment_charge.rb b/ruby/lib/jam_ruby/models/lesson_payment_charge.rb
index c4f5dd508..b4bb267a3 100644
--- a/ruby/lib/jam_ruby/models/lesson_payment_charge.rb
+++ b/ruby/lib/jam_ruby/models/lesson_payment_charge.rb
@@ -63,11 +63,8 @@ module JamRuby
post_sale_test_failure
- distribution = target.teacher_distribution
- if distribution # not all lessons/payment charges have a distribution
- distribution.ready = true
- distribution.save(validate: false)
- end
+ target.teacher_distributions.update_all(ready:true) # possibly there are 0 distributions on this lesson
+
stripe_charge
end
@@ -103,7 +100,9 @@ module JamRuby
end
def expected_price_in_cents
- target.lesson_booking.distribution_price_in_cents(target)
+ distribution = target.teacher_distribution
+ for_education = distribution && distribution.education
+ target.lesson_booking.distribution_price_in_cents(target, for_education)
end
end
end
\ No newline at end of file
diff --git a/ruby/lib/jam_ruby/models/lesson_session.rb b/ruby/lib/jam_ruby/models/lesson_session.rb
index c9de915a8..88a42a2e9 100644
--- a/ruby/lib/jam_ruby/models/lesson_session.rb
+++ b/ruby/lib/jam_ruby/models/lesson_session.rb
@@ -11,7 +11,7 @@ module JamRuby
@@log = Logging.logger[LessonSession]
delegate :sent_billing_notices, :last_billing_attempt_at, :billing_attempts, :billing_should_retry, :billed_at, :billing_error_detail, :billing_error_reason, :is_card_declined?, :is_card_expired?, :last_billed_at_date, :sent_billing_notices, to: :lesson_payment_charge, allow_nil: true
- delegate :is_test_drive?, :is_single_free?, :is_normal?, :approved_before?, :is_active?, :recurring, :is_monthly_payment?, :school_on_school?, :scheduling_email, :teacher_school_emails, :school_and_teacher, :school_over_teacher, :school_and_teacher_ids, :school_over_teacher_ids, to: :lesson_booking
+ delegate :is_test_drive?, :is_single_free?, :is_normal?, :approved_before?, :is_active?, :recurring, :is_monthly_payment?, :school_on_school?, :school_on_school_payment?, :no_school_on_school_payment?, :payment_if_school_on_school?, :scheduling_email, :teacher_school_emails, :school_and_teacher, :school_over_teacher, :school_and_teacher_ids, :school_over_teacher_ids, to: :lesson_booking
delegate :pretty_scheduled_start, to: :music_session
@@ -41,7 +41,7 @@ module JamRuby
belongs_to :slot, class_name: "JamRuby::LessonBookingSlot", foreign_key: :slot_id, :dependent => :destroy
belongs_to :lesson_payment_charge, class_name: "JamRuby::LessonPaymentCharge", foreign_key: :charge_id
belongs_to :counter_slot, class_name: "JamRuby::LessonBookingSlot", foreign_key: :counter_slot_id, inverse_of: :countered_lesson, :dependent => :destroy
- has_one :teacher_distribution, class_name: "JamRuby::TeacherDistribution", dependent: :destroy
+ has_many :teacher_distributions, class_name: "JamRuby::TeacherDistribution", dependent: :destroy
has_many :lesson_booking_slots, class_name: "JamRuby::LessonBookingSlot"
has_many :notifications, :class_name => "JamRuby::Notification", :foreign_key => "lesson_session_id"
has_many :chat_messages, :class_name => "JamRuby::ChatMessage", :foreign_key => "lesson_session_id"
@@ -86,7 +86,7 @@ module JamRuby
.order('music_sessions.scheduled_start DESC') }
def create_charge
- if !school_on_school? && !is_test_drive? && !is_monthly_payment?
+ if payment_if_school_on_school? && !is_test_drive? && !is_monthly_payment?
self.lesson_payment_charge = LessonPaymentCharge.new
lesson_payment_charge.user = @assigned_student
lesson_payment_charge.amount_in_cents = 0
@@ -96,6 +96,14 @@ module JamRuby
end
end
+ def teacher_distribution
+ teacher_distributions.where(education:false).first
+ end
+
+ def education_distribution
+ teacher_distributions.where(education:true).first
+ end
+
def manage_slot_changes
# if this slot changed, we need to update the time. But LessonBooking does this for us, for requested/accepted .
# TODO: what to do, what to do.
@@ -209,7 +217,10 @@ module JamRuby
self.status = STATUS_COMPLETED
if success && lesson_booking.requires_teacher_distribution?(self)
- self.teacher_distribution = TeacherDistribution.create_for_lesson(self)
+ self.teacher_distributions << TeacherDistribution.create_for_lesson(self, false)
+ if lesson_booking.school_on_school_payment?
+ self.teacher_distributions << TeacherDistribution.create_for_lesson(self, true)
+ end
end
if self.save
@@ -292,7 +303,7 @@ module JamRuby
end
def bill_lesson
- if school_on_school?
+ if no_school_on_school_payment?
success = true
else
lesson_payment_charge.charge
@@ -341,14 +352,9 @@ module JamRuby
def test_drive_completed
- distribution = teacher_distribution
-
if !sent_notices
if success
- if distribution # not all lessons/payment charges have a distribution
- distribution.ready = true
- distribution.save(validate: false)
- end
+ teacher_distributions.update_all(ready:true) # possibly there are 0 distributions on this lesson
student.test_drive_succeeded(self)
else
student.test_drive_failed(self)
@@ -387,7 +393,7 @@ module JamRuby
else
if lesson_booking.is_monthly_payment?
if !sent_notices
- if !school_on_school?
+ if payment_if_school_on_school?
# bad session; just poke user
UserMailer.monthly_recurring_no_bill(self).deliver_now
end
@@ -401,7 +407,7 @@ module JamRuby
else
if !sent_notices
- if !school_on_school?
+ if payment_if_school_on_school?
# bad session; just poke user
UserMailer.student_lesson_normal_no_bill(self).deliver_now
end
@@ -422,7 +428,7 @@ module JamRuby
bill_lesson
else
if !sent_notices
- if !school_on_school?
+ if payment_if_school_on_school?
UserMailer.student_lesson_normal_no_bill(self).deliver_now
UserMailer.teacher_lesson_normal_no_bill(self).deliver_now
end
diff --git a/ruby/lib/jam_ruby/models/school.rb b/ruby/lib/jam_ruby/models/school.rb
index 1e7523b50..94aaea30e 100644
--- a/ruby/lib/jam_ruby/models/school.rb
+++ b/ruby/lib/jam_ruby/models/school.rb
@@ -24,6 +24,7 @@ module JamRuby
validates :user, presence: true
validates :enabled, inclusion: {in: [true, false]}
+ validates :education, inclusion: {in: [true, false]}
validates :scheduling_communication, inclusion: {in: SCHEDULING_COMMS}
validates :correspondence_email, email: true, allow_blank: true
validate :validate_avatar_info
@@ -31,6 +32,10 @@ module JamRuby
after_create :create_affiliate
before_save :stringify_avatar_info, :if => :updating_avatar
+ def is_education?
+ education
+ end
+
def scheduling_comm?
scheduling_communication == SCHEDULING_COMM_SCHOOL
end
@@ -39,6 +44,10 @@ module JamRuby
correspondence_email.blank? ? owner.email : correspondence_email
end
+ def approved_teachers
+ teachers.where('teachers.ready_for_session_at is not null')
+ end
+
def create_affiliate
AffiliatePartner.create_from_school(self)
end
@@ -119,4 +128,8 @@ module JamRuby
self.crop_selection = crop_selection.to_json if !crop_selection.nil?
end
end
+
+ def teacher_list_url
+ "#{APP_CONFIG.external_root_url}/school/#{id}/teachers"
+ end
end
diff --git a/ruby/lib/jam_ruby/models/teacher.rb b/ruby/lib/jam_ruby/models/teacher.rb
index 14d1fe2f5..126847f48 100644
--- a/ruby/lib/jam_ruby/models/teacher.rb
+++ b/ruby/lib/jam_ruby/models/teacher.rb
@@ -416,21 +416,7 @@ module JamRuby
## !!!! this is only valid for tests
def stripe_account_id=(new_acct_id)
- existing = user.stripe_auth
- existing.destroy if existing
-
- user_auth_hash = {
- :provider => 'stripe_connect',
- :uid => new_acct_id,
- :token => 'bogus',
- :refresh_token => 'refresh_bogus',
- :token_expiration => Date.new(2050, 1, 1),
- :secret => "secret"
- }
-
- authorization = user.user_authorizations.build(user_auth_hash)
- authorization.save!
-
+ user.stripe_account_id = new_acct_id
end
# how complete is their profile?
diff --git a/ruby/lib/jam_ruby/models/teacher_distribution.rb b/ruby/lib/jam_ruby/models/teacher_distribution.rb
index 5d93d3581..51c964329 100644
--- a/ruby/lib/jam_ruby/models/teacher_distribution.rb
+++ b/ruby/lib/jam_ruby/models/teacher_distribution.rb
@@ -43,24 +43,26 @@ module JamRuby
end
end
- def self.create_for_lesson(lesson_session)
- distribution = create(lesson_session)
+ def self.create_for_lesson(lesson_session, for_education)
+ distribution = create(lesson_session, for_education)
distribution.lesson_session = lesson_session
+ distribution.education = for_education
distribution
end
- def self.create_for_lesson_package_purchase(lesson_package_purchase)
- distribution = create(lesson_package_purchase)
+ def self.create_for_lesson_package_purchase(lesson_package_purchase, for_education)
+ distribution = create(lesson_package_purchase, for_education)
distribution.lesson_package_purchase = lesson_package_purchase
+ distribution.education = for_education
distribution
end
- def self.create(target)
+ def self.create(target, education)
distribution = TeacherDistribution.new
distribution.teacher = target.teacher
distribution.ready = false
distribution.distributed = false
- distribution.amount_in_cents = target.lesson_booking.distribution_price_in_cents(target)
+ distribution.amount_in_cents = target.lesson_booking.distribution_price_in_cents(target, education)
distribution.school = target.lesson_booking.school
distribution
end
@@ -82,6 +84,7 @@ module JamRuby
end
def real_distribution
+
(real_distribution_in_cents / 100.0)
end
@@ -109,17 +112,21 @@ module JamRuby
end
def calculate_teacher_fee
- if is_test_drive?
+ if education
0
else
- if school
- # if school exists, use it's rate
- rate = school.jamkazam_rate
+ if is_test_drive?
+ 0
else
- # otherwise use the teacher's rate
- rate = teacher.teacher.jamkazam_rate
+ if school
+ # if school exists, use it's rate
+ rate = school.jamkazam_rate
+ else
+ # otherwise use the teacher's rate
+ rate = teacher.teacher.jamkazam_rate
+ end
+ (amount_in_cents * (rate + 0.03)).round
end
- (amount_in_cents * (rate + 0.03)).round
end
end
diff --git a/ruby/lib/jam_ruby/models/teacher_payment.rb b/ruby/lib/jam_ruby/models/teacher_payment.rb
index 25ac5f614..44bb299c7 100644
--- a/ruby/lib/jam_ruby/models/teacher_payment.rb
+++ b/ruby/lib/jam_ruby/models/teacher_payment.rb
@@ -15,7 +15,11 @@ module JamRuby
# pay the school if the payment owns the school; otherwise default to the teacher
def payable_teacher
if school
- school.owner
+ if school.education
+ teacher
+ else
+ school.owner
+ end
else
teacher
end
diff --git a/ruby/lib/jam_ruby/models/teacher_payment_charge.rb b/ruby/lib/jam_ruby/models/teacher_payment_charge.rb
index 3d74167b7..ce52fd143 100644
--- a/ruby/lib/jam_ruby/models/teacher_payment_charge.rb
+++ b/ruby/lib/jam_ruby/models/teacher_payment_charge.rb
@@ -21,8 +21,6 @@ module JamRuby
def do_charge(force)
- # source will let you supply a token. But... how to get a token in this case?
-
@stripe_charge = Stripe::Charge.create(
:amount => amount_in_cents,
:currency => "usd",
diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb
index 4faf1d925..7b098b08c 100644
--- a/ruby/lib/jam_ruby/models/user.rb
+++ b/ruby/lib/jam_ruby/models/user.rb
@@ -2033,6 +2033,24 @@ module JamRuby
customer
end
+ ## !!!! this is only valid for tests
+ def stripe_account_id=(new_acct_id)
+ existing = stripe_auth
+ existing.destroy if existing
+
+ user_auth_hash = {
+ :provider => 'stripe_connect',
+ :uid => new_acct_id,
+ :token => 'bogus',
+ :refresh_token => 'refresh_bogus',
+ :token_expiration => Date.new(2050, 1, 1),
+ :secret => "secret"
+ }
+
+ authorization = user_authorizations.build(user_auth_hash)
+ authorization.save!
+ end
+
def card_approved(token, zip, booking_id, test_drive_package_choice_id = nil)
approved_booking = nil
@@ -2261,6 +2279,10 @@ module JamRuby
LessonBooking.engaged_bookings(student, self, since_at).test_drive.count > 0
end
+ def same_school_with_student?(student)
+ student.school && self.teacher && self.teacher.school && student.school.id == self.teacher.school.id
+ end
+
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
diff --git a/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb b/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb
index 1f8ca34a1..fee6bf527 100644
--- a/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb
+++ b/ruby/spec/jam_ruby/flows/monthly_recurring_lesson_spec.rb
@@ -35,6 +35,8 @@ describe "Monthly Recurring Lesson Flow" do
booking.card_presumed_ok.should be_false
booking.user.should eql user
booking.card_presumed_ok.should be_false
+ booking.same_school.should be_false
+ booking.same_school_free.should be_false
booking.should eql user.unprocessed_normal_lesson
booking.sent_notices.should be_false
booking.booked_price.should eql 30.00
@@ -213,6 +215,252 @@ describe "Monthly Recurring Lesson Flow" do
+ # teacher & student get into session
+ start = lesson_session.scheduled_start
+ end_time = lesson_session.scheduled_start + (60 * lesson_session.duration)
+ uh2 = FactoryGirl.create(:music_session_user_history, user: teacher_user, history: lesson_session.music_session, created_at: start, session_removed_at: end_time)
+ # artificially end the session, which is covered by other background jobs
+ lesson_session.music_session.session_removed_at = end_time
+ lesson_session.music_session.save!
+
+
+ UserMailer.deliveries.clear
+ # background code comes around and analyses the session
+ LessonSession.hourly_check
+ lesson_session.reload
+ lesson_session.analysed.should be_true
+ analysis = lesson_session.analysis
+ analysis["reason"].should eql LessonSessionAnalyser::STUDENT_FAULT
+ analysis["student"].should eql LessonSessionAnalyser::NO_SHOW
+ if lesson_session.billing_error_detail
+ puts "monthly recurring lesson flow #{lesson_session.billing_error_detail}" # this should not occur, but helps a great deal if a regression occurs and running all the tests
+ end
+
+ lesson.amount_charged.should eql 0.0
+ lesson_session.billing_error_reason.should be_nil
+ lesson_session.sent_billing_notices.should be nil
+ user.reload
+ user.remaining_test_drives.should eql 0
+ UserMailer.deliveries.length.should eql 0 # one for student
+ end
+
+ it "works (school on school education)" do
+
+ # make sure teacher can get payments
+ teacher.stripe_account_id = stripe_account1_id
+ school.user.stripe_account_id = stripe_account2_id
+
+ # get user and teacher into same school
+ school.education = true
+ school.save!
+ user.school = school
+ user.save!
+ teacher.school = school
+ teacher.save!
+
+
+ # if it's later in the month, we'll make 2 lesson_package_purchases (prorated one, and next month's), which can throw off some assertions later on
+ Timecop.travel(Date.new(2016, 3, 20))
+
+ # user has no test drives, no credit card on file, but attempts to book a lesson
+ booking = LessonBooking.book_normal(user, teacher_user, valid_recurring_slots, "Hey I've heard of you before.", true, LessonBooking::PAYMENT_STYLE_MONTHLY, 60)
+ booking.errors.any?.should be_false
+ booking.card_presumed_ok.should be_false
+ booking.user.should eql user
+ booking.card_presumed_ok.should be_false
+ booking.should eql user.unprocessed_normal_lesson
+ booking.sent_notices.should be_false
+ booking.booked_price.should eql 30.00
+
+ ########## Need validate their credit card
+ token = create_stripe_token
+ result = user.payment_update({token: token, zip: '78759', normal: true, booking_id: booking.id})
+ booking.reload
+ booking.card_presumed_ok.should be_true
+ booking.errors.any?.should be_false
+ booking = result[:lesson]
+ lesson = booking.lesson_sessions[0]
+ lesson.errors.any?.should be_false
+
+ booking.sent_notices.should be_true
+ lesson.music_session.scheduled_start.should eql booking.default_slot.scheduled_time(0)
+ lesson.amount_charged.should be 0.0
+ lesson.reload
+
+ user.reload
+ user.stripe_customer_id.should_not be nil
+ user.remaining_test_drives.should eql 0
+ user.lesson_purchases.length.should eql 0
+
+ customer = Stripe::Customer.retrieve(user.stripe_customer_id)
+ customer.email.should eql user.email
+
+ booking.lesson_sessions.length.should eql 1
+ lesson_session = booking.lesson_sessions[0]
+ lesson_session.status.should eql LessonBooking::STATUS_REQUESTED
+ booking.status.should eql LessonBooking::STATUS_REQUESTED
+
+ ######### Teacher counters with new slot
+ teacher_countered_slot = FactoryGirl.build(:lesson_booking_slot_recurring, hour: 14, update_all: true)
+ UserMailer.deliveries.clear
+ lesson_session.counter({proposer: teacher_user, slot: teacher_countered_slot, message: 'Does this work?'})
+ booking.reload
+ booking.errors.any?.should be false
+ lesson_session.lesson_booking.errors.any?.should be false
+ lesson_session.lesson_booking_slots.length.should eql 1
+ lesson_session.lesson_booking_slots[0].proposer.should eql teacher_user
+ teacher_counter = lesson_session.lesson_booking_slots.order(:created_at).last
+ teacher_counter.should eql teacher_countered_slot
+ teacher_counter.proposer.should eql teacher_user
+ booking.lesson_booking_slots.length.should eql 3
+ UserMailer.deliveries.length.should eql 1
+ chat = ChatMessage.unscoped.order(:created_at).last
+ chat.channel.should eql ChatMessage::CHANNEL_LESSON
+ chat.message.should eql 'Does this work?'
+ chat.user.should eql teacher_user
+ chat.target_user.should eql user
+ notification = Notification.unscoped.order(:created_at).last
+ notification.session_id.should eql lesson_session.music_session.id
+ notification.student_directed.should eql true
+ notification.purpose.should eql 'counter'
+ notification.description.should eql NotificationTypes::LESSON_MESSAGE
+
+ ######### Student counters with new slot
+ student_countered_slot = FactoryGirl.build(:lesson_booking_slot_recurring, hour: 16, update_all: true)
+ UserMailer.deliveries.clear
+ lesson_session.counter({proposer: user, slot: student_countered_slot, message: 'Does this work better?'})
+ lesson_session.errors.any?.should be false
+ lesson_session.lesson_booking.errors.any?.should be false
+ lesson_session.lesson_booking_slots.length.should eql 2
+ student_counter = booking.lesson_booking_slots.order(:created_at).last
+ student_counter.proposer.should eql user
+ booking.reload
+ booking.lesson_booking_slots.length.should eql 4
+ UserMailer.deliveries.length.should eql 1
+ chat = ChatMessage.unscoped.order(:created_at).last
+ chat.message.should eql 'Does this work better?'
+ chat.channel.should eql ChatMessage::CHANNEL_LESSON
+ chat.user.should eql user
+ chat.target_user.should eql teacher_user
+ notification = Notification.unscoped.order(:created_at).last
+ notification.session_id.should eql lesson_session.music_session.id
+ notification.student_directed.should eql false
+ notification.purpose.should eql 'counter'
+ notification.description.should eql NotificationTypes::LESSON_MESSAGE
+
+ ######## Teacher accepts slot
+ UserMailer.deliveries.clear
+ lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user})
+ UserMailer.deliveries.each do |del|
+ # puts del.inspect
+ end
+ # get acceptance emails, as well as 'your stuff is accepted'
+ UserMailer.deliveries.length.should eql 2
+ lesson_session.errors.any?.should be_false
+ lesson_session.reload
+ lesson_session.slot.should eql student_counter
+ lesson_session.status.should eql LessonSession::STATUS_APPROVED
+ booking.reload
+ booking.default_slot.should eql student_counter
+ lesson_session.music_session.scheduled_start.should eql booking.default_slot.scheduled_time(0)
+ booking.status.should eql LessonBooking::STATUS_APPROVED
+
+ UserMailer.deliveries.length.should eql 2
+ chat = ChatMessage.unscoped.order(:created_at).last
+ chat.message.should eql 'Yeah I got this'
+ chat.purpose.should eql 'Lesson Approved'
+ chat.channel.should eql ChatMessage::CHANNEL_LESSON
+ chat.user.should eql teacher_user
+ chat.target_user.should eql user
+ notification = Notification.unscoped.order(:created_at).last
+ notification.session_id.should eql lesson_session.music_session.id
+ notification.student_directed.should eql true
+ notification.purpose.should eql 'accept'
+ notification.description.should eql NotificationTypes::LESSON_MESSAGE
+
+
+ # teacher & student get into session
+ start = lesson_session.scheduled_start
+ end_time = lesson_session.scheduled_start + (60 * lesson_session.duration)
+ uh2 = FactoryGirl.create(:music_session_user_history, user: teacher_user, history: lesson_session.music_session, created_at: start, session_removed_at: end_time)
+ # artificially end the session, which is covered by other background jobs
+ lesson_session.music_session.session_removed_at = end_time
+ lesson_session.music_session.save!
+
+ Timecop.travel(end_time + 1)
+
+ LessonSession.hourly_check
+ lesson_session.reload
+ lesson_session.analysed.should be_true
+ analysis = lesson_session.analysis
+ analysis["reason"].should eql LessonSessionAnalyser::STUDENT_FAULT
+ analysis["student"].should eql LessonSessionAnalyser::NO_SHOW
+ if lesson_session.billing_error_detail
+ puts "monthly recurring lesson flow #{lesson_session.billing_error_detail}" # this should not occur, but helps a great deal if a regression occurs and running all the tests
+ end
+
+ # let user pay for it
+ LessonBooking.hourly_check
+
+ booked_price = booking.booked_price
+ prorated = booked_price / 2
+ prorated_cents = (booked_price * 100).to_i
+ user.reload
+ user.lesson_purchases.length.should eql 1
+ lesson_purchase = user.lesson_purchases[0]
+ puts "LESSON_PURCHASE PRICE #{lesson_purchase.price}"
+ lesson_purchase.price.should eql prorated
+ lesson_purchase.lesson_package_type.is_normal?.should eql true
+ lesson_purchase.price_in_cents.should eql prorated_cents
+ teacher_distribution = lesson_purchase.teacher_distribution
+ teacher_distribution.amount_in_cents.should eql prorated_cents
+ teacher_distribution.ready.should be_true
+ teacher_distribution.distributed.should be_false
+ education_distribution = lesson_purchase.education_distribution
+ education_distribution.amount_in_cents.should eql (prorated_cents * 0.0625).round
+ education_distribution.ready.should be_true
+ education_distribution.distributed.should be_false
+ user.sales.length.should eql 1
+ sale = user.sales.first
+ sale.stripe_charge_id.should_not be_nil
+ sale.recurly_tax_in_cents.should eql (100 * prorated * 0.0825).round.to_i
+ sale.recurly_total_in_cents.should eql ((prorated * 100 * 0.0825).round + 100 * prorated).to_i
+ sale.recurly_subtotal_in_cents.should eql prorated_cents
+ sale.recurly_currency.should eql 'USD'
+ sale.stripe_charge_id.should_not be_nil
+ line_item = sale.sale_line_items[0]
+ line_item.quantity.should eql 1
+ line_item.product_type.should eql SaleLineItem::LESSON
+ line_item.product_id.should eq LessonPackageType.single.id
+ line_item.lesson_package_purchase.should eql lesson_purchase
+ lesson_purchase.sale_line_item.should eql line_item
+
+ TeacherPayment.count.should eql 0
+ TeacherPayment.hourly_check
+ teacher_distribution.reload
+ teacher_distribution.distributed.should be_true
+ TeacherPayment.count.should eql 2
+ payment = teacher_distribution.teacher_payment
+ payment.amount_in_cents.should eql 3000
+ payment.fee_in_cents.should eql (3000 * 0.28).round
+ payment.teacher_payment_charge.amount_in_cents.should eql (3000 + 3000 * APP_CONFIG.stripe[:ach_pct]).round
+ payment.teacher_payment_charge.fee_in_cents.should eql (3000 * 0.28).round
+ payment.teacher.should eql teacher_user
+ payment.teacher_distribution.should eql teacher_distribution
+ education_distribution.reload
+ education_distribution.distributed.should be_true
+
+ education_amt = (3000 * 0.0625).round
+ payment = education_distribution.teacher_payment
+ payment.amount_in_cents.should eql education_amt
+ payment.fee_in_cents.should eql 0
+ payment.teacher_payment_charge.amount_in_cents.should eql (education_amt + education_amt * APP_CONFIG.stripe[:ach_pct]).round
+ payment.teacher_payment_charge.fee_in_cents.should eql 0
+ payment.teacher.should eql teacher_user
+ payment.teacher_distribution.should eql education_distribution
+
+
+
# teacher & student get into session
start = lesson_session.scheduled_start
end_time = lesson_session.scheduled_start + (60 * lesson_session.duration)
@@ -422,6 +670,7 @@ describe "Monthly Recurring Lesson Flow" do
end
+
it "affiliate gets their cut" do
Timecop.travel(2016, 05, 15)
user.affiliate_referral = affiliate_partner
diff --git a/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb b/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb
index da9a65fe7..71192bccc 100644
--- a/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb
+++ b/ruby/spec/jam_ruby/flows/normal_lesson_spec.rb
@@ -266,12 +266,16 @@ describe "Normal Lesson Flow" do
it "works" do
+ # set up teacher stripe acct
+ teacher.stripe_account_id = stripe_account1_id
+
# user has no test drives, no credit card on file, but attempts to book a lesson
booking = LessonBooking.book_normal(user, teacher_user, valid_single_slots, "Hey I've heard of you before.", false, LessonBooking::PAYMENT_STYLE_SINGLE, 60)
booking.errors.any?.should be_false
booking.card_presumed_ok.should be_false
booking.user.should eql user
booking.card_presumed_ok.should be_false
+ booking.same_school_free.should be_false
booking.should eql user.unprocessed_normal_lesson
booking.sent_notices.should be_false
booking.booked_price.should eql 30.00
@@ -293,6 +297,7 @@ describe "Normal Lesson Flow" do
user.stripe_customer_id.should_not be nil
user.remaining_test_drives.should eql 0
user.lesson_purchases.length.should eql 0
+ teacher_user.stripe_auth.should_not be_nil
customer = Stripe::Customer.retrieve(user.stripe_customer_id)
customer.email.should eql user.email
@@ -389,6 +394,7 @@ describe "Normal Lesson Flow" do
UserMailer.deliveries.clear
# background code comes around and analyses the session
LessonSession.hourly_check
+
lesson_session.reload
lesson_session.analysed.should be_true
analysis = lesson_session.analysis
@@ -397,6 +403,17 @@ describe "Normal Lesson Flow" do
if lesson_session.billing_error_detail
puts "testdrive flow #{lesson_session.billing_error_detail}" # this should not occur, but helps a great deal if a regression occurs and running all the tests
end
+
+ TeacherPayment.count.should eql 0
+ TeacherPayment.hourly_check
+ TeacherPayment.count.should eql 1
+
+
+ teacher_distribution = lesson_session.teacher_distribution
+ teacher_distribution.ready.should be_true
+ teacher_distribution.distributed.should be_true
+ education_distribution = lesson_session.education_distribution
+ education_distribution.should be_nil
lesson_session.billed.should be true
user.reload
user.lesson_purchases.length.should eql 1
@@ -423,7 +440,7 @@ describe "Normal Lesson Flow" do
lesson_session.sent_billing_notices.should be true
user.reload
user.remaining_test_drives.should eql 0
- UserMailer.deliveries.length.should eql 2 # one for student, one for teacher
+ UserMailer.deliveries.length.should eql 3 # one for student, one for teacher
end
@@ -568,6 +585,224 @@ describe "Normal Lesson Flow" do
TeacherDistribution.count.should eql 0
end
+
+ it "works (school on school education)" do
+
+ # make sure teacher can get payments
+ teacher.stripe_account_id = stripe_account1_id
+ school.user.stripe_account_id = stripe_account2_id
+
+ # make sure can get stripe payments
+
+ # get user and teacher into same school
+
+ school.education = true
+ school.save!
+ user.school = school
+ user.save!
+ teacher.school = school
+ teacher.save!
+
+ # user has no test drives, no credit card on file, but attempts to book a lesson
+ booking = LessonBooking.book_normal(user, teacher_user, valid_single_slots, "Hey I've heard of you before.", false, LessonBooking::PAYMENT_STYLE_SINGLE, 60)
+ booking.errors.any?.should be_false
+ booking.school.should be_true
+ booking.card_presumed_ok.should be_false
+ booking.user.should eql user
+ user.unprocessed_normal_lesson.should be_nil
+ booking.sent_notices.should be_false
+ booking.booked_price.should eql 30.00
+ booking.is_requested?.should be_true
+ booking.lesson_sessions[0].music_session.scheduled_start.should eql booking.default_slot.scheduled_time(0)
+ LessonPaymentCharge.count.should eql 1
+
+
+ ########## Need validate their credit card
+ token = create_stripe_token
+ result = user.payment_update({token: token, zip: '78759', normal: true, booking_id: booking.id})
+ booking = result[:lesson]
+ lesson = booking.lesson_sessions[0]
+ booking.errors.any?.should be_false
+ lesson.errors.any?.should be_false
+ booking.card_presumed_ok.should be_true
+ booking.sent_notices.should be_true
+ lesson.music_session.scheduled_start.should eql booking.default_slot.scheduled_time(0)
+ lesson.amount_charged.should eql 0.0
+ lesson.reload
+
+ user.reload
+ user.stripe_customer_id.should_not be nil
+ user.remaining_test_drives.should eql 0
+ user.lesson_purchases.length.should eql 0
+
+ customer = Stripe::Customer.retrieve(user.stripe_customer_id)
+ customer.email.should eql user.email
+
+ booking.lesson_sessions.length.should eql 1
+ lesson_session = booking.lesson_sessions[0]
+ lesson_session.status.should eql LessonBooking::STATUS_REQUESTED
+ booking.status.should eql LessonBooking::STATUS_REQUESTED
+
+ ######### Teacher counters with new slot
+ teacher_countered_slot = FactoryGirl.build(:lesson_booking_slot_single, hour: 14)
+ UserMailer.deliveries.clear
+ lesson_session.counter({proposer: teacher_user, slot: teacher_countered_slot, message: 'Does this work?'})
+ booking.reload
+ booking.errors.any?.should be false
+ lesson_session.lesson_booking.errors.any?.should be false
+ lesson_session.lesson_booking_slots.length.should eql 1
+ lesson_session.lesson_booking_slots[0].proposer.should eql teacher_user
+ teacher_counter = lesson_session.lesson_booking_slots.order(:created_at).last
+ teacher_counter.should eql teacher_countered_slot
+ teacher_counter.proposer.should eql teacher_user
+ booking.lesson_booking_slots.length.should eql 3
+ UserMailer.deliveries.length.should eql 1
+ chat = ChatMessage.unscoped.order(:created_at).last
+ chat.channel.should eql ChatMessage::CHANNEL_LESSON
+ chat.message.should eql 'Does this work?'
+ chat.user.should eql teacher_user
+ chat.target_user.should eql user
+ notification = Notification.unscoped.order(:created_at).last
+ notification.session_id.should eql lesson_session.music_session.id
+ notification.student_directed.should eql true
+ notification.purpose.should eql 'counter'
+ notification.description.should eql NotificationTypes::LESSON_MESSAGE
+
+ ######### Student counters with new slot
+ student_countered_slot = FactoryGirl.build(:lesson_booking_slot_single, hour: 16)
+ UserMailer.deliveries.clear
+ lesson_session.counter({proposer: user, slot: student_countered_slot, message: 'Does this work better?'})
+ lesson_session.errors.any?.should be false
+ lesson_session.lesson_booking.errors.any?.should be false
+ lesson_session.lesson_booking_slots.length.should eql 2
+ student_counter = booking.lesson_booking_slots.order(:created_at).last
+ student_counter.proposer.should eql user
+ booking.reload
+ booking.lesson_booking_slots.length.should eql 4
+ UserMailer.deliveries.length.should eql 1
+ chat = ChatMessage.unscoped.order(:created_at).last
+ chat.message.should eql 'Does this work better?'
+ chat.channel.should eql ChatMessage::CHANNEL_LESSON
+ chat.user.should eql user
+ chat.target_user.should eql teacher_user
+ notification = Notification.unscoped.order(:created_at).last
+ notification.session_id.should eql lesson_session.music_session.id
+ notification.student_directed.should eql false
+ notification.purpose.should eql 'counter'
+ notification.description.should eql NotificationTypes::LESSON_MESSAGE
+
+ ######## Teacher accepts slot
+ UserMailer.deliveries.clear
+
+ lesson_session.accept({message: 'Yeah I got this', slot: student_counter.id, update_all: false, accepter: teacher_user})
+ lesson_session.errors.any?.should be_false
+ lesson_session.reload
+ lesson_session.slot.should eql student_counter
+ lesson_session.status.should eql LessonSession::STATUS_APPROVED
+ booking.reload
+ booking.default_slot.should eql student_counter
+ lesson_session.music_session.scheduled_start.should eql booking.default_slot.scheduled_time(0)
+ booking.status.should eql LessonBooking::STATUS_APPROVED
+
+ UserMailer.deliveries.length.should eql 2
+ chat = ChatMessage.unscoped.order(:created_at).last
+ chat.message.should eql 'Yeah I got this'
+ chat.purpose.should eql 'Lesson Approved'
+ chat.channel.should eql ChatMessage::CHANNEL_LESSON
+ chat.user.should eql teacher_user
+ chat.target_user.should eql user
+ notification = Notification.unscoped.order(:created_at).last
+ notification.session_id.should eql lesson_session.music_session.id
+ notification.student_directed.should eql true
+ notification.purpose.should eql 'accept'
+ notification.description.should eql NotificationTypes::LESSON_MESSAGE
+
+ # teacher & student get into session
+ start = lesson_session.scheduled_start
+ end_time = lesson_session.scheduled_start + (60 * lesson_session.duration)
+ uh2 = FactoryGirl.create(:music_session_user_history, user: teacher_user, history: lesson_session.music_session, created_at: start, session_removed_at: end_time)
+ # artificially end the session, which is covered by other background jobs
+ lesson_session.music_session.session_removed_at = end_time
+ lesson_session.music_session.save!
+
+ Timecop.travel(end_time + 1)
+
+ UserMailer.deliveries.clear
+ # background code comes around and analyses the session
+ LessonSession.hourly_check
+ lesson_session.reload
+ lesson_session.analysed.should be_true
+ analysis = lesson_session.analysis
+ analysis["reason"].should eql LessonSessionAnalyser::STUDENT_FAULT
+ analysis["student"].should eql LessonSessionAnalyser::NO_SHOW
+ lesson_session.billed.should be_true
+ if lesson_session.billing_error_detail
+ puts "testdrive flow #{lesson_session.billing_error_detail}" # this should not occur, but helps a great deal if a regression occurs and running all the tests
+ end
+ lesson_session.billing_attempts.should eql 1
+ user.reload
+ user.lesson_purchases.length.should eql 1
+
+ LessonBooking.hourly_check
+
+ lesson_session.reload
+ teacher_distribution = lesson_session.teacher_distribution
+ teacher_distribution.amount_in_cents.should eql 3000
+ teacher_distribution.ready.should be_true
+ teacher_distribution.distributed.should be_false
+
+ lesson_session.teacher_distributions.count.should eql 2
+ education_distribution = lesson_session.education_distribution
+ education_distribution.amount_in_cents.should eql (3000 * 0.0625).round
+ education_distribution.ready.should be_true
+ education_distribution.distributed.should be_false
+
+ lesson_session.billed.should be true
+ user.reload
+ user.lesson_purchases.length.should eql 1
+ user.sales.length.should eql 1
+ lesson_session.amount_charged.should eql 32.48
+ lesson_session.billing_error_reason.should be_nil
+ lesson_session.sent_billing_notices.should be_true
+ user.reload
+ user.remaining_test_drives.should eql 0
+ UserMailer.deliveries.length.should eql 2 # one for student, one for teacher
+
+ TeacherPayment.count.should eql 0
+ TeacherPayment.hourly_check
+ TeacherPayment.count.should eql 2
+
+ LessonPaymentCharge.count.should eql 1
+ TeacherDistribution.count.should eql 2
+
+
+ teacher_distribution.reload
+ teacher_distribution.distributed.should be_true
+ education_distribution.reload
+ education_distribution.distributed.should be_true
+
+ education_amt = (3000 * 0.0625).round
+ payment = education_distribution.teacher_payment
+ payment.amount_in_cents.should eql education_amt
+ payment.fee_in_cents.should eql 0
+ payment.teacher_payment_charge.amount_in_cents.should eql (education_amt + education_amt * APP_CONFIG.stripe[:ach_pct]).round
+ payment.teacher_payment_charge.fee_in_cents.should eql 0
+ payment.teacher.should eql teacher_user
+ payment.teacher_distribution.should eql education_distribution
+ payment = teacher_distribution.teacher_payment
+ payment.amount_in_cents.should eql 3000
+ payment.fee_in_cents.should eql (3000 * 0.28).round
+ payment.teacher_payment_charge.amount_in_cents.should eql (3000 + 3000 * APP_CONFIG.stripe[:ach_pct]).round
+ payment.teacher_payment_charge.fee_in_cents.should eql (3000 * 0.28).round
+ payment.teacher.should eql teacher_user
+ payment.teacher_distribution.should eql teacher_distribution
+ lesson_session.lesson_booking.status.should eql LessonBooking::STATUS_COMPLETED
+ lesson_session.lesson_booking.success.should be_true
+
+
+
+ end
+
it "affiliate gets their cut" do
user.affiliate_referral = affiliate_partner
user.save!
diff --git a/web/app/assets/images/landing/Scott Himel - Avatar.png b/web/app/assets/images/landing/Scott Himel - Avatar.png
new file mode 100644
index 0000000000000000000000000000000000000000..4b81238165a210a356b6ce796135b8e0f18280e0
GIT binary patch
literal 16637
zcmV)6K*+y|P)!u!G?eEW`x7?Uz7DTd%V3B^O;7
zZ#i&i)|?yVE_2xU2e_XYupdRKb)XikW^Si7;<@{c0E`dPBvsseu~m&03qYbAs0qpv
z+k*u{Ay5k}lHb?|YD4y+-In{Y4;06DxefVW@)B^_AFhC0O(Gz(Z?>@y`@@Q1v9MHF
zF6ZT1uw0xTP#@IE|J-W=Gj6~A_A!YSyH@~piVlgQ%>;w80XH36MfP4hV^Vyk>vyxL
zDt+LM;C|HHe_}Eg7E&rny2;r+{$D(2^2AyKqmm}BmcYY>Cv&AvjtVF!N~Q!Ov9Z8J
zJ1gWjqdKV2HBwVz(j=P#!~bHV?89I&a6PCIFp;@XC+C3@IX{#LP?DDbgF}M>)v*uv
z$RbIUXW(<6$W&hp1~`Lb{d`&=2Cxs
0U0dADez{9}?0>aKqKF`>4j4Dme-1-dnrOVxK?(Jj7(W?XlCInBF|
zf}Q)BmnURerrN)2^1s!^2@-udZcd0lVv;YKVO^jRE$Oih!wM6PTY)&6_G^EWu0*D>
zUom&&0pPBHG%@*4MH?fe%EC~*B?;)vXtVK;kmD(PDY}s%{h|apD;GbdQlrQV7RNOI
zm$(MZ`PU&Yqt&-EuJlKNpktZV1jKN$~3UX?Wg?Y8%h@#2OtV)79}0>Ho-p
zFF0Z_+?Nm~u)`=F`{kvsJ>@-=>K`2iUO9KuVgI#ah84kuBFd<;gk}TD2~EDx^e$Sw
zXYm@XNv80B*ephH&Mp3Va@Yj4-1z8If@Sy7s}Rfbzw7RI1g?aTb_0quu)n7fRA|zm
z&v-aSqD}rE#=t(QLYl*oSs7P`U@*?Btk<*usa^so{@7p@e%o~j3<|D+G1Tv_c%(m^
z{}dZL%p3wuGI0W_ToUlZK;NGwZ;Y^m1Et%#xj<
$n}F5ebco(EyDv
zwU(REd!&yj19}Lkds151Mnd}rBzLyyXICQyAYP;Hm7c}pAL*nlpH6WPjjZbh>eMl{
zAF{k=V#6m=Gf>7*jqlR(GQCWFtsLg#1-@9G=lHz9lABEI=iFpBdeEh;W>t1_fAg3T
zs^jXKeNS*K1QP!iJS`{O!B%G);xx)cA?Ye9{7%{b~biduW1lXbSC>Td%{=8rtnJ%+Z{|*UJYKaPzdF{74=|MHC-)ryZ{vOwQ
zM}ys@zCN(j%bon^Fr
sD@Ee^9a-79EGTl-T{+hV}-1mF6@HDjvZcYI(e!M3y
zqpy&qa$GW|fwzKVjN}4epO+(m5BD47BC{Vx<#4TwtL6
OAaUbj5$u|1Ih
zL;*Bz%=NC-hM5f*&n?N8I+h*AYLv(p0@~dY0VBLOsF>f3&(x5rQperZNBd&wx=gfv
z*U>eKek7$!=`3+W*0=;DOD_;V&REq0IwG)>y3G3AKA{OFXjdlNgc@N|Kz{7uq?UrK
z06NaJu}#_o`E8J|agK$!H8ZKC)cnE&dDHJt+;;0FT`{T##<>#wmZ_bv-Yb?hPD>rI
zS|0Z?doQ8%rFl6{FnC!wDk#~#*>4@rGzl7Vji0>pEIwG
ziDvLshAYE!mlu8fkxpaQgr~aDbTNW=rqXih!oz#*G$Ea^@R%$z3tn<^eMB68dP!|p
z$!6PDdci#%+o1X#gcL7L$0oI=E4z_((@6YIMMR(c5MSAw7QH_Z`e>jAPT2Eg9PyR_
zRjO6hi-s2Qz3V1&F!m%6?P4MUEDDT9y@ynpr5CX@D1Y>Of6h8F&zBm&x
ziH4MiXB!#r`jY~#cZE`0FjZyvcd+Q6U!6J>-+dS*FvtnLmnH3Yf9)>PD2ySy!5YR3
zH~t9HCbFeJ%VUPg18$wf*80k_Ux1Oz|Gw9!yoQ(FS_?D%J{u!%Km2n(;1^GmgOYH@
zs9gwAXH5g6M$u^?#Ho5Zd@AvXamX9tE@FNk^DNwrp#O9|Jwxf|t{uM^X$Nk}>-5Zz
zrL9c&ID-WX7nWi3fYziGJAo)g*k{9GE#LDJ41x8+h;iz5kDi&Y4T4Uhx|Hc)@KU{I
z2j&~ryjva6gYsE&gLSB7&=9}Z*f&^Y*