Skip to content

Instantly share code, notes, and snippets.

@robcole
Created November 14, 2011 19:29
Show Gist options
  • Save robcole/1364875 to your computer and use it in GitHub Desktop.
Save robcole/1364875 to your computer and use it in GitHub Desktop.
user_payments = []
active_users = []
subscriptions = Subscription.where('end > ?', Date.today)
subscriptions.each do |s|
active_users << s.user
end
active_users.each do |user|
@last_cim_payment = user.cim_payments.last
@last_moneybookers_payment = user.subscription.moneybookers_payments.last
@last_paypal_payment = user.subscription.paypal_payments.last
array = [@last_cim_payment, @last_moneybookers_payment, @last_paypal_payment]
array.delete_if {|a| a.nil?}
array.sort {|y, x| x.created_at <=> y.created_at }
user_payments << [user.login, array.first]
end
user_payments.each do |payment|
u = User.fbl(payment[0])
unless payment[1].nil?
# track what type of payment it is, call the amount properly to determine product type
if payment[1].amount.to_i == 29 # monthly
if u.valid?
u.subscription.last_product_id = 1
u.subscription.save!
end
elsif payment[1].amount.to_i == 147 # 6mo
if u.valid?
u.subscription.last_product_id = 3
u.subscription.save!
end
elsif payment[1].amount.to_i == 278 # 1yr
if u.valid?
u.subscription.last_product_id = 4
u.subscription.save!
end
else
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment