Skip to content

Instantly share code, notes, and snippets.

@oddlyzen
Created February 10, 2009 17:36
Show Gist options
  • Save oddlyzen/61486 to your computer and use it in GitHub Desktop.
Save oddlyzen/61486 to your computer and use it in GitHub Desktop.
# Cron jobs start here --------------------------------------------------------------
def self.check_trial
accounts = BillingAccount.find(:all, :include => :user, :conditions => ["kind = 'trial' and status = 'active'"])
accounts.each do |a|
if a.expires_at.to_s == Time.today.strftime("%Y-%m-%d")
pay_me = execute_payment(:customer_profile_id => a.customer_profile_id, :customer_payment_profile_id => a.customer_payment_profile_id, :user_id => a.user_id)
if pay_me.success?
a.kind = "full"
a.expires_at = 1.year.from_now
a.save!
UserMailer.deliver_payment_receipt(a.user)
else
a.status = "canceled"
a.save!
UserMailer.deliver_payment_declined(a.user)
end
elsif a.expires_at.to_s == 3.days.from_now.strftime("%Y-%m-%d")
UserMailer.deliver_subscription_start_reminder(a.user)
end
end
end
def self.check_expired
accounts = BillingAccount.find(:all, :include => :user, :conditions => ["kind = 'full' and status = 'active' and expires_at = ?", Time.today.strftime("%Y-%m-%d")])
accounts.each do |a|
pay_me = execute_payment(:customer_profile_id => a.customer_profile_id, :customer_payment_profile_id => a.customer_payment_profile_id, :user_id => a.user_id)
if pay_me.success?
a.expires_at = 1.year.from_now
a.save!
UserMailer.deliver_payment_receipt(a.user)
else
a.status = "canceled"
a.save!
UserMailer.deliver_payment_declined(a.user)
end
end
end
# cron jobs end here--------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment