2016-04-06 02:23:15 +00:00
|
|
|
module JamRuby
|
|
|
|
|
class AffiliatePaymentCharge < Charge
|
|
|
|
|
|
2016-05-12 21:29:27 +00:00
|
|
|
#has_one :teacher_payment, class_name: "JamRuby::TeacherPayment", foreign_key: :affiliate_charge_id
|
2016-04-06 02:23:15 +00:00
|
|
|
|
|
|
|
|
def distribution
|
|
|
|
|
@distribution ||= teacher_payment.teacher_distribution
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def max_retries
|
|
|
|
|
9999999
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def teacher
|
|
|
|
|
@teacher ||= teacher_payment.teacher
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def charged_user
|
|
|
|
|
teacher
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def do_charge
|
|
|
|
|
|
|
|
|
|
# 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",
|
|
|
|
|
:customer => APP_CONFIG.stripe[:source_customer],
|
|
|
|
|
:description => construct_description,
|
|
|
|
|
:destination => teacher.teacher.stripe_account_id,
|
|
|
|
|
:application_fee => fee_in_cents,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
stripe_charge
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def do_send_notices
|
2016-05-12 21:29:27 +00:00
|
|
|
#UserMailer.teacher_distribution_done(teacher_payment)
|
2016-04-06 02:23:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def do_send_unable_charge
|
2016-05-12 21:29:27 +00:00
|
|
|
#UserMailer.teacher_distribution_fail(teacher_payment)
|
2016-04-06 02:23:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def construct_description
|
2016-05-12 21:29:27 +00:00
|
|
|
#teacher_payment.teacher_distribution.description
|
2016-04-06 02:23:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|